I am trying to make a 2 column layout, apparently the bane of CSS. I know you shouldn\'t use tables for layout, but I\'ve settled on this CSS. Note the use of display: table
You said using display:table
for a great auto-width like columns?
I can't use css float, because I want the columns to expand and contract with the available space.
Then, you could also use flex properties! Let's get in that:
In CSS3 there were many properties added, there's one group called flex which is used to have flexible divs without using tables or display: table
; also used when the user's using a small screen (maybe a mini laptop, tablet, big smartphone like Galaxy series or small...?). These are the properties:
-webkit-
before the value (inline-flex
's also applicable) for Google and Safari support. You don't need to use -moz-
or -o-
, nor -ms-
.row
, column
, row-reverse
, or column-reverse
. Because of you want a main div and a sidebar, ya shall use column. Use -moz- and -webkit- for more browser support.main
(not recommended) or div class="main"
and aside
or div class="sidebar"
.-moz-
n -webkit-
plz.-webkit-
& -moz-
r Rcomment ed.Moar info at: http://css-tricks.com/snippets/css/a-guide-to-flexbox/ and http://www.w3schools.com/cssref/default.asp#flexible.
Oh, and here's the answer: yes, you can use it. Read at: http:/www.w3.org/TR/css3-flexbox/#intro. It says
table layout, designed for laying out 2D data in a tabular format
They doesn't talk about bad idea, it just sets its format to ACT (and maybe don't look like) like a table.
Using the display:table is fine when you're talking about semantics. The reason "tables are bad" in the first place is because the markup (HTML) is supposed to describe the content inside of it. So, if it's not data, it doesn't belong in a table.
Since you're just setting how the markup displays (in a table structure), that's perfectly fine.
However, this will not work for all browsers. Specifically IE6 and IE7 (and IE8 in "compatibility mode") will not display this correctly.
For more information on display types and browser support, you can refer to this: http://www.quirksmode.org/css/display.html
It would be swell if every possible layout could be done with css, with no tables or pseudo-tables in sight. But there are exceptions, and until html and css (and browser support) let us do it, be comfortable with your tables. The point, after all, is to satisfy your users, not to adhere to someone else's philosophy.