Reputation: 1582
I wish to achieve a table border like this (notice the thick border under the 3rd row):
So, I coded as the one given below,
body {
font-family: Roboto Condensed;
background-color: hsl(0, 0%, 25%);
color: white;
padding: 2px 5px 2px 5px;
}
table {
border: 2px solid;
border-collapse: collapse;
width: 100%;
}
caption {
font-weight: bold;
border: 2px solid;
border-collapse: collapse;
padding: 8px;
padding-top: 12px;
padding-bottom: 12px;
}
th {
border: 2px solid;
padding: 8px;
padding-top: 12px;
padding-bottom: 12px;
background-color: hsla(0, 0%, 50%, .5);
width: 10%;
}
td {
border: 1px solid #ccc;
padding: 8px;
width: 15%;
}
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet" type="text/css">
<table>
<caption>TableCaption</caption>
<tr>
<th>TableHeader</th>
<th>TableHeader</th>
<th>TableHeader</th>
<th>TableHeader</th>
<th>TableHeader</th>
</tr>
<tr>
<th rowspan="2">SpannedRow1</th>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
<tr>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
<tr>
<th rowspan="2">SpannedRow1</th>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
<tr>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
</table>
And it ends up like this (notice that the border under third row isn't thick):
Now I would like to know in which way if handle the table border so that I can have the expected result.
Upvotes: 0
Views: 90
Reputation: 244
Hoping can help you
tbody tr:nth-child(2n) {
border-bottom: 2px solid red;
}
Upvotes: 1
Reputation: 199
You can try using nth child for the table row as below:
tr:nth-child(3) {
border-bottom: 2px solid white;
}
Here I have updated your code snippet:
body {
font-family: Roboto Condensed;
background-color: hsl(0, 0%, 25%);
color: white;
padding: 2px 5px 2px 5px;
}
table {
border: 2px solid;
border-collapse: collapse;
width: 100%;
}
caption {
font-weight: bold;
border: 2px solid;
border-collapse: collapse;
padding: 8px;
padding-top: 12px;
padding-bottom: 12px;
}
th {
border: 2px solid;
padding: 8px;
padding-top: 12px;
padding-bottom: 12px;
background-color: hsla(0, 0%, 50%, .5);
width: 10%;
}
td {
border: 1px solid #ccc;
padding: 8px;
width: 15%;
}
tr:nth-child(3) {
border-bottom: 2px solid white;
}
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet" type="text/css">
<table>
<caption>TableCaption</caption>
<tr>
<th>TableHeader</th>
<th>TableHeader</th>
<th>TableHeader</th>
<th>TableHeader</th>
<th>TableHeader</th>
</tr>
<tr>
<th rowspan="2">SpannedRow1</th>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
<tr>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
<tr>
<th rowspan="2">SpannedRow1</th>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
<tr>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
</table>
Upvotes: 2