开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜