Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display:table versus using tables

I was wondering if it's a good idea to use CSS display property to emulate tables for a veeeery simple forum system.

I know this wasn't good thing to do like 2 years ago when IE and maybe others did not support display:table / table-cell etc. But I think now all browsers support it, right?

like image 406
Alex Avatar asked Jul 08 '11 20:07

Alex


People also ask

What is the purpose of display table?

Setting display to table makes the element behave like a table. So you can make a replica of an HTML table without using the table element and corresponding elements such as tr and td . For example, in HTML, you can make a table with the <table> element and also a <div> , or any container of your choice.

Is it ever okay to use TABLEs for layout?

The World Wide Web Consortium (W3C®) discourages use of tables for layout because they are striving for a web in which content and structure are completely separate from presentation.

Should I use table or grid?

If your intention is to display a table, an HTML table is your way to go. If your goal is to lay out content on a webpage, CSS grid is one way of doing that. It doesn't have perfect browser support yet so you might want to consider another option for layout, but it is an option. Tables were never meant for layout.

What is the use of display table in CSS?

The display CSS property sets whether an element is treated as a block or inline element and the layout used for its children, such as flow layout, grid or flex. Formally, the display property sets an element's inner and outer display types.


2 Answers

If the information being displayed on the forum is tabular, then don't be afraid to use a table if it makes sense semantically.

For general page layout, personally I wouldn't use it. I'd stick to the typical block-level div layouts and floats. IE7 does not support display:table and there are other caveats, such as the fact that it will expand in width based on content. For the future, I look forward to when flexbox is fully supported.

I do occasionally use display:inline-block for centering dynamic list items and the like.

like image 151
jwinn Avatar answered Sep 25 '22 13:09

jwinn


I wouldn't mix structure (HTML) with style (CSS). If it's tabular data, just use <table>s if it's not, you're best bet would to use divs/CSS.

like image 45
Phil Avatar answered Sep 23 '22 13:09

Phil