Is it wrong to structure a form with tables?

Asked

Viewed 2,054 times

9

Today with the HTML5/CSS3 and its numerous ways to align the elements (Divs)

Is it wrong to structure a table form? Ex:

<form action="action" method="POST">
<table style="width:100%">
  <tr>
    <td>Nome</td>
    <td><input type="text"></td>    
    <td>Sobrenome</td>
    <td><input type="text"></td>        
  </tr>
  <tr>
    <td>Endereço</td>
    <td><input type="text"></td>    
    <td>Cidade</td>
    <td><input type="text"></td>    
    <td>Estado</td>
    <td><input type="text"></td>        
  </tr>
</table>
</form>
  • I think it’s not wrong but the idea is to structure with div’s.

  • It’s not that "it’s wrong", but "not recommended". Focusing everything on CSS makes it much easier to maintain the code, as well as readability.Not to mention that divs are more flexible than the tds of the table.

  • Regardless of what you asked, this table is unbalanced, it has more columns in the second row. It lacked a colspan in one of the first-line cells.

  • @bfavaretto yes, it was an example only...the question itself is the structuring of a form, css or attributes should be used either in table or in div

  • Wrong is a very strong word. Because of the recommendation tableless I’ll say it’s inappropriate

2 answers

8


Tableless

Tables exist in HTML for a single reason: To display tabular data. But then with the border="0" It became possible for designers to have a grid on which to place images and text. thus designing visually rich websites, the use of tables is actually a way to interfere with the development of a better, more accessible, flexible and functional Web. Let’s see what the problems are:

Beginning

At first, the Internet was essentially a means for academics, researchers, and the military to share information. However, it didn’t take long for business visionaries to realize that this new medium of communication was ideal for selling everything from fresh produce to hot dogs.

However, like anything else in his childhood, the Internet at first was aesthetically 'raw' (and was not appealing to consumers) until David Siegel published his reference book, which offered some brilliant solutions to the limitations of existing browsers and W3C specifications.

Problems with Tables

  • Mixing presentation data with content.
    • This makes your pages size unnecessarily large, so users need to download this presentation data every time they visit the page.
    • Band is not infinite, by the way, it is very scarce.
  • This makes redesigning existing sites and adding content an extremely difficult job (and expensive).
  • This also makes it extremely difficult (and expensive) to maintain the complete visual consistency of all pages of a website.
  • Table-based pages are also much less accessible using smartphones.

Best practice

Modern web-browsers follow web standards and we don’t need to use these archaic methods anymore for building pages.

Instead of tables inside tables, causing a huge problem to deal with later, we can use CSS to set positions and are faster to load, easier to redesign, and more accessible to all.

Utilize table only where you are sure it is a table

Where to use then?

We should date use the table tag. Think of it as an excel, normally data represented in excel, are tabular data, follow an example:

table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}
th, td {
    padding: 5px;
    text-align: left;
}
<table style="width:100%">
  <caption>Economia mensal</caption>
  <tr>
    <th>Mês</th>
    <th>Economizado</th>
  </tr>
  <tr>
    <td>Janeiro</td>
    <td>R$ 100</td>
  </tr>
  <tr>
    <td>Fevereiro</td>
    <td>R$ 50</td>
  </tr>
</table>

  • 1

    Just to be clear, tables (even nested on multiple levels) were only used for layout because they were for a long time the only cross-browser way to achieve the desired result. Who has no dog, hunts with cat.

  • Yes, it’s true.

  • I liked the answer, if possible, complement in which cases should be used table, since according to the W3C table still exists... Exemplify cases where table should be used :)

  • I put a very simple example, but passes the idea of where to use.

  • @guiandmag passed yes...in Ports, datagrids, thank you!

3

It’s not wrong but it’s outside HTML5 standards. Ideally, you should use Divs and style them using CSS. There are frameworks that facilitate the work of creating layout structuring as the Grid960. This framework provides ready-made classes for HTML structuring through Divs, making the work much easier

  • I didn’t know this Amanda, thank you.

  • @Rafaelacioly is one of the most "famous" css grids that exists, one of the pioneers to tell the truth... :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.