CSS - Display

Display

The CSS display property is used to set how element(s) should be laid out on the web page. The default display property value for most element is inline and block; but there are other properties.

Display Property Values

inline - takes the space that is required of its content. It does not start on a new line entirely.

block - takes 100% of the entire width. It always starts from a new line entirely.

inline-block - an inline element that has block characteristics such as setting height, width.

contents - makes an element disappear, but leaves its children as a direct child for top parent element.

grid - sets an element to become a grid container that uses grid layout model for creating of multiple layouts with rows and columns.

flex - sets an element to become a flex container that uses flex layout model making flex items flexible and responsible which allows easy alignment, distribution and ordering of flex items along a single axis.

tips
TIP:

Instead of using float property; flex can also be used for easy arrangement or alignment of elements.

inline-grid - sets an element to become an inline-grid container (that is, it behaves like an inline element) while using the grid model layout for creating of multiple layouts with rows and columns.

inline-flex - sets an element to become an inline-flex container (that is, it behaves like an inline element) while using the flex model layout for making flex items flexible and responsible which allows easy alignment, distribution and ordering of flex items along a single axis.

note
NOTE:

Difference between inline-grid and grid
inline-grid will make the element become an inline element.
grid will make the element become a block element.

Difference between inline-flex and flex
inline-flex will make the container behave like inline element.
grid will make the container behave like inline element.


run-in - sets an element to behave as block or inline element depending on its context.

list-item - to make element behave like list items; which displays list markers (bullets or numbering).

Table Layout - To create table-like layouts without using HTML table element, you can use the following values.

  • table - create container like a <table> element.
  • table-cell - similar to <td> element.
  • table-row - similar to <tr> element.
  • table-caption - similar to <caption> element.
  • table-column-group - similar to <colgroup> element.
  • table-header-group - similar to <thead> element.
  • table-footer-group - similar to <tfoot> element.
  • table-row-group - similar to <tbody> element.
  • table-column - similar to <col> element.

none - to hide an element such that it is not visible and does not occupy any space.

initial - sets the property value to its default value.

inherit - sets the property value to its parent value.

ADVERTISEMENTS

LEARNING IS A CONTINOUS PROCESS - PRACTICE MAKES PERFECT