In WebKit, Firefox and Opera, you can set the various table elements to display: block
to stop them displaying like tables:
This can be useful on smaller screens (e.g. iPhones) that don’t have room to display tables laid out traditionally.
IE 9, however, still lays out the table cells next to each other horizontally — it doesn’t seem to honour display: block
on the table elements.
Is there any other code that will stop IE 9 (or earlier) from laying out tables as tables?
display: block An element that has the display property set to block starts on a new line and takes up the available screen width. You can specify the width and height properties for such elements. Examples of elements that are at block-level by default are <div> , <section> , <p> , and lots more.
The display: inline-block Value Compared to display: inline , the major difference is that display: inline-block allows to set a width and height on the element. Also, with display: inline-block , the top and bottom margins/paddings are respected, but with display: inline they are not.
As we can understand from its name, display: inline-block declaration shows both the characteristics of inline and block-level elements. In other words, we can think of an inline element, that width & height properties can be set, or we can think of a block-level element, that doesn't have to start with a new line.
The display CSS property sets whether an element is treated as a block or inline element and the layout used for its children, such as flow layout, grid or flex. Formally, the display property sets an element's inner and outer display types.
Adding float:left;clear:left;
will make IE 9 behave a bit better, but the width of each element will not be correct. If you add width:100%
to the mix, it seems to behave the same as in Chrome and Firefox.
table,
thead,
tfoot,
tbody,
tr,
th,
td {
display:block;
width:100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
float:left;
clear:left;
}
Edit: This has been asked before How can I make "display: block" work on a <td> in IE? and partially covered on How can I get inline-block to render consistently when applied to table cells? which quite rightly mention that any padding will cause the width:100%
to create a horizontal scrollbar. However, this can be avoided with box-sizing:border-box;
, or by using a suitably lower width or containing element with a fixed width.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With