Kilian Valkhof

Front-end developer, user experience designer & Jedi.

Random CSS Thought: Vertical-float

CSS & (X)HTML, 30 April 2007, 7 comments

Vertical floating is an idea I’ve had for some time now, but only recently really had a need for. Float:left; and float:right; are often used to float images or clear certain parts of the background, making the text flow nicely around it. And it’s used for good reason, it is a whole lot cleaner then manually putting <br /> tags at the end of each line of text.

Why only horizontal?

A couple of weeks ago, I was working on a website that had an image on the side which a portion of the text had to wrap around. Only, the image I wanted to clear was located in the lower right corner. I tried a couple of things, but in the end the only solution I had was to use <br /> tags to make sure the lower lines of text floated nicely around the image. After feeling reasonably ashamed for at least an hour, I began thinking about how I would like to see it done. So I came up with this solution:

Floating or sinking?

A short interruption with horrible pun, but we now continue with the article. Most CSS attributes have both a horizontal and vertical value. for example, background-position, margin, padding all give you the ability to select a horizontal and vertical value. It would be very useful to be able to use a vertical float value as well:


#foo {
	float:right bottom;
}

This should then result in the element floating in the lower right corner of it’s parent element, giving you the ability to float something, but measuring from the bottom upward. (Like how float:right gives you the ability to measure something starting from the right.)

I also thought about a vertical-float attribute, but that really is too much to write, and I quite like the simplicity of the above example. (Fine, so call me lazy. I’d like to call it efficient.)

Discussion

This would seem fairly easy to implement. I have quite some uses for it. how about you?

Other CSS thoughts
If you enjoyed this article, please consider reading any of my previous CSS thought articles:

Thank you for reading this article.

Please don't hesitate to leave a comment!

I am a front-end developer and user experience developer from the Netherlands, and I am available for freelance work. Contact me or ping me on twitter: @kilianvalkhof.

7 comments

  1. Without looking at any potential technical drawbacks there might be, I fully agree with this one. Something like this really should have been there in the first place, because the problem is just begging for a clean solution. I can’t believe that the CSS spec. authors never even considered the problem this would solve, so I wonder if it was just too technically awkward to implement.

    Another thing for CSS 3.1, maybe? ;)

  2. I love the idea. It would make header and footer images so much easier to align, instead of worrying negative margins, etc.

    You’re on a roll, Kil :D

  3. Sweet idea Kilian! And why can’t I use rel attrs in link tags on your blog? :p

  4. *hides behind his #1 excuse*

    Once I get my custom design done, I’ll add it in :)

  5. i assumed it did exist…i mean it’s such a basic basic concept…i found this page while trying to find whether there was such as thing as float:below or sink etc.

  6. I was looking for something like this too, and found a solution.
    In my case, I needed it to float left down. When I used float and clear, I got the results I wanted :D

  7. Would be decent yeah… I wanted to vertically float something at the bottom right of a table cell earlier… you can’t absolutely position it because the table repeats with different data-base driven content or different sizes!

    So i’ve had to drop what I wanted and resort to something else

Your response?

If you post code examples, make sure to escape your HTML.