Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Float:left vs Display:inline? While every element in browser goes to left by default

Tags:

css

What is the differences between Float vs Display:inline? by default everything goes to left side in every browser. then 2 display inlined elements should be worked same like float:left.

http://www.w3schools.com/css/tryit.asp?filename=trycss_display_inline

like image 570
Jitendra Vyas Avatar asked Nov 09 '09 17:11

Jitendra Vyas


People also ask

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

Display:inline-block puts a particular space between two Display:inline-block elements, if not written continually. ^1 Whereas Float never put any space between two elements of its kind. Float floats elements to left with float:left and to right with float:right.

What is the difference between float and display?

A "float" directive, on an element, forces the browser to display the element out of the normal workflow, on the top-left or the top-right side of the webpage. The "display inline" directive forces the block elements to be displayed inline, so the browser manage these elements as explain above!

What is the main difference between display inline and display inline-block in CSS?

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 float and align in HTML?

Float allows other HTML elements to flow around the floating element. Align simply shifts an element to the left or right. Align - You use align to align text and other items rather it be left, right, centered, or justified. Align DOES NOT remove the item from the document flow.


2 Answers

display:inline means a element is will "stack" next to other items, like images, spans or the bold tag. This is opposed by block level elements (display:block) which take up horizontal space, imply a line break, and will not sit next to one another, like divs, paragraphs, or tables.

Think of it this way...

<img /><img /><img />  <div /> <div /> <div /> 

float is a different notion altogether, moving content either left or right. By default, a floated element is inline, and floated elements will stack up next to one another.

All of these types of elements are part of the normal document flow, meaning they take up "space" in the design that cannot be shared.

like image 96
Frank DeRosa Avatar answered Oct 05 '22 03:10

Frank DeRosa


There are two types of formatting: block level and inline. The block level formatting is done with a box model that uses a set of rules for layout.

Inline formatting is what text normally gets. It means, informally, that things are filled into lines.

At times, you want to change the default formatting an item will get. Something that normally might be block level formatted you might want to have treated as inline. A div containing content such as graphic of a key, for example, might need to be displayed within a sentence. One might then override its formatting with display:inline. Images are already displayed "Inline"

The CSS specification has a surprisingly simple definition for floats:

A float is a box that is shifted to the left or right on the current line. The most interesting characteristic of a float (or "floated" or "floating" box) is that content may flow along its side

So a float is a sort of third category of formatting model. It relates to inline as being, informally put, a layout model.

like image 22
DigitalRoss Avatar answered Oct 05 '22 03:10

DigitalRoss