Can you make IE 9 (or earlier) lay out table elements as if they were regular display:block elements?

本小妞迷上赌 提交于 2019-12-19 03:22:05

问题


In WebKit, Firefox and Opera, you can set the various table elements to display: block to stop them displaying like tables:

  • http://jsfiddle.net/bHzsC/

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?


回答1:


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.




回答2:


How about:

table,
thead,
tfoot,
tbody,
tr,
th,
td {
    float:left;
    clear: left;
}

It might have repercussions on your layout with it using floats

Working example: http://jsfiddle.net/bHzsC/1/



来源:https://stackoverflow.com/questions/9990173/can-you-make-ie-9-or-earlier-lay-out-table-elements-as-if-they-were-regular-di

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!