0

Hi I have a question that has been bodering me for a while.I have seen many developers that when they try to position block level elements on the same line they use both:

float:left
display:inline

I myself only use display:inline-block for this and I get the same effect.A couple a weeks ago a developer suggested that I should use the above code but when I asked why he diden't answer.

If that developer is right then why should I use the above code?What is the difference?

Nistor Alexandru
  • 5,309
  • 9
  • 46
  • 71
  • I've never heard this, and just looking at it, `display: inline` *after* `float: left` I believe would overrule the `float` directive; if this works, my initial thought is it's a hack. Anyhow, if `display: inline-block` is working for you, use **that**. `float`s are abused and based on old techniques that sprang from the lack of something like `display: inline-block` in earlier browser versions (and IE's early buggy support of `float`). Some older versions of IE don't support it (I think IE8 was the first). But `inline-block` is the future-forward-proof method. – Jared Farrish Aug 11 '12 at 18:05
  • See [my answer here](http://stackoverflow.com/questions/11709501/is-there-a-way-to-have-elements-be-positioned-to-the-right-without-removing-them/11709780#11709780) and the comments under the question. And yes, I get a little *irritated* when people promote continued use of `float` for `inline-block` while ignoring the correctness of the latter in most cases. – Jared Farrish Aug 11 '12 at 18:10
  • Not sure why you'd declare `display: inline` rule in addition to the float. I never do. – steveax Aug 11 '12 at 20:06

1 Answers1

1

display:inline-block isn't supported on IE7 and below and a few other old browsers. I guess if you are supporting older browsers, you would need to use what the other developer suggested in conditional stylesheets.

Otherwise, it's just a hack that people are still using because it's what they already know, even though display:inline-block is better. The reason he didn't answer you about why is because he doesn't have a good answer, his answer would likely be simply 'because that's how I do it'.

Erika E
  • 337
  • 2
  • 7