I want to have a simple table consisting of 7 columns and x rows (Monday,….,Sunday) & 1 – 365
i want the background-color of col-saturday and col-sunday to be red
this is how my CSS (external, in the same folder) looks:
*{
background-color:black;
color:white;
}
table{
width:100%;
}
th,td{
border:2px solid white;
border-collapse:collapse;
background-color:black;
}
tr:hover td{
background-color:green;
}
this is how my code looks like for the table:
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Homepage</title>
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="styless.css">
</head>
<body>
<table>
<colgroup>
<col span="5">
<col span="2" **style="background-color:red"**>
</colgroup>
<tr>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
<th>Saturday</th>
<th>Sunday</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
</table>
</body>
</html>
how it looks like; no red background-color
i don’t get why cols sat and sun won’t be red.
i thought inline styles have the highest priority, or am i missing something else?
when i unlink the .css from my code it looks like this:
2
Answers
Since it’s not a MUST in your request, I would do it without
<colgroup>
and implement everything via CSS, so you have more flexibility in my opinion. The key is to select the last 2 child elements. You can achieve this by using the:nth-child(n)
selector like so:nth-child(-n+2)
. Have a look, hope that helps.td are inside colgroups. Therefore every direct styling of td (even in separate sheet) will take precedence over every colgroup styling.
Try something like:
Or try @Dimava suggestion, it will save you colgroups.