开发者

Is there a way to make the CSS to recognize 100% to include the paddings, margins and border?

I have a the following html code:

<div class="panel">Some Text Here</div>

With the following css attached

.panel{
    display:inline-block;
    heigh开发者_高级运维t:100%;
    border:1px solid black;
}

Because the panel has a border it's causing the vertical scrollbar to appear, is there a way to make the CSS to recognize 100% to include the paddings, margins and border?


Well, if you're targeting CSS3 you can use the box-sizing property

Of course, only newer browser support it, and even then they don't support it directly (yet), so you have to use the browser specific version (e.g. -moz-box-sizing)

.panel{
    display:inline-block;
    height:100%;
    border:1px solid black;

    box-sizing: border-box;         // IE8, Opera
    -moz-box-sizing: border-box;    // Firefox
    -webkit-box-sizing: border-box; // Chrome
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜