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

Asked

Viewed 3,594 times

5

When testing with alignment of div, both have the same purpose

But what would be your difference?

  • You could post the code where it was tested?

  • 1

    In certain contexts they may have the same result, but it certainly does not have the same purpose.

3 answers

4

inline-block is the junction of behaviors inline (ex.: occupy only the space of the content, not break line) and block (eg: configurable dimensions) in a single HTML element

float causes the element to fluctuate in the direction specified above the other HTML elements.

They may be similar because the float adds some features that the inline-blockalso possesses, but not all.

2

  • Great reference article! I’ve always used/use the float, but I found the comparisons interesting... maybe start testing the inline-block also.

1

Float property

Display property

Float: left;

The element floats to the left

Display:inline-block

Displays an element as an inline-level block container. The Inside of this block is Formatted as block-level box, and the element itself is Formatted as an inline-level box

Basically, the left float only throws things to the left, whereas the inline-block arrow they must acquire line shape while there is space and when the space runs out it, block-shaped, breaks to the next line.

At the beginning links have examples.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.