I have am using css clamp() to adjust height of my div, but it doesn't work as expected.
.container{
height: clamp(200px, auto, 400px);
}
but works well when
.container{
min-height: 200px;
height: auto;
max-height: 400px;
}
from the documentation css clamp(): MDN Web Docs , it says it does the job of min, value and max. why is it not working?
if you check the syntax you can see:
autois not a part of the syntax which is logical since you cannot compareautowith pixel value (or any length)You think that the browser will first apply
autoto height in order to find the value of the height based on the content then convert that value topxand then apply theclamp()using that value but no. It doesn't work that way.The browser will try to first resolve
clamp(200px, auto, 400px)which is invalid becauseautois not a<calc-value>. We don't even need to know to which property its applied.