Joe Morano Joe Morano - 1 month ago 8
CSS Question

How to set a max-width as percent AND pixels?

How can I prevent the width of a div from expanding beyond a percent AND a pixel? In other words, the browser should calculate the pixel value of the percent, and then choose the lower of the two values.

If I were to set them both like this:

{max-width:100px;max-width:20%;}
the asset pipeline would simply choose the second one and ignore the first one.

JJJ JJJ
Answer
width:20%;
max-width:100px;

This sets the width to 20% but caps it at 100 px.

Comments