Can anyone help me find CSS rules that can set a fixed width for an element (width: 500px
) but also allow it to be responsive with max-width: 100%
if the container is narrower than the element?
I saw this example and it works perfectly:
.elem {
width: 600px;
max-width: 100%;
}
This code ensures that if the container of .elem
is smaller than the element itself, then the .elem
will adjust to match the container's width, which could be less than 600px
.
Is there a way to achieve similar responsiveness using min-width
? I tried the following snippet, but it didn't work as expected:
.elem {
min-width: 600px;
max-width: 100%;
}
Any suggestions on how to solve this problem using CSS Grid or possibly JavaScript?