html inline-table,html - What is the difference between inline-block and inline-table? - Stack Overf...

The element generates an inline-level box.

The difference is that

The element generates a block container box, and lays out its

contents using flow layout. It always establishes a new block

formatting context for its contents.

The element generates a principal table wrapper box containing an

additionally-generated table box, and establishes a table

formatting context.

However, in most cases, inline-table will behave like inline-block because of anonymous table objects:

Generate missing child wrappers:

If a child C of a 'table' or 'inline-table' box is not a proper table child, then generate an anonymous 'table-row' box around C and

all consecutive siblings of C that are not proper table children.

If a child C of a 'table-row' box is not a 'table-cell', then generate an anonymous 'table-cell' box around C and all consecutive

siblings of C that are not 'table-cell' boxes.

Therefore, if your inline-table element has non-tabular content, that content will be wrapped in an anonymous table-cell.

But if the inline-table has tabular content, it will behave differently than inline-block.

Some examples:

Inside an inline-block, cells with non-tabular separator will generate different table anonymous parents, so they will appear at different lines. Inside an inline-table, it will be the separator who will generate a table-cell parent, so they all will appear at the same row.

.itable {

display: inline-table;

}

.iblock {

display: inline-block;

}

.cell {

display: table-cell;

}

.wrapper > span {

border: 1px solid #000;

padding: 5px;

}

inline-table

table-cell

inline-block

table-cell

inline-block

table-cell

inline-block

table-cell

Inner cells won't grow to fill a wide inline-block:

.itable {

display: inline-table;

}

.iblock {

display: inline-block;

}

.wrapper {

width: 100%;

}

.cell {

display: table-cell;

border: 1px solid #000;

}

inline-table

table-cell

inline-block

table-cell

The border of the inline-block won't collapse with the border of the inner cells:

.wrapper, .cell {

border-collapse: collapse;

border: 5px solid #000;

}

.itable {

display: inline-table;

}

.iblock {

display: inline-block;

}

.cell {

display: table-cell;

}

inline-table

table-cell

table-cell

inline-block

table-cell

table-cell

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值