I was just wonder开发者_JAVA百科ing if it's possible to give a div a width of auto (expandable) but also not allow it to expand more then x amount of pixels?
Yep, you can use the style, max-width
div {
width: auto;
max-width: 100px;
}
You can use max-width
:
http://jsfiddle.net/CssJJ/
Be aware that certain version of IE don't support this (would have to look up which) and some I believe require a strict doctype.
max-width: %/px/em/vh/vw,etc...
Also if you put max-width: 100%
on an image element, the image scales to fit its parent container. Ie. Responsive images
精彩评论