Can the background color on a table's caption be changed with CSS?
The captions on my tables are currently using the background behind them and I would like to make the caption's background a different color. If so what is the CSS property ?
Here is my current CSS
.Table {
margin:0px;padding:0px;
width:100%;
border:1px solid #4c4040;
-moz-border-radius-bottomleft:8px;
-webkit-border-bottom-left-radius:8px;
border-bottom-left-radius:8px;
-moz-border-radius-bottomright:8px;
-webkit-border-bottom-right-radius:8px;
border-bottom-right-radius:8px;
-moz-border-radius-topright:8px;
-webkit-border-top-right-radius:8px;
border-top-right-radius:8px;
-moz-border-radius-topleft:8px;
-webkit-border-top-left-radius:8px;
border-top-left-radius:8px;
}
.Table table{
border-collapse: collapse;
border-spacing: 0;
width:100%;
height:100%;
margin:0px;padding:0px;
}
And my HTML
<div class="Table" >
<table align='center' summary='blank Sum'>
<caption><br>
Please enter the Emails of the people you want to invite.
<br> <br>
</caption>
<tr>
<td>Party ID</td><td>Party Name</td><td>Date</td><td>Sales</td>
<td>blah</td> <td>blah</td> <td>blah</td><td>blah</td>
</tr>
</table>
</div>
Quick answer
CSS
table caption { background: #F00; }
Slower Answer
The .Table
div
seems superfluous. I would have something like this:
HTML
<table summary='blank Sum'>
<caption>
Please enter the Emails of the people you want to invite.
</caption>
<thead>
<tr>
<th>Party ID</th>
<th>Party Name</th>
<th>Date</th>
<th>Sales</th>
</tr>
</thead>
<tbody>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
</tbody>
</table>
CSS
table {
width: 500px; /* whatever width */
margin: 0 auto; /*center table*/
}
table caption {
padding: 10px;
background: #F00;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.