2016-12-09 155 views
0

在這種情況下,我有一個這樣的CSS:CSS高度等於由相關寬度

.w{ 
    width:80%; 
    display:block; 
} 

.d{ 
    width:14%; 
    display:inline-block 
} 

,這是我的html

<div class="w"> 
    <a href="#" class="d">1</a> 
    <a href="#" class="d">2</a> 
    <a href="#" class="d">3</a> 
    <a href="#" class="d">4</a> 
    <a href="#" class="d">5</a> 
</div> 

所以現在的問題是,這有可能使.d高度等於它的寬度? 我的意思是像這樣的東西:height: 14% OF WIDTH。 我讀過css的所有單位here,但我找不到任何有用的東西

+0

http://stackoverflow.com/questions/2648733/make-a-div-square-when-there-is-a-dynamically-changing-width基礎的上,percenta – pol

回答

-2

如果你不能用javascript做到這一點,你可以將寬度與視口相關聯,你可以設置寬度和高度視口寬度的相同%

.w{ 
 
    width:80vw; 
 
    display:block; 
 
} 
 

 
.d{ 
 
    width:11.2vw; 
 
    display:inline-block; 
 
    border:1px solid red; 
 
    height:11.2vw; 
 
}
<div class="w"> 
 
    <a href="#" class="d">1</a> 
 
    <a href="#" class="d">2</a> 
 
    <a href="#" class="d">3</a> 
 
    <a href="#" class="d">4</a> 
 
    <a href="#" class="d">5</a> 
 
</div>