Susan
Susan

Reputation: 89

Can I specify width in % and min-width in px for a DIV?

I have a sidebar DIV on my web page that has buttons. I have the width of the sidebar set as follows:

width: 20%; 

but when the browser size is reduce then there's sometime not enough space for the buttons. Is it possible for me to have the width as 20% but also specify a minimum in px?

Upvotes: 2

Views: 298

Answers (3)

Jens
Jens

Reputation: 72667

Yes. The W3C CSS recommendation generally does not require that units for different dimensions like width and min-width be the same. (Not quite relevant side note: You can even mix different units for dimensions like padding, e.g. padding: 2px 1em;.)

Upvotes: 1

user912695
user912695

Reputation:

Using “min width”. min-width: 20px; for example. But if you want its width to always be at least the size of whatever is contained, consider using display: table-cell;

Upvotes: 0

Matchu
Matchu

Reputation: 85802

Yes. This is pretty common, too. Have fun!

And protip: you can always just try and find out ;)

Upvotes: 3

Related Questions