css Column/Grid-Layout: position or float. Any alternatives to that?

1.6k views Asked by At

As far as i know and understood, there are two possibilities to build a colum-layout or grid-layout or to position elements in a more complex way with css:

1)position:absolute/relative;

2)float:left/right; clear

Are there any alternatives to that and what is better or is less supported or doesn't it matter at all which technique you use? What is best practice with best browser support?

Told or known alternatives:

3) display: inline-block;

4) display: table-cell; (isn't it the same as html-tables?)

5) html-table (but that's not css or semantic)

6) css3 columns (less support or not?)

2

There are 2 answers

4
recursive On

You could use a sequence of inline-blocks for columns as well I think. Or maybe display: table-cell as well. There are probably dozens of ways of accomplishing it.

2
Mog On

1) position:absolute/relative;

Can be part of a layout, not necessarily.

2) float:left/right; clear

Yes, float is commonly used for layouts.

3) display: inline-block;

This is rarely if ever used for page layouts, and support for it is buggy (it's also white-space sensitive).

4) display: table-cell; (isn't it the same as html-tables?)

No, it's not the same as using HTML tables. Tables are in your markup (content), display:table-* is part of your CSS (presentation). This is a nice way to tackle a layout but once again, support is not totally there for older browsers.

5) html-table (but that's not css or semantic)

You're right, don't use this, tables are for marking up tabular data, not for layout.

6) css3 columns (less support or not?)

Once again, support isn't really there, and I believe this is meant for text more than for layout (even if it could be used for both).

What is best practice with best browser support?

If you're looking for a general answer, you want to build this yourself, and you're concerned with browser support, just use floats, with relative/absolute positioning if necessary. Make a decision on exactly which browsers you want to support, and as always, test your layout in different browsers to see what works and what doesn't. There is no magic bullet, the devil's in the details.