Astunda Astunda - 1 month ago 9
CSS Question

td adding extra margin or padding to right of element

On an assignment for my teacher, we are making a table in which I want each td element to be 200px wide for a total of 5 cells which equal to 1000px (wrapper). When I do this however, the last td in each tr jumps down to the next line when they should all line up properly with no issues.

EDIT: Solved! (Read comments)

Here is my code for the table:



<table id="assignment-table">
<tr>
<th>Assignment</th>
<th>Fall 2013</th>
<th>Responsive?</th>
<th>Winter 2014</th>
<th>Responsive?</th>
</tr>

<tr>
<td>A1</td>
<td>Code Provided Site</td>
<td>No</td>
<td>Designasaurus</td>
<td>Yes</td>
</tr>

<tr>
<td>A2a</td>
<td>Restaurant Mock-up</td>
<td>N/a</td>
<td>TBA</td>
<td>-</td>
</tr>

<tr>
<td>A2b</td>
<td>Restaurant Static</td>
<td>No</td>
<td>TBA</td>
<td>-</td>
</tr>

<tr>
<td>A3a</td>
<td>Adaptive Excercise</td>
<td>No</td>
<td>TBA</td>
<td>-</td>
</tr>

<tr>
<td>A3b</td>
<td>Responsive Excercise</td>
<td>Yes</td>
<td>TBA</td>
<td>-</td>
</tr>

<tr>
<td>A4</td>
<td>Restaurant Final</td>
<td>Yes</td>
<td>TBA</td>
<td>-</td>
</tr>

<tr>
<td>A5a</td>
<td>Final Mock-up</td>
<td>N/a</td>
<td>TBA</td>
<td>-</td>
</tr>

<tr>
<td>A5b</td>
<td>Final Site</td>
<td>Yes</td>
<td>TBA</td>
<td>-</td>
</tr>

<tr>
<td class="lastrow">NSCC GRAPHIC DESIGN | 2012-14</td>
</tr>
</table>

</div>


And then the CSS:

#content {
width: 100%;
color: white;
}

#assignment-table {
font-size: 16px;
border-spacing: 0!important;
border-collapse: collapse;
}

#assignment-table th {
display: inline-block;
padding: 25px 0;
width: 200px;
text-align: center;
}

#assignment-table tr {
display: block;
border-bottom: 1px solid #ffffff;
}

#assignment-table tr:last-child {
width: 1000px;
border-bottom: none!important;
}

#assignment-table td {
display: inline-block;
padding: 25px 0;
width: 200px;
text-align: center;
}

.lastrow {
width: 1000px!important;
}

th:nth-child(3) {
background-color: rgba(255,255,255,0.05);
}

td:nth-child(3) {
background-color: rgba(255,255,255,0.05);
font-family: 'source_sans_proitalic';
}

th:nth-child(5) {
background-color: rgba(255,255,255,0.05);
}

td:nth-child(5) {
background-color: rgba(255,255,255,0.05);
font-family: 'source_sans_proitalic';
}


It should look like this:


Answer

It looks like you have display: inline-block; on your table cells. inline-block will automatically insert a space between elements. It's this space that is adding up and wrapping your last element. I would remove the display: inline-block; from your css entries, since this is a table it doesn't need it anyway.

CSS:

#assignment-table th {
  //display: inline-block;   <- remove this
  padding: 25px 0;
  width: 200px;
  text-align: center;
}  

#assignment-table td {
  //display: inline-block;  <- remove this
  padding: 25px 0;
  width: 200px;
  text-align: center;
}

EXAMPLE FIDDLE

Comments