簡體   English   中英

如何在沒有JavaScript的情況下更改表標題中的背景顏色並修復HTML中的標題?

[英]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.

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