This code seems to have a different effect in each browser.
.container {
display: inline-block;
border: 1px solid black;
padding-top: 5px;
padding-bottom: 5px;
}
.box {
display: table;
width: 10px;
height: 10px;
background-color: red;
border: 5px solid blue;
}
<div class="container">
<div class="box"></div>
</div>
In Chrome 43.0, the table is not confined to the container:
In Safari 5.1, the border completely overlaps the table because it seems to interpret the width as inclusive of the border width:
In Firefox 38.0 and Internet Explorer 11.0, the table renders correctly:
The ideal would be that all browsers behave similar to Firefox/Internet Explorer.
Using box-sizing: border-box
and increasing the width of .box
to include the width of the border makes all browsers show the Firefox/Internet Explorer version, but assuming that the width of the border is unknown, is there any way to make all major browsers render the model according to Firefox/Internet Explorer (without using JavaScript)?
The following doesn't help at all:
- Using
table-layout: fixed
on the.box
. - Using
border-collapse: separate
on the.box
- Using
box-sizing: content-box
on the.box
- Using
<table>
instead ofdisplay: table
(This just makes Chrome's preview look the same as Safari's and I would prefer to not use a table element.)
This issue seems to be similar to Chrome vs. box-sizing:border-box in a display:table, but that problem was already fixed.
Just for frame of reference:
That was all just a minimal example demonstrating the same problem. The actual issue is that I have a <div>
with display: table
that will have its width only defined by the width of its cells (which is equal to the height of the cells) and the padding between them. That div also happens to have a border. That div is contained by another element that is floated to the right. However, because of this problem, when the floated container is completely on the right, the div overflows off the screen.