【发布时间】:2022-02-04 19:51:49
【问题描述】:
我已经阅读了Maintain the aspect ratio of a div with CSS(不是重复的,请进一步阅读)和其他方法,但在这里我要问一些更具体的问题:
有没有办法在 CSS 计算规则中使用当前元素(自身)的宽度?
如果没有,是否可以在height: calc(...) 中使用父 元素的width?
类似:
#container {
display: flex;
width: 500px;
flex-direction: row;
}
#a {
background-color: red;
width: 50%;
}
#b {
background-color: blue;
width: 50%;
height: calc(100% of self current width); /* <------- pseudo code here - does this exist? */
}
<div id="container">
<div id="a">
Hello
</div>
<div id="b">
World
</div>
</div>
【问题讨论】:
-
你可以在这里找到一些可以帮助你的东西stackoverflow.com/questions/5445491/…
-
阅读副本的第二个答案
-
@TemaniAfif 它在这里没有回答这个问题,你读过我的第一段吗?这是一个关于
calc的具体问题。 -
你不能用 calc() 来做,因此建议的解决方案
-
@TemaniAfif 那么,这不是重复的(因为我的问题实际上是关于使用
calc进行操作),答案是“不,这是不可能的”。请重新打开,问题具体有这个要求,并提到了链接问题(不是重复的)。