Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 866
Joe Morano Avatar asked May 28 '15 19:05

Joe Morano


2 Answers

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

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

like image 182
JJJ Avatar answered Oct 29 '22 15:10

JJJ


One way to accomplish this is to simply use two divs

<div class="outer">   <div class="inner">     This content will not exceed 100px or 20% width.   </div> </div>  <style> .outer {   max-width: 90%; } .inner {   max-width: 100px; } </style> 
like image 44
Jason Axelson Avatar answered Oct 29 '22 13:10

Jason Axelson