How one could create a CSS rule for width which
Uses 100% width by default
If 100% width exceeds certain pixel width (let\'s say 512 px), th
That's in fact the intended use of max-width. If the computed (actual) width
of an element exceeds max-width
, it will be constrained to the max value instead of going beyond it. Percentage versus pixels isn't relevant.
Declare both in the same rule like this (no need for the calc()
function):
#somediv {
width: 100%;
max-width: 512px;
}
If it's block level element it should be 100% by default so no need to declare the width, then max-width: 512px;
would curtail it
calc()
is not supported very well at all, but in this case I wouldn't think you would need it
div{ max-width: 512px; }
should suffice.