All About Display Properties in CSS - Things you must know

Photo by Greg Rakozy on Unsplash

All About Display Properties in CSS - Things you must know

ยท

3 min read

Hey guys, welcome back to the other blog in this blog we will be talking about one of the most confusing CSS properties. But before that do not forget to subscribe to the newsletter.

When I was in my initial days of learning CSS, I used to get confused about the properties of the display because there were so many. Now when I sorted myself I thought that there must be so many like me who get confused about this.

I promise you by the time you finish reading this blog you will not be having any doubts.

What is the significance of display property in CSS?

What is CSS?

The display property is responsible for the display behaviour of the element. Suppose you have a box and you want to put it in a particular place, you will do adjustments related to that. This same happens with the display property in the CSS.

Generally display properties sets the inner and other display types.

Types of the Display properties

There are majorly five types of display properties that are used widely and they are as follows -

  1. Block: By this, the element generates a box and gives it a full width.

  2. Inline: This makes the element take the space of its actual size.

  3. None: As the name suggests it will hide the element from the place. There won't be any space allocated to it.

  4. Flex: Using this in the parent element it can make child elements align in a column or row and give it auto width and height.

  5. Grid: It defines the container as a grid one and gives it the grid formatting.

Apart from these, there are a few more that can be as a sub-property.

display: inline-flex; // inline-flex will make the flex container an inline                     element while its content maintains its flexbox properties
display: inline-grid; // make the element inline while grid will make it a block-level element.
display: flow-root; // It always establishes a new block formatting context for its contents.

/* box generation */
display: contents; // 

/* multi-keyword syntax */
display: block flow; 
display: inline flow;
display: inline flow-root;
display: block flex;
display: inline flex;
display: block grid;
display: inline grid;
display: block flow-root;

/* other values */
display: table;
display: table-row; /* all table elements have an equivalent CSS display value */
display: list-item;

/* Global values */
display: inherit; // causes the element to take the computed value of the property from its parent element
display: initial; // initial always means inline , because that's the designated initial value of the property. 
display: revert; // resetsโ€ a property back to it's inherited value
display: revert-layer; //  rollback styles to the ones specified in previous cascade layers.
display: unset; // resets a property to its inherited value if the property naturally inherits from its parent, and to its initial value if not.

It will be very helpful for you if just try them all one by one. It will help you master these and will able to know their use.

Thank You

Thanks for reading this blog, if you like the article please sponsor it or bye me a coffee. ๐Ÿ˜Š๐Ÿ˜Š

Buy Me A Coffee

Did you find this article valuable?

Support Ishan Gaur by becoming a sponsor. Any amount is appreciated!

ย