有没有办法在 CSS 计算规则中使用 self 的宽度?

Is there a way to use use the width of self in a CSS calc rule?

我已经阅读了Maintain the aspect ratio of a div with CSS(不是重复的,请进一步阅读)和其他方法,但在这里我要问一些更具体的问题:

有没有办法在 CSS 计算规则中使用当前元素(自身)的宽度?

或者如果不能,是否可以在 height: calc(...) 中使用 parent 元素的 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>

您可以使用 padding-top: 100%; 使 width:height = 1:1.

参考:https://www.w3schools.com/howto/howto_css_aspect_ratio.asp