0

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?)

sewo
  • 330
  • 1
  • 3
  • 14

2 Answers2

2

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.

Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
  • Yeah, i noticed that mostly floats are used, but i found out that i can do the same just with position, width, left, rigth, etc... So there is commonly no other way as using floats or working with position. All others are less supported or no really god... And not - like the other answerer told - dozens of ways to do this...Am i right? – sewo Jan 22 '12 at 18:32
  • Like I said, the exact details are what matters - not *just* the overall technique. I honestly don't know what the other answer is talking about (sequence of inline-blocks?), it's extremely vague - but then again, so is your question. There are multiple ways to do most things in CSS. – Wesley Murch Jan 22 '12 at 18:35
1

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.

recursive
  • 83,943
  • 34
  • 151
  • 241
  • Ok, that should work too, but is there any best practice or what else can you do? Are there really dozens of ways to do this? Can you tell me some more please? – sewo Jan 22 '12 at 02:12
  • It's very situation-dependent, which way ends up the "best practice". Can you give more information on what you're up to? – skybondsor Jan 22 '12 at 03:44
  • Nothing specific. Just started to think about different layouting techniques and what's the best. And wondered if there is anything else i didn't know about. Is there something recommended for standard div-box-three-column-layout. In the past i did this alway with floats but recognized i can do this also with absolute and relative position. Or if want to layout forms, doesn't it matter what i use? What are the advantages of position or float or any alternative? – sewo Jan 22 '12 at 13:34
  • Can you give me maybe some good article on that topic, if there is no best practice for all needs? or tell me a little bit more about it. thanks. – sewo Jan 22 '12 at 13:39