Display:block vs inline-block in CSS

Display:block vs inline-block in CSS

In this post we will give you information about Display:block vs inline-block in CSS. Hear we will give you detail about Display:block vs inline-block in CSSAnd how to use it also give you demo for it if it is necessary.

we are going to learn about the difference between block vs inline-block in css with the help of examples.

Block

If we set display property with value block then those elements will occupy the entire space on the x-axis(horizontal line).

Each element will also start on the new line.

Let’s see an example:

<span>First item</span><span>Second item</span><span>Second item</span>
span{  display: block;}

Output:

Have you seen in the above image each span element is occupied the entire space on an x-axis.

By default in html we have block level elements which are div, h1 , p, form,li,article, footer, section etc.

inline-block

If we set display property with inline-block then those elements are positioned side by side on the x-axis.

<span>&lt;h1&gt;First heading&lt;/h1&gt;&lt;h1&gt;Second heading&lt;/h1&gt;&lt;h1&gt;Third heading&lt;/h1&gt;
h1{   display: inline-block;   padding:1rem;   border:1px solid;}

Output:

Here we have the output with h1 elements are positioned side by side.

Conclusion

The main difference between block and inline-block is block elements will starts with a new line and occupy the entire space on the x-axis(horizontal line), inline-block will place each element side by side on the x-axis.

Hope this code and post will helped you for implement Display:block vs inline-block in CSS. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US