簡體   English   中英

使用CSS更改HTML表格標題BG顏色

[英]Change HTML Table Caption BG Color With CSS

可以使用CSS更改表格標題上的背景顏色嗎?

我桌子上的標題當前正在使用它們后面的背景,我想使標題的背景具有不同的顏色。 如果是這樣,CSS屬性是什么?

這是我目前的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;
}

還有我的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>

快速回答

小提琴!

CSS

table caption { background: #F00; }

較慢的答案

.Table div似乎是多余的。 我會有這樣的事情:

小提琴!

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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM