Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS div with display:table-cell and box-sizing:border-box - width/height calculation inconsistency

Tags:

css

Using the latest Google Chrome:

On a page with just this inside body:

<div class="personicon"></div>

and the following CSS:

.personicon {
    display:table-cell;
    width:100px;
    height:100px;
    background-color:#ECECEC;
    border:1px solid #BBBBBB;

    box-sizing:border-box;
}

Actual outer dimensions (including the border): 100px by 102px (expected: 100px by 100px)

Without box-sizing:border-box, outer dimensions are 102px by 102px (as expected).

Why is box-sizing:border-box only applying to the width and not the height?

Thanks :-)

like image 306
Pavel Avatar asked Dec 16 '11 07:12

Pavel


1 Answers

The solution I've found to work for most browsers is to avoid adding borders to display:table-cell elements that are in a display:table && table-layout:fixed. If a border is needed, put it on a regular div (display:block) which is inside the table-cell.

like image 85
Pavel Avatar answered Sep 19 '22 15:09

Pavel