我想在现代Safari/Chrome浏览器中使用新的CSS容器查询.(Safari16.3,谷歌Chrome 113.0)
然而,基于高度的容器查询并没有像预期的那样工作.
预期结果:一旦外部容器变成蓝色(500px或更低的屏幕高度),我预计粉色正方形(500px容器的50vh)就会变成红色.
当前结果:正方形保持粉色,不会变成粉色.如果实现是宽度相对的,则该示例有效.
Did I do anything wrong in my implementation or is it just not jet implemented in Webkit engine? Any other solutions (without Javascript) to solve the problem, if in the final product the container will be resizeable by the user?个
body {
margin: 0
}
.container {
height: 50vh;
container-type: inline-size;
}
.test {
width: 250px;
height: 250px;
background-color: hotpink;
}
@container (max-height: 250px) {
.test {
background-color: red;
}
}
@media screen and (max-height: 500px) {
.container {
background: blue;
}
}
<div class="container">
<div class="test"></div>
</div>