为了账号安全,请及时绑定邮箱和手机立即绑定

清除浮动的提问

为元素为什么display:table呢? 不能使block

正在回答

1 回答

涉及到margin折叠。

W3C:http://www.w3.org/TR/CSS2/tables.html#anonymous-boxes

Any table element will automatically generate necessary anonymous table objects around itself, consisting of at least three nested objects corresponding to a 'table'/'inline-table' element, a 'table-row' element, and a 'table-cell' element.

所以display:table 会产生匿名的table-cell元素,进而产生BFC从而避免margin折叠。

It does not need to be display: table. The difference, however, is worth to be mentioned: If you use display: block instead of display: table, your margins will collapse as usual. If you use display: table, however, you will lose margin collapse between siblings and the first/last children of the element where you've applied the clearfix on, which might or might not be a desired feature.

代码演示

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

清除浮动的提问

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信