AmirHosein KazemNejad AmirHosein KazemNejad - 2 months ago 6
CSS Question

100% width is bigger than parent's div

I'm working on vBulletin theme, but on thread list, every thread has 100% for its width but threads are also bigger than their parents, but when i remove border of threads, they will fit parent's div:). so think this problem is on borders.

You can see that better on jsfiddle (thread is white shape with black border)


<body>
<div class="after-body">
<div class="body-wrapper">
<div class="threadlist">
<ol class="threads">
<li class="threadbit"><div class="thread"></div></li>
<li class="threadbit"><div class="thread"></div></li>
</ol>
</div>
</div>
</div>
</body>

Answer

The problem here is that the width is a size of the inner area with text, and the padding with border are "wrapped" around it. That specification makes no sense, but most modern browsers follow it.

Your savior is called box-sizing: border-box;.

.threadbit .thread {

    /* ... some stuff ... */

    -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
    -moz-box-sizing: border-box;    /* Firefox, other Gecko */
    box-sizing: border-box;         /* Opera/IE 8+ */
}

Look here: jsFiddle

More info on this property here and here.

Comments