These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:21 pm Advanced search

Table-cell VS float

Here you can discuss things related to HTML and the Web in general that do not fit in to other categories.

Table-cell VS float

Postby smsulliva » Fri Oct 15, 2010 5:52 pm

I have a question about best practices when it comes to positioning in HTML5.
I've read here that they are using the display property of table and table-cell.
I also know everyone still talks about using float for positions too. What is the best practices to use?
smsulliva
<h6>
 
Posts: 1
Joined: Fri Oct 15, 2010 5:48 pm

Postby JAB Creations » Sat Oct 16, 2010 2:42 am

Tables are only intended for tabular data, in example the nutrition panel on the side of most food products is a good example if you're in America.

If you're formatting the layout of a page you're supposed to use divisible elements. (X)HTML5 has more specific elements for layout though the browser support just is not there yet and won't be for a few more years. However you should definitely use tableless layouts.

Take this code in example...

Code: Select all
<div style="background-color: #dff; float: left; width: 80%;"><p>content</p></div>
<div style="background-color: #ffd; float: left; width: 20%;"><p>sidebar</p></div>


To add padding you add a child divisible element and then add margins to the child, width and float only on the parent.
User avatar
JAB Creations
<aside>
 
Posts: 566
Joined: Tue Mar 13, 2007 4:48 am
Location: Sarasota Florida, USA

Postby Alan » Tue Nov 02, 2010 4:37 pm

Another alternative is the CSS3 flexible box model. There's an implementation in JavaScript for legacy browsers, too, though I haven't looked into it.

The new structural elements in HTML5 work cross-browser as long as you style them appropriately (e.g. all unknown elements usually default to display: inline). MSIE < 9 also needs a JavaScript hack to make them respond to styling (the trick is to create instances of each "unknown" element off-screen before the document body is rendered).

display: table-cell has nothing to do with HTML tables, though (other than making the styled element behave like a table cell). The reason you shouldn't use HTML tables for layout lies in their semantics, not their appearance. What CSS you apply to your elements doesn't have anything to do with that.
Alan
<h5>
 
Posts: 18
Joined: Sun Oct 31, 2010 2:16 pm
Location: Cologne, Germany


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests