2016-12-09 158 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>