Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between display:grid and display:inline-grid? [duplicate]

Tags:

css

display

I noticed that people covered specifics of some display properties in a 1:1 comparison, but there are quite a few that have not been covered in illustrating the differences. Could someone explain the differences between the various inline-something display tags?

A more elaborated definition over places like w3schools would do wonders.

like image 599
NBeers Avatar asked Jun 19 '14 17:06

NBeers


People also ask

What is the difference between display grid and display inline-grid?

The difference between the values inline-grid and grid is that the inline-grid will make the element inline while grid will make it a block-level element.

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

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.

What is the difference between display flex and display grid?

The basic difference between CSS Grid Layout and CSS Flexbox Layout is that flexbox was designed for layout in one dimension - either a row or a column. Grid was designed for two-dimensional layout - rows, and columns at the same time.

What does display grid means?

display. Defines the element as a grid container and establishes a new grid formatting context for its contents. Values: grid – generates a block-level grid. inline-grid – generates an inline-level grid.


1 Answers

The only difference, for any display type that has block and inline variants, is that the inline-* display type has the box laid inline (i.e. in an inline formatting context) while the other has the box formatted as a block-level box, subject to most of the same formatting conventions as other block-level elements in a block formatting context. The difference between a block-level box and an inline-level box is covered in depth elsewhere.

Everything concerning how the box lays out its contents is pretty much the same (the specifics of which, of course, are governed by the display type itself); any other nuanced differences would have been stated explicitly in the spec. As far as I'm aware, there are in fact no such differences.

When in doubt, prefer block-level display types. If you find yourself asking whether inline-level is appropriate, chances are the answer is no. Certain scenarios may prevent a box from ever being formatted as an inline-level box anyway, such as absolute positioning or floating, or being formatted as a flex item or grid item instead. The result is a direct conversion from the inline-* variant to its usual block variant. That is, inline-block is converted to block, inline-table to table, inline-flex to flex, and inline-grid to grid. Again, this does not directly affect how an element's contents are formatted, not as far as the specifications go.

Examples of each display type and its inline-level counterpart follow.


In CSS2.1, section 9.2.4 describes block and inline-block as follows:

block
This value causes an element to generate a block box.

inline-block
This value causes an element to generate an inline-level block container. The inside of an inline-block is formatted as a block box, and the element itself is formatted as an atomic inline-level box.

Note that "block box" is a shorthand for "block-level block container", and a block container is something that can contain block-level boxes.

You can see that both of these two values cause an element to generate a block container box, in which its contents will always follow the same set of formatting rules, but that block container box itself is either formatted as block-level, or inline-level.

There is one additional difference between block and inline-block: an inline-block box always establishes a new block formatting context; block boxes only do so under a set of conditions. This does not hold true for any of the other display types that have block-level and inline-level counterparts.

Section 17.2 describes table and inline-table as follows:

table (In HTML: TABLE)
Specifies that an element defines a block-level table: it is a rectangular block that participates in a block formatting context.

inline-table (In HTML: TABLE)
Specifies that an element defines an inline-level table: it is a rectangular block that participates in an inline formatting context).

The Flexbox module describes flex and inline-flex as follows:

flex
This value causes an element to generate a block-level flex container box.

inline-flex
This value causes an element to generate an inline-level flex container box.

And the Grid Layout module describes grid and inline-grid as follows:

grid
This value causes an element to generate a block-level grid container box.

inline-grid
This value causes an element to generate an inline-level grid container box.

Again, in all of these scenarios, a table, a flex container, or a grid container will behave exactly the same way whether it is block-level or inline-level. A flex container always establishes a flex formatting context for its flex items, and a grid container always establishes a grid formatting context for its grid items.

like image 124
BoltClock Avatar answered Sep 18 '22 16:09

BoltClock