Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any guide on "When to use display:block when :inline and when :inline-block" and why?

Do you know any good article on "When to use display:block when :inline and when :inline-block" and why?

and when we will have to override display:?? through css for any HTML tag/element?

like image 362
Jitendra Vyas Avatar asked Jun 15 '10 06:06

Jitendra Vyas


People also ask

When should I use display block?

It's useful when you want to have small blocks flowing left-to-right, top-to-bottom like regular text, but still have them like blocks. Note: in 90% of cases you don't need to specify the display property, just use appropriate elements with classes, like <strong> or <em> for inline, <div> or <p> for blocks.

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's one advantage to using inline-block over inline display?

No need to clear floats anymore. Compared to display: inline , the major difference is that inline-block allows to set a width and height on the element.

What does inline-block display do?

“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

inline - Treats the element as though it were an inline chunk of text. width and height are meaningless

block - Treats the element as as rectangle. width and height can be specified

inline-block - Flows a element inline with the text, but allows width and height to be specified.

Elements default to one of these anyway. For example:

<span>, <em>, <strong> -> inline

<div>, <p> -> block

like image 190
Eric Avatar answered Oct 25 '22 19:10

Eric


quirksmode.org has a good explanation with screenshots:

http://www.quirksmode.org/css/display.html

like image 35
Warren Rumak Avatar answered Oct 25 '22 17:10

Warren Rumak