OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Container Queries based on height not working

  • Thread starter Thread starter Tim Nikischin
  • Start date Start date
T

Tim Nikischin

Guest
I would want to use the new CSS container queries in modern Safari/Chrome browser. (Safari 16.3, Google Chrome 113.0)

However container queries based on height are not working as expected.

Expected result: as soon as the outer container turns blue (500px screen height or below) I would expect the pink square (50vh of 500px container) to turn red.

Current result: The square stays pink and does not turn pink. The example works if the implementation is width relative.

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?


Code:
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;
    }
}

Code:
<div class="container">
    <div class="test"></div>
</div>
<p>I would want to use the new CSS container queries in modern Safari/Chrome browser. (Safari 16.3, Google Chrome 113.0)</p>
<p>However container queries based on height are not working as expected.</p>
<p>Expected result: as soon as the outer container turns blue (500px screen height or below) I would expect the pink square (50vh of 500px container) to turn red.</p>
<p>Current result: The square stays pink and does not turn pink. The example works if the implementation is width relative.</p>
<p><strong>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?</strong></p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>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;
}
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="container">
<div class="test"></div>
</div></code></pre>
</div>
</div>
</p>
Continue reading...
 

Latest posts

A
Replies
0
Views
1
Anthonin Chaboteaux
A
Top