I've created a div that i want to be 50% (for arguments sake) but at least a certain width and at most 100% width, (so that it never extends the window)
.about {
position:absolute;
right:0;
width: 50%;
min-width: 500px;
max-width: 100%;
}
Basically, i want the min-width to work, but i want the max-width to be considered MORE important so that it is never wider than the window, i assumed that i could do this by the order, or at least by using !important, but this doesn't seem to be the case
https://jsfiddle.net/ex716kam/2/
max-width overrides width , but min-width overrides max-width .
And min-width specify lower bound for width. So the width of the element will vary from min-width to ... (it will depend on other style). So if you specify min-width and max-width , you will set up a lower and upper bound and if both are equal it will be the same as simply specifing a width .
The min-width property defines the minimum width of an element. If the content is smaller than the minimum width, the minimum width will be applied. If the content is larger than the minimum width, the min-width property has no effect.
Generally if you are starting small screen first use min-width and then build on top with media queries targeting larger resolutions.
I've given it a few tries but I can't seem to make it work with CSS alone. I would recommend using simple javascript or media queries to make it work.
Working jsFiddle
@media screen and (min-width:1000px){
.about{
width:50%;
}
}
Note what @lmgonzalves wrote about min-width being the "strongest"..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With