CSS display: inline-block: why it rocks, and why it sucks
Usually when you want a horizontal list, you need to use float in the CSS code to make it work, with all its drawbacks. However, there is an alternative with display: inline-block.
Problems with float
The problem when you have float in your CSS code is that you need to take some precaution to make the surrounding element to encompass the floated elements, and also to avoid following elements in the code to sneak up next to it. Another problem is that if you have a floated list that will take up several rows (visually speaking) and the content is of varying height, you are in for a world of hurt.
Enter display: inline-block
This is where the magic value inline-block for the display property comes into play. Basically, it’s a way to make elements inline, but preserving their block capabilities such as setting width and height, top and bottom margins and paddings etc. A simple example will look like this:
<style>
ul#display-inline-block-example,
ul#display-inline-block-example li {
/* Setting a common base */
margin: 0;
padding: 0;
}
ul#display-inline-block-example li {
display: inline-block;
width: 100px;
min-height: 100px;
background: #ccc;
}
</style>
<ul id="display-inline-block-example">
<li>Item one</li>
<li>Item two</li>
<li>Item three</li>
</ul>
Rendered results
- Item one
- Item two
- Item three
As you can see, display: inline-block; helps us here to render three square gray boxes next to each other. Awesome, right? However, with varying content, we need to add the property vertical-align: top to mkae sure everything is aligned to the top.
<style>
ul#display-inline-block-example,
ul#display-inline-block-example li {
/* Setting a common base */
margin: 0;
padding: 0;
}
ul#display-inline-block-example li {
display: inline-block;
width: 100px;
min-height: 100px;
background: #ccc;
vertical-align: top;
}
</style>
<ul id="display-inline-block-example">
<li>Item one</li>
<li>Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two</li>
<li>Item three</li>
</ul>
Rendered results
- Item one
- Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two
- Item three
This will render just fine in Firefox, Safari, Google Chrome and IE 8. However, for older versions of Internet Explorer, we need to trigger hasLayout and also use a little hack to set the display to inline (note that this code could be in a separate stylesheet for IE, included via conditional comments – it’s inline here out of simplicity for this example):
<style>
ul#display-inline-block-example,
ul#display-inline-block-example li {
/* Setting a common base */
margin: 0;
padding: 0;
}
ul#display-inline-block-example li {
display: inline-block;
width: 100px;
min-height: 100px;
background: #ccc;
vertical-align: top;
/* For IE 7 */
zoom: 1;
*display: inline;
}
</style>
<ul id="display-inline-block-example">
<li>Item one</li>
<li>Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two</li>
<li>Item three</li>
</ul>
Rendered results that will work in IE 7 too
- Item one
- Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two Item two
- Item three
The enormous drawback
I hope so far that I have managed to get you to realize the potential and simplicity of this approach. However, there’s one giant drawback, that might or might not apply to your use case. That is, since the elements become rendered inline, white-space in your HTML code will affect the rendering. That means, if we want perfect size and alignment, but we have space between the LI elements in our code example, it will render a 4 pixel margin to the right of each element.
Case in point, let’s make it more clear by giving the surrounding UL element a fixed width, wherein the LI elements should fit:
<style>
ul#display-inline-block-example,
ul#display-inline-block-example li {
/* Setting a common base */
margin: 0;
padding: 0;
}
ul#display-inline-block-example {
width: 300px;
border: 1px solid #000;
}
ul#display-inline-block-example li {
display: inline-block;
width: 100px;
min-height: 100px;
background: #ccc;
vertical-align: top;
/* For IE 7 */
zoom: 1;
*display: inline;
}
</style>
<ul id="display-inline-block-example">
<li>Item one</li>
<li>Item two</li>
<li>Item three</li>
</ul>
Rendered results
- Item one
- Item two
- Item three
As you can see, the third item will now fall down to the next row. Which sucks! Hard! However, if we were to place the LI elements directly after each other, they would all be rendered in the same line:
<ul id="display-inline-block-example"> <li>Item one</li><li>Item two</li><li>Item three</li> </ul>
Conclusion
So, the conclusion is that white-space dependent rendering blows! But, there are also great possibilities with display: inline-block, so I advise you to try it out, play around with it and see if it works fine in your specific context.

114 Comments
February 24th, 2010 at 13:53
A little trick to overcome the white-space issue, but still have more or less readable/maintainable code, is to wrap line endings and indentation inside HTML comments:
<code><ul id="display-inline-block-example"><!–
–>Item one<!–
–>Item two<!–
–>Item three<!–
–></code>
It still looks a little messy, but at least it’s more readable compared to a one-liner.
February 24th, 2010 at 14:09
Or you could – gasp!- lose the end-tags…
Was that me who said that? No….
February 24th, 2010 at 15:07
Very interesting post Robert!
As usual, I have a few thoughts to add
White-space dependent rendering is usually a very-bad-idea[tm].
Different developers might not understand that they've made invisible mistakes when updating your carefully crafted code. I am not suggesting we should cater to the lowest common denominator, but this shit is tricky to spot.
Also, you have no control over what happens to your code once it leaves the server, different proxies do very different things to html, and then there is Opera Turbo … does anyone know how it treats whitespace? Some sites suggest that it uses OBML (Opera Binary Markup Language) to transfer pages … I wouldn't be surprised to find that it "optimizes" whitespace.
Furhtermore, the http://reference.sitepoint.com/css/display seems to suggest that IE7 automagically triggers hasLayout for elements with inline-block display, yet you set it in your example. Any thoughts on the different perceptions on this?
February 24th, 2010 at 15:11
I use inline-block from time to time. It can save you a few lines of extra CSS, getting floats to behave. And I love how logical IE7 is — first you declare something inline-block, then switch it to inline to get it working, because that makes perfect sense.
February 24th, 2010 at 18:53
Mathis,
Good input! I have tested that approach, although it indeed feels quite messy.
Lars,
Man, that's pragmatic.
But yes, it would work.
Morgan,
Thanks!
And yes, white-space dependent code sucks, and with the associated trickery, it becomes a maintenance/code handover risk.
With IE 7, in my testing at least, setting hasLayout and changing display to inline has been necessary.
David,
Yeah, IE 7 is a mess…
February 25th, 2010 at 4:35
this can fix the last problem
ul{letter-spacing:-.25em}
li{letter-spacing:normal;}
ul's letter-spacing value is different by font, it may be:
Verdana -.5em
Arial -.25em
Tahoma -.333em
see more http://www.99css.com/?tag=inline-block
you can translate it from chinese to english by using google translate:)
February 25th, 2010 at 12:18
ytzong,
Interesting! I need to experiment with that!
February 25th, 2010 at 12:56
I recently used "display:inline-block" and came the same conclusion.
I have another fix to propose:
ul{font-size:0}
li{font-size:13px;}
In theory you should not be bothered anymore with white-spaces.
February 25th, 2010 at 15:48
Thomas,
Cool, another option to test!
February 25th, 2010 at 16:23
@Thomas
Google's Chrome Browser can't define font-size which value less then 12px at least on chinese version, so your method would be unavailable
February 26th, 2010 at 1:43
The white-space issue is also apparent when using display: inline.
February 26th, 2010 at 11:02
ytzong,
Interesting, didn't know that about Google Chrome.
John,
Absolutely, good point.
February 26th, 2010 at 16:12
I've been using this approach a lot more recently — for layout as well as lists — and I really don't see the white space thing as a serious issue. You just need to be aware of it. And while floats can be made to work in these types of situations, they feel more "hackish" to me and can be a real pain.
February 26th, 2010 at 17:49
Peter,
Right, getting floats to behave exactly as desired can definitely be a pain.
February 27th, 2010 at 14:24
[...] http://robertnyman.com/2010/02/24/css-display-inline-block-why-it-rocks-and-why-it-sucks/ [...]
February 27th, 2010 at 17:29
Just wondering, but wouldn't the whitespace property applied to the ul tag be helpfull ?
Didn't test it out or anything, just a hunch
February 27th, 2010 at 21:59
I just happened to be visiting this page using an old Mozilla 1.7 browser. Lotsa rendering problems here.
February 27th, 2010 at 23:21
<code>:before { content:'009'; }</code> is one way to fake whitespace (e.g., indenting) if it is not in HTML.
February 28th, 2010 at 13:30
Here’s another fix for the problem, using a monospaced font and negative values for <code>margin-left</code> and <code>margin-right</code>: http://nerd.vasilis.nl/remove-whitespace-inline-b…
March 1st, 2010 at 9:32
[...] CSS display: inline-block: why it rocks, and why it sucks Via / CSS Globe [...]
March 1st, 2010 at 13:35
Jan,
It's an interesting thought, but apparently it can't be used to remove white-sapce.
Jon_E,
Yes, since this is a private web site, there's no time or need, from my point of view, to adapt a design to a web browser used by less than 0.01% of my visitors.
Sarven,
It's interesting, but only in web browsers that support the <code>:before</code> pseudo protocol.
Mathias,
Interesting! Seems a bit tricky, but might be a viable option. Thanks!
March 1st, 2010 at 17:44
This is a great article about css inlin display, very helpful and informative.
March 1st, 2010 at 17:47
Jordan,
Thank you!
March 1st, 2010 at 19:15
Display:inline-block is also handy when you want to align traditionally block-level content ( say a list or a small form ) within a line-box ( The block level parent ). Remember vertical-align:middle or text-align:center ? This all works with elements that are display:inline-block. Rarely needed, but nice to have when you need it.
March 1st, 2010 at 19:18
dougwig,
Absolutely, good point!
March 2nd, 2010 at 14:31
CSS display: inline-block: why it rocks, and why it sucks…
Usually when you want a horizontal list, you need to use float in the CSS code to make it work, with all its drawbacks. However, there is an alternative with display: inline-block….
March 2nd, 2010 at 23:34
inline-block is the shizzle! In my opinion floats were never meant to be used as a complex layout mechanism, but rather for having text wrap around images and stuff like that.
One huge advantage is that it removes all the hassle of clearing. On the downside though is the gap issue that you mentioned. Is there any logical reason as to why it should behave that way?
March 3rd, 2010 at 11:44
Anders,
Yep, the gap is the only actual issue with it. I believe it comes from a long, troublesome heritage of respecting white-space between inline elements, which is, if you ask me, a terrible thing.
March 4th, 2010 at 21:25
Hi there,
i'm not exactly sure (I'm french) to understand, but problems I often encountered with float, came from "clear" property from the parent element.
To solve it, I use "overflow:hidden" property on parent element, for exemple :
<code>
ul#display-inline-block-example,
ul#display-inline-block-example li {
/* Setting a common base */
margin: 0;
padding: 0;
}
ul#display-inline-block-example {
display: block;
position:relative;
overflow:hidden;
width:100%;/*for exemple*/
}
ul#display-inline-block-example li {
float:left;
width: 100px;
min-height: 100px;
background: #ccc;
}
</code>
What do you think about this tip ?
March 5th, 2010 at 11:32
Christophe,
Using <code>overflow: hidden</code> to make a parent element contain all its floated children elements is a great approach, but it won't be sufficient when the floated children span across multiple rows and and when the items aren't of equal height.
March 7th, 2010 at 5:42
Tables! Let do all the work!
tOM
March 7th, 2010 at 5:44
(actually meant <td>)
March 8th, 2010 at 12:01
tOM,
Well, there are a number of downsides to that to, in terms of semantic value and representation, certain lack of width control etc.
March 23rd, 2010 at 9:21
[...] ???????float:left; ????display:inline-block; ????????? ?????CSS display: inline-block: why it rocks, and why it sucks [...]
April 26th, 2010 at 22:03
[...] According to Robert Nyman: Basically, it’s a way to make elements inline, but preserving their block capabilities such as setting width and height, top and bottom margins and paddings etc. [...]
June 1st, 2010 at 19:59
Hi Robert!
Thank you for this interesting article!
For my personal usage, "display: inline" rocks
I use it to get perfect images gallery and I align for example 3 thumbnails horizontally on a line with equal space on the left and right of my pics.
My CSS code is very simple as I use a "float:left;" with "width:33%;" and an img class including "display: inline".
I used to have display:block and my thumbnails were not perfectly centered. When I switched to inline, they just moved to a perfect equally aligned position.
So for me, yes this is a magic value
Cheers!
Roger
June 2nd, 2010 at 2:08
Roger,
Glad you liked it!
July 9th, 2010 at 17:23
Thank you.
/* For IE 7 */
zoom: 1;
*display: inline; was important for me.
July 25th, 2010 at 13:33
[...] » CSS display: inline-block: why it rocks, and why it sucksRobert’s talk – Web developm… [...]
September 1st, 2010 at 22:18
[...] [...]
September 27th, 2010 at 17:37
Hello,
Have you tried a mix between <code>font-size: 0</code> on parent, and <code>letter-spacing: -1px</code> to prevent the font-size bug on Chrome ?
This seems to work on every browsers
September 27th, 2010 at 18:19
Matbaa,
Yes, that's a good way to trigger layout.
Raphael,
Thanks! It's an interesting approach, but part of me just fear that font-size: 0 could affect some devices (e.g. all kinds of mobile web browsers) or just break in the future, so I would be afraid to use it.
But, perhaps it just magically works for all.
September 27th, 2010 at 18:22
So we just have to wait that CSS3 white-space-collapse: discard; is understood by some browsers
September 28th, 2010 at 12:37
Raphael,
Exactly!
September 30th, 2010 at 21:31
nice posts.. thanks….
October 8th, 2010 at 12:43
[...] you need to know more about inline-block, then check the site here, it’s a good overview (even if it’s a little over the top on the “drawback” [...]
October 15th, 2010 at 9:29
Dang. The <code>font-size:0;</code> works pretty good. My Windows machine is acting up so I can't test it right now, but it looks fine for now. I've always just worked with the inline coding when using inline-block. Not a biggie.
One thing I love about inline-blocks too is the ability to put block elements inside of them. It makes navigation and pagination awesome because you can center stuff.
This is my snippet of code I use for inline-blocks. I'll usually assign multiple elements to it so I don't have to put it in my CSS twice.
<code>
#element_1,#parent > div{
display:inline-block; /* For modern browsers */
*display:inline; /* Hack for IE 7 and less */
zoom:1; /* Hack for IE */
_height:1%; /* Hack for IE6 */
vertical-align:top; /* Just makes sure everything is at the top */
}
</code>
I use inline-blocks for everything now. All my layout is inline-blocks.
October 15th, 2010 at 11:18
Buttars,
Good point!
October 17th, 2010 at 18:46
[...] http://robertnyman.com/2010/02/24/css-display-inline-block-why-it-rocks-and-why-it-sucks/ [...]
November 6th, 2010 at 16:33
[...] CSS display:inline-block: Why It Rocks and Why It Sucks [Robert Nyman] [...]
December 1st, 2010 at 5:58
Robert,
Thank you for writing this!! ‘display:inline-block’ helped me with a problem I had while trying to make a navbar that was coded in the HTML as a list and had a set background image for a:hover.
I am a total newb, but this helped with the whitespace problem for me:
#menubar ul li a {
margin-right:-4px
}
It seems like a really simple solution, and it looks great in firefox, but will I have trouble down the road across browser platforms??
December 1st, 2010 at 10:32
davo2323,
You’re welcome!
Your solution might work, but there is also, as you mention, a possible risk cross-platform.
December 21st, 2010 at 21:02
[...] Traduzido e adaptado daqui. [...]
January 28th, 2011 at 1:43
what about white-space:nowrap ? I’ve used this to get around the white-space issue with inline-block. Obviously then on one line…
January 28th, 2011 at 8:57
SirG,
Well, if you have it all on one line, it could work, although its main purpose is to take care of white-space within an element’s content.
But then again, as long as you have no white-space in your HTML in the beginning it would work to, but it’s not an optimal approach.
February 11th, 2011 at 22:27
Beautiful tutorial! As a web developer quite embarrassingly I haven’t used inline-block but definitely plan to from here on out. Thank you.
February 13th, 2011 at 21:52
Eric,
Thanks, glad you liked it!
February 16th, 2011 at 14:36
[...] display: inline-block comes to the rescue. But this new tool in my chest is not perfect. In “CSS display: inline-block: why it rocks, and why it sucks,” Robert Nyman [...]
February 23rd, 2011 at 8:41
[...] Inline-block: why it rocks, and why it sucks Jag har lagt en del tid på att få inline-block att fungera om man zoomar i sin browser, men ett elakt white-space förstör. [...]
March 20th, 2011 at 13:51
[...] CSS display: inline-Block: Why It Rocks, And Why It Sucks [...]
March 22nd, 2011 at 19:53
I didn’t know the “strong” tag could be used inside CSS
March 23rd, 2011 at 9:57
rolfen,
Ha ha! Formatting error – it’s fixed now.
April 6th, 2011 at 7:09
Lars Gunther wrote:
Why does that work? It seems like magic…
April 6th, 2011 at 9:59
Sparrow,
The magic of the web browser automatically self-closing the tags…
June 17th, 2011 at 15:56
[...] FUENTE: http://robertnyman.com/2010/02/24/css-display-inline-block-why-it-rocks-and-why-it-sucks/ [...]
July 8th, 2011 at 11:39
I can say that I’m quite a floater, but after I’ve checked some sites with CSS lint it said I use too many floats.
I knew about ‘display: inline-block’, but never got it act the same like floats until I found your useful article.
Thanks for the article and also thanks to some commentators that came with useful additions to it.
July 9th, 2011 at 0:30
Ralph,
Glad it was of use to you!
August 5th, 2011 at 16:58
A better solution for list items is to use:
nav li{float:left; width:auto;}
Has exactly the same visual effect without the headache.
August 5th, 2011 at 20:08
Louisa,
That will not work with content over multiple rows, where the content isn’t of equal height.
August 15th, 2011 at 2:27
Here’s how I get rid of the white-space:
<ul>
<li>block1</li
><li>block2</li
><li>block3</li>
</ul>
It’s perfectly valid, and I haven’t seen anyone mention it here yet…
August 15th, 2011 at 12:29
stephband,
It is, but it’s sad to have to use such an approach, I think.
August 21st, 2011 at 16:32
hi,
very helpful U solve one of my biggest probs with lists…
tnx tnx tnx!
August 31st, 2011 at 13:00
haha stephband ,you are genius!
September 16th, 2011 at 19:20
Though you might be interested in my CSS framework that uses inline-block. I use a monospace font to eliminate the whitespace issue. I’ve tested in thoroughly on all browsers. Obviously Firefox < 2.0 has rendering problems but I'm prepared to live with that. I also use a hack to target Opera because it doesn't understand negative letter-spacing on inline-block nodes, so I have to use word-spacing.
Anyhoo, check it out guys and let me know what you think.
September 16th, 2011 at 22:58
camslice,
Cool, thanks for sharing!
September 17th, 2011 at 16:14
This article saved my day: CSS display: inline-Block: Why It Rocks, And Why It Sucks
October 2nd, 2011 at 16:49
As soon as browsers start to support display:box or display:grid, inline-block will be obsolete.
October 5th, 2011 at 2:22
I’ve been converting a bunch of forms that use tables to using div/span and had already been using the inline-block to get everything to align horizontally but the vertical alignment was not how I wanted. Your suggestion of using the (I guess obvious now) “vertical-align:top” works great. Excellent and helpful post.
David
October 5th, 2011 at 8:58
davidtg,
Glad it was of help to you!
October 8th, 2011 at 5:40
Thank you so much for the tutorial. This saved me tonight!!!!
October 12th, 2011 at 13:28
Fantastic, been struggling with centered lists for years, this solves all my issues! Ta.
October 12th, 2011 at 17:07
Brandon, Laurence,
You’re welcome!
October 13th, 2011 at 22:17
very cool tutorial! i’m thinking of abandoning floats for layout and using display:inline-block or CSS tables framework here http://www.vcarrer.com/2010/10/two-lines-css-framework.html
@camslice or @Robert, was there a link included in his/her comment for us to view an alternative solution?
October 17th, 2011 at 16:30
Chris,
No other link, unfortunately.
And good luck! I believe inline-block and such can be good in some scenarios, but also find floats to still be a viable solution.
October 19th, 2011 at 4:53
[...] Robert Nyman???? Basically, it’s a way to make elements inline, but preserving their block capabilities such as [...]
October 21st, 2011 at 21:19
[...] See also: http://robertnyman.com/2010/02/24/css-display-inline-block-why-it-rocks-and-why-it-sucks/ [...]
October 22nd, 2011 at 1:42
Thank you for this helpful article (with helpful comments also)!
I thought I ‘d never figure this alignment stuff out. Finding your site made my day! =)
October 22nd, 2011 at 11:20
missycola,
Good to hear!
November 2nd, 2011 at 21:50
Just throwing in 2 cents: it seems inline-block only works in quirks mode for Firefox. In all DOCTYPE instances I tested, having DOCTYPE declaration at all, causes inline-block to behave as though it were inline instead.
November 2nd, 2011 at 21:57
Declaring any type of DOCTYPE causes Firefox to display inline-block to behave as if display:inline rather than inline-block. QUIRKS Mode specific, which leaves off all the good functionality of the robust doctypes. Seems like its an either or.
November 3rd, 2011 at 0:00
[...] It may suit your needs better, but it’s difficult to say. display: inline-block comes with rendering drawbacks, as does float of [...]
November 3rd, 2011 at 3:36
Cypher,
Not really sure where you get that from: display:inline-block definitely works with a strict doctype in Firefox, and has always done so.
November 14th, 2011 at 5:05
For those who like the font-size:0 solution but want to preserve the relative size of their font (which is important for accessibility):
ul {font-size:1%}
li {font-size:font-size:10000%;}
November 14th, 2011 at 21:29
Nicolas,
Cool, thanks for the tip!
December 4th, 2011 at 14:42
Hi,
to get rid of the white space issue
ul#display-inline-block-example li
{ ..
white-space: nowrap;
}
might work.
December 5th, 2011 at 10:25
Hanno,
Sorry, but that only applies within element contents, not between elements.
December 6th, 2011 at 18:58
To use inline-block, even for page layout, you should use the following CSS:
.container {letter-spacing: -4px;
word-spacing: -4px;
}
.container .inline-block-element {
display: inline-block;
vertical-align: top;
letter-spacing: normal;
word-spacing: normal;
/* for older IE's, as mentioned in the poster's original article */
zoom: 1;
*display: inline;
}
The above has been tested cross-browser and cross-platform. I’m not sure if anyone has posted about this in the comments but using inline-block for layout is the only way for centre aligning variable width content blocks or menu items, for example.
More about using inline-block for page layout on my blog: Holy Grail 3 column layout without using float
December 7th, 2011 at 14:57
BlueAngel,
It’s true about vertical aligning, although overall I don’t find it to be the best approach for main layouts. I just find it counter-intuitive with negative margins and such, even if it works in practice.
December 10th, 2011 at 3:22
Very usefull when i put social icon on the right top of my site, thank you very much for this tutorial!
December 13th, 2011 at 12:14
BlueAngel,
I wouldn’t relay on that. The right gap width is proportional to the font-size; i.e. you get 4 pixels when the parent element font-size is between 12 and 15 pixels.
This is also the reason why setting the parent element font-size to zero can be a fix to the issue.
December 24th, 2011 at 6:45
Something you can do to get around the white space issue, in some instances, is wrap the inline content in a container, and set the background image/styling for the container…sure you still have the “dead space” but visually your vistors won’t be the wiser. Of course, this isn’t a perfect solution for 100% of instances, but it works in some cases.
December 31st, 2011 at 1:18
Patrick,
Yep, it could work in some cases, but it’s not really optimal.
January 3rd, 2012 at 4:19
I always carried a bit of hate for display inline block, mainly because it doesn’t work with older versions of IE (surprise!). However, I might give it a go in my next project now that I know how to properly use it. Thanks for sharing this with us!
January 3rd, 2012 at 8:25
Adele,
Yes, there is a way at least. Good luck!
January 4th, 2012 at 14:50
Actually this is wrong:
“Basically, it’s a way to make elements inline, but preserving their block capabilities such as setting width and height, top and bottom margins and paddings etc.”
Since top and bottom margins, paddings osv. is ignored for inline elements:
“If you try to add dimension to an inline element, some properties will be applied, some properties will be partially applied and others will not be applied at all. The most noticable properties are width, height, margin and padding.
Margins operate in the same way as padding on inline elements. In the example below, 50px of margin has been applied to all sides of the element. While the left and right edges are effected, the content above and below are not:”
Source: http://www.maxdesign.com.au/articles/inline/
January 4th, 2012 at 17:02
magnemg,
Not sure what you mean. As described by me in the sentence you quoted, they are like inline elements but with block element abilities like margin, padding etc on all sides intact (i.e. working).
January 9th, 2012 at 7:01
[...] For the menu elements, instead using float I chose the inline-block alternative. If you want to find out more about inline-block pros and cons, I’d recommend Robert Nyman’s article: CSS display: inline-block: why it rocks, and why it sucks. [...]
January 14th, 2012 at 19:00
Hi there! I want to thank you a LOT! You have explained that perfectly! I used that for the menu in my web site!
Again – THANK YOU!
January 14th, 2012 at 23:44
Hristiyan,
Good to hear – glad it was of help!
January 17th, 2012 at 18:26
Why dont you just use display: table-cell;
January 18th, 2012 at 10:06
Se3ker,
Because a table cell and inline block element don’t really have the same rendering characteristics.
January 25th, 2012 at 6:01
If you want to use 3 elements in line (300px total for 3*100px) – just set font-size:0 for container. This is very logical in this case and now you can use all benefits from inline-blocks, like align:justify!
January 25th, 2012 at 10:01
Vladimir,
Yes, it works. Although I’d argue that it’s not really logical with font-size for spacing.
January 25th, 2012 at 14:03
[...] For the menu elements, instead using float I chose the inline-block alternative. If you want to find out more about inline-block pros and cons, I’d recommend Robert Nyman’s article: CSS display: inline-block: why it rocks, and why it sucks. [...]
Write a comment