gpt4 book ai didi

html - CSS 高度等于相关宽度

转载 作者:行者123 更新时间:2023-11-28 15:40:59 35 4
gpt4 key购买 nike

在这种情况下,我有一个这样的 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 , 但我找不到任何有用的东西

最佳答案

如果你不能用 javascript 做到这一点,并且你可以将宽度与视口(viewport)相关联,你可以将宽度和高度设置为视口(viewport)宽度的相同百分比

.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>

关于html - CSS 高度等于相关宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41053792/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com