开发者

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

I have a sideba开发者_开发知识库r 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?


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

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


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;.)


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;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜