I am coding for the homepage of a website. Shall I use tables or div for partitioning the homepage into sub-sections.
Can anyone clear my doubt that if partitioning is done with tables, it might not work well in mobile or tab devices??
I am coding for the homepage of a website. Shall I use tables or div for partitioning the homepage into sub-sections.
Can anyone clear my doubt that if partitioning is done with tables, it might not work well in mobile or tab devices??
Use <div>
instead of tables. Different browsers have different approach for plotting <table>
s in web pages, but for <div>
, there is a common standard. I strongly suggest you to stick with <div>
s.
In addition to that, the two top reasons for using Divs instead of Tables are
The ability of a Div to fill the space is just a nice feature to have - especially when working with fluid layouts.
You may refer to these articles:
I recommend you to use bootstrap for this. You will spend maximum 2 days to learn it. Here is link
And using div is better, than tables. You should use it with well formed css, and you page's will be really nice.
Tables
Tables generally increase the complexity of documents and make them more difficult to maintain. Also, they reduce a website’s flexibility in accommodating different media and design elements, and they limit a website’s functionality. Semantically speaking, the table tag is meant for listing tabular data. It is not optimized to build structure.
Ease of use
Using tables to build structure is quite intuitive. We see tabular data every day, and the concept is well known.
Also, tables don’t break when the content is too wide. Columns are not squeezed under other columns as they are in a div-based structure. This adds to the feeling that using tables is safe.
Maintainability
Table contains different tags: the table
tag being the wrapper, tr
for each row and td
for each cell. The thead
and tbody
tags are not used for structural purposes because they add semantic meaning to the content. For readability, each tag is normally given its own line of code, with indention. With all of these tags for the table, several extra lines of code are added to content. The colspan
and rowspan
attributes make the code even more complex, and any developer maintaining that page in future has to go through a lot of code to understand its structure.
Divs
The div
tag is a block-level element that defines a section within a document. Divs are thus suitable for building the structure of Web pages. The div
tag is also used to describe content that cannot be properly described by other more semantic tags.
Ease of Use
The div
element isn’t visual like the table
element. Everyone knows what a table looks like, but divs are not as obvious. The good thing about a div
, though, is that it’s only one element. It’s not wrapped in a parent element the way td
tags are in tables. The container, then, is more flexible and doesn’t have the limitations of its parent tag.
Using a div
for structure can make a page more fragile when content is pushing the div to its limit. It can also force columns to fall under each other. But this is usually only true for older browsers (particularly IE6); newer browsers make content flow to the next column.
Maintainability
The biggest problem with div
tags is that they are used too often. Divs should only be used to build structure and as placeholders for design elements when no other block-level elements can describe the content. The div
tag is for logical groupings of elements.
Nesting div
should be used with descriptive class and structure names makes the code more understandable.
Divs should be used when semantic block-level tags would better describe the content; for instance, headings should be wrapped in h1 to h5 tags. Writing semantic code usually reduces the code base; and less divs with floats helps keep browser bugs away.
Flexibility with Media
Div-based structure is more flexible in supporting different media than a table-based structure. Not having to maintain separate pages for each media saves maintenance and development costs. A div-based structure allows you to move columns around and even hide columns using display: none in the style sheet.