Is there a practical difference between whether a left-floated element (say, and image) has display: inline-block; applied to it, as opposed to leaving the default display: block; rule applied?
In other words, what's the difference between:
<div style="float: left; display: inline-block;">text</div>
and
<div style="float: left; display: block;">text</div>
?
An answer by @thirtydot might help you... Question's link
Yes,
display: block
is redundant if you've specifiedfloat: left
(orright
).display: inline
will not make any difference, because settingfloat: left
forcesdisplay: block
"no matter what":http://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo
To summarize said table:
float
=display: block
.However, your specific example of
float: left; display: inline
is useful in one way - it fixes an IE6 bug.Some examples:
position: absolute
, thenfloat: none
is forced.top
,right
,bottom
,left
properties will not have any effect unlessposition
has been set to a value other than the default ofstatic
.I don't think so. It's not something that is ever needed, so I can't see why anybody would have written such a tool.
When you use
float: left;
almost any elements behave as ablock
element. So there is no any difference in this particular case.You don't have to specify a
float: left
and adisplay: inline-block
for the same element, you use one or the other, not both. Float is used to float text around elements, its not the best weapon to choose when doing a layout. Go with display: block, and inline-block.http://joshnh.com/2012/02/07/why-you-should-use-inline-block-when-positioning-elements/
Block elements — form boxes according to the css box-model. They have width, height, padding, border, and margin and they stack vertically on top of each other.
Inline elements — don’t form boxes. They sit horizontally next to each other.
Inline-block elements — act like block elements on the inside where they form boxes. On the outside they act like inline elements sitting horizontally next to each other instead of stacking on top of each other.
A good resource: http://learnlayout.com/inline-block.html
According to SitePoint:
http://www.sitepoint.com/give-floats-the-flick-in-css-layouts/