Width of a <td> is not of last size

Asked

Viewed 433 times

0

Good afternoon, I’m having a question here in the form mounting using and varied.

i have the following table:

<table>
<tr>
  <td>Nome:</td>
  <td>Senha:</td>
</tr>
<tr>
  <td>Código</td>
  <td>E-mail</td>
</tr>
<tr>
  <td class="campo-grande">Número de RAPSI:</td>
</tr>

and the CSS:

table{
 margin:0;
padding:0;
}
tr{
 display:block;
 border:1px solid black;
 margin-top:5px;
 }
td{
 display:inline-block;
border:1px solid black;
 width:200px;
}  
.campo-grande{
 width:400px;
}

What happens is that the field "RAPSI number" does not get 400px width, anyone knows what it is? I do not have much experience with tables, if help follows the codepen

http://codepen.io/haykou/pen/GtcxL

1 answer

7


I don’t understand why using a table, apart from table patterns via CSS... If you really want to use table (if it’s to show tabular data, ok, otherwise do not recommend), use colspan="2" in the last cell, and remove the display for tr and td:

*{
  border-box:box-sizing;
}
table{
  margin:0;
  padding:0;
}
tr{
  border:1px solid black;
  margin-top:5px;
}
td{
  border:1px solid black;
  width:200px;
  padding:0;
}
.campo-grande{
  width:400px;
}
 <table>
    <tr>
      <td>Nome:</td>
      <td>Senha:</td>
    </tr>
    <tr>
      <td>Código</td>
      <td>E-mail</td>
    </tr>
    <tr>
      <td colspan="2" class="campo-grande">Número de RAPSI:</td>
    </tr>
  </table>

  • @bfavaretto, without wanting to deviate the scope of the question, one could say why it did not work the way that haykou did?

  • Because display: inline-block suffers interference from whitespace, like HTML line breaks and indentation. @Cold

  • Okay, just ask why I’ve been here trying (even without display: inline-block) and I couldn’t. I must have missed something... Thanks @bfavaretto

  • @Cold Look how it looks without the blanks: http://codepen.io/anon/pen/LiGwJ The difference in the size of the last line is due to the 2px extra edge on the top lines (because they have 2 cells each).

  • Very enlightened... vlw

Browser other questions tagged

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