[英]How can I change the background color in table header and fix the header in HTML, without JavaScript?
我試圖使用它,但是沒有用。
.header {
position: fixed;
top: 0;
width: 100%;
}
您可以在CSS中說,第一個<tr>
(通常是<th>
標記)具有特定的背景,應該固定
tr:first-child
{
background-color: yourColor;
position:fixed;
}
這個例子也可以幫助你https://codepen.io/tjvantoll/pen/JEKIu
如果以下是基本表的布局:
<table>
<tr><th>Something Here</th></tr>
<tr><td>Row 1</td></tr>
<tr><td>Row 2</td></tr>
<tr><td>Row 3</td></tr>
</table>
那么您可以執行以下操作:
th{
color: white;
background: black;
}
其中th
是表頭。
這是表格標題上的參考鏈接。 希望對您有所幫助。
這是工作示例:
th { color: white; background: black; }
<table> <tr> <th>Something Here</th> </tr> <tr> <td>Row 1</td> </tr> <tr> <td>Row 2</td> </tr> <tr> <td>Row 3</td> </tr> </table>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.