Subtracting an exact amount of pixels from a relative value
In my CSS, I need to make the width of a div 100% - 10px. Is this possible? If so, how?
Pretty straight forward开发者_开发百科 and simple.
This is not possible in CSS. You simply can't do any calculations in CSS. You'll have to rely on Javascript for that.
If you absolutely need it to work through CSS only, you should wrap it in a div with a padding.
HTML:
<div class="wrapper">
<div class="inner"></div>
</div>
CSS:
.wrapper {
padding-right: 10px;
}
And here's the fiddle: http://jsfiddle.net/sZvDY/
Use a margin set it to 5px left and right if you want it centered or 10px either side.
精彩评论