Sunday 27 March 2005
Gecko 1.8 For Web Developers: Columns
One of the big things I've been working on for Gecko 1.8 is support for multicolumn layout. Our implementation follows the CSS3 draft pretty closely. Right now we support the properties -moz-column-count, -moz-column-width, -moz-column-gap and (soon) -moz-column-rule.
Basically this lets you set up multiple columns like a newspaper, so that content flows from the end of one column to the top of the next column automatically. The big win is that you can use the full width of a large screen without making lines excessively long. This very blog is using columns on most entries --- check it out with a Firefox trunk build.
The draft specifies 'balanced' columns. This means that we automatically find a minimal height for a set of columns that balances the content as evenly as possible across the columns while fitting into the available width of the page. This is very powerful and you have to see it in action to appreciate what it does for you. However, balanced columns are inherently a little slow. Also, sometimes you want the columns to be a fixed height but extend horizontally as far as necessary to fit the content. We support that by extending the draft slightly; if the 'height' property on the column set is 'auto', we balance the columns and horizontal overflow doesn't happen, otherwise we do not balance the columns and horizontal overflow can happen.
Our implementation has a few limitations that cannot be fixed for 1.8:
Of course there are still some bugs but it's already in much better shape than it was a few weeks ago. In particular some huge issues involving floats breaking across columns have been fixed. Since we use the same code for page layout as for columns, this also means a lot of problems with printing (and print previewing) pages with floats have been fixed.
I'm really interested in having Web developers play with this feature, in particular to shake out any critical bugs. Some tips for using columns:
Please file Bugzilla bugs when you find we're doing something unexpected or not per spec. If you have other feedback you can email me personally or just blog about it and let me know.
Basically this lets you set up multiple columns like a newspaper, so that content flows from the end of one column to the top of the next column automatically. The big win is that you can use the full width of a large screen without making lines excessively long. This very blog is using columns on most entries --- check it out with a Firefox trunk build.
The draft specifies 'balanced' columns. This means that we automatically find a minimal height for a set of columns that balances the content as evenly as possible across the columns while fitting into the available width of the page. This is very powerful and you have to see it in action to appreciate what it does for you. However, balanced columns are inherently a little slow. Also, sometimes you want the columns to be a fixed height but extend horizontally as far as necessary to fit the content. We support that by extending the draft slightly; if the 'height' property on the column set is 'auto', we balance the columns and horizontal overflow doesn't happen, otherwise we do not balance the columns and horizontal overflow can happen.
Our implementation has a few limitations that cannot be fixed for 1.8:
- Tables don't break across column boundaries.
- Absolutely positioned elements don't break across column boundaries, even if the absolutes' container does.
- We don't always find the minimum height for a balanced column set, for example when the column set contains blocks with margin, borders or padding things can go wrong.
- We don't support the CSS properties for page break control, so you can get widows and orphans (a paragraph breaking just after its first line or just before its last line). And you can't prevent breaks from happening without using hacks.
- There is no way to make content in one column span multiple columns. In the future we may allow content in a column to flow around overflowing floats in previous columns, but we're not going to get that in this release.
Of course there are still some bugs but it's already in much better shape than it was a few weeks ago. In particular some huge issues involving floats breaking across columns have been fixed. Since we use the same code for page layout as for columns, this also means a lot of problems with printing (and print previewing) pages with floats have been fixed.
I'm really interested in having Web developers play with this feature, in particular to shake out any critical bugs. Some tips for using columns:
- Watch out for content that horizontally overflows the column it's in. The next column will draw right over it.
- Thus, it might be a good idea to put a DIV inside a columns element and give it a background color, and put the rest of your content inside that.
- Column balancing can be slow. Unbalanced columns give faster layout.
- People have always thought of elements as being rectangular, thus we have Javascript properties like clientX, clientY, clientWidth, clientHeight etc. That was never true for inlines, and now it's not even true for blocks. Those properties will just give you the first rectangle of many rectangles that might make up the block. Beware.
Please file Bugzilla bugs when you find we're doing something unexpected or not per spec. If you have other feedback you can email me personally or just blog about it and let me know.
Comments
Screenshot:
http://www.jeria.net/mozilla/columns_bug.gif
And make new properties for getting the real coverage. ( As a list of paths? Dunno what would make sense for this. )
PS. I really mainly posted to imitate your subheader, because I thought it curious to be proclaiming being a christian. ;-)
rjw: that doesn't seem very useful. Consider a paragraph that has one line at the bottom of column 1 and a second line at the top of column 2.
Peter: :-)
In http://weblogs.mozillazine.org/roc/archives/2005/03/gecko_18_for_we_1.html when I hit reload, only part of the page (up till and including the columns) is rendered; the rest is shown when I click and hold a link though.
I also saw part of the content disappear a number of times. E.g. when I have any of these columned blog entries and remove my (Sage) sidebar (at 1024x768). A third column appears, and half of the content disappears.
~Grauw
It is a bit of problem when you have longer articles, spanning more than one window worth of contents, though. But it is sure a fun thing to play with.
Implementing css3 media queries, would give more (better ?) control over width and text flow.
But thanks for implementing this.
Grauw: probably the same bug that's already filed. I will fix it.
Foxtrot: not sure what you mean