Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between inline-block and inline-table?

Tags:

html

css

As far as I can tell, these display selectors seem to be identical.

From the Mozilla CSS documentation:

inline-table: The inline-table value does not have a direct mapping in HTML. It behaves like a <table> HTML element, but as an inline box, rather than a block-level box. Inside the table box is a block-level context.

inline-block: The element generates a block element box that will be flowed with surrounding content as if it were a single inline box (behaving much like a replaced element would).

It seems that whatever could be done with inline-table can be done with inline-block.

like image 689
Steve Barna Avatar asked Oct 14 '13 00:10

Steve Barna


People also ask

Whats the difference between inline and inline-block?

Compared to display: inline , the major difference is that inline-block allows to set a width and height on the element. Also, with display: inline , top and bottom margins & paddings are not respected, and with display: inline-block they are.

What are inline tables?

An inline table is a temporary table created using a VALUES clause.

What is the difference between block and inline-block?

Block Elements occupy the full width irrespective of their sufficiency. Inline elements don't start in a new line. Block elements always start in a line. Inline elements allow other inline elements to sit behind.

What is an inline-block?

“display: inline-block” Property: This property is used to display an element as an inline-level block container. The element itself is formatted as an inline element, but it can apply height and width values. It is placed as an inline element (on the same line as adjacent content).


2 Answers

Both inline-block and inline-table have an inline outer display role. That means

The element generates an inline-level box.

The difference is that

  • inline-block has a flow-root inner display model, that is

    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.

  • inline-table has a table inner display model, that is

    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.

And table-cell has a flow-root inner display model, just like inline-block.

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;  }
    <fieldset>    <legend>inline-table</legend>    <div class="itable wrapper">      <span class="cell">table-cell</span>      <span class="iblock">inline-block</span>      <span class="cell">table-cell</span>    </div>  </fieldset>  <fieldset>    <legend>inline-block</legend>    <div class="iblock wrapper">      <span class="cell">table-cell</span>      <span class="iblock">inline-block</span>      <span class="cell">table-cell</span>    </div>  </fieldset>
  • 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;  }
    <fieldset>    <legend>inline-table</legend>    <div class="itable wrapper">      <span class="cell">table-cell</span>    </div>  </fieldset>  <fieldset>    <legend>inline-block</legend>    <div class="iblock wrapper">      <span class="cell">table-cell</span>    </div>  </fieldset>
  • 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;  }
    <fieldset>    <legend>inline-table</legend>    <div class="itable wrapper">      <span class="cell">table-cell</span>      <span class="cell">table-cell</span>    </div>  </fieldset>  <fieldset>    <legend>inline-block</legend>    <div class="iblock wrapper">      <span class="cell">table-cell</span>      <span class="cell">table-cell</span>    </div>  </fieldset>
like image 59
Oriol Avatar answered Oct 13 '22 20:10

Oriol


display:table will make your tag behave like a table. inline-table just means that the element is displayed as an inline-level table. You can then do table-cell to let your element behave like a <td> element.

display:inline - displays your element as an inline element (like <span>), and inline-block will just group them together in a block container.

As the other answer suggested you can replace between the two as long as you follow the display convention in the rest of your code. (i.e. use table-cell with inline-table and not with inline-block).
Check this link for more info on display.

like image 26
Quantico Avatar answered Oct 13 '22 18:10

Quantico