You are reading...

September 9th

Tucked away in Firefox 3.0’s new feature’s page is this nugget

The display property’s inline-block and inline-table values are now implemented.

Finally, every web developer’s favorite browser fully supports one of the best alternatives to floats. To implement inline-block a layout simply write:
.column {
width:40%;
display:inline-block;
vertical-align:top;
}

Yes, you can use the vertical-align property. You will have to use this for column since the default vertical-align property is baseline. Not so useful in layouts, but great for galleries. There is a slight IE issue though. I believe in order for inline-block to work properly, IE has to think it is an inline element. So in your IE stylesheet, put this in:
.column {
display:inline;
}

If you don’t have an IE stylesheet. Get one. If you cannot get one, there is a bit of hackery involved. Add this in addition to the above codes.
#container > /* ie crap */ div {
display:inline-block;
}

This is assuming #container is the parent element of .column. Modern browsers would switch back to inline-block. IE, however, cannot read it if there is a comment in between the operator and the child element.

You can also use inline-block to build a next/previous bar.


.next, .prev {
display:inline-block;
width:50%;
}

.next {
text-align:left;
}

.previous {
text-align:right;
}

There is one issue I have encountered with inline-block. Simply put, 2x=y. But if x= inline-block element. 2x != y. I have yet to figure why that is the case. But for now make 2x < y if you encounter this issue.

If there is one reason I use inline-block over floats for layout, this is it. While developing this blog, I switched over to IE6 to do my usual fixes. Guess how many layout issues I ended up having?

Zero.

I kid you not. All the pain of fixing IE6 issues. Gone. That would never have never happened if I were still using floats. No floats also means no more clear divs. No use of clear at all. No more overflow:hidden. Don’t need to set the width of every damn child element.

In front-end web development, that means we are in heaven.

Later, I will show you the power of inline-block, including building a gallery with horizontally and vertically aligned images.

Together, we can break the hold floats have on our web development lives.

Leave a Reply





This is my Twitter status linked to my Facebook status. Annoying, huh?

My left hand hurts from all the COD4. Good thing I do the other thing with my right.

Tumblr : the other white short format blog.

And this is why I don't do photo editing... voluntarily
Tuesday, 6 January 2009, 7:56 pm

I don't remember much about NYE
Saturday, 3 January 2009, 9:19 pm

Hey Gweilo!
Saturday, 3 January 2009, 10:24 am

I must learn how to do this.
Saturday, 27 December 2008, 9:12 am

You can call me a Nissan Libertarian
Monday, 22 December 2008, 5:55 pm

So how is this not Guild Wars?
Wednesday, 17 December 2008, 8:26 pm

Old Bowl
Tuesday, 16 December 2008, 3:21 pm