在鼠标悬停时更改整个表格

问题描述 投票:0回答:5
html css html-table mouseover
5个回答
2
投票

@Sebastian Heyn 请检查以下代码。我希望你也有同样的期望。

table:hover {
    background-color: #FFEB3B;
    color: red;
}
<table>
<tr>
<th>Header</th>
<th>Header</th>
</tr>
<tr><td>Somecontent</td>
<td>Somecontent</td>
</tr>
</table>


1
投票

为什么要结合使用内联 JS 和 CSS?把这些东西放在你的样式表中......

table:hover {
    background: red; 
}

0
投票

试试我的代码。希望它可以帮助你。

.sample {
border:1px;
}
.sample th{
background-color:red;
}
.sample th:hover{
background-color:blue;
}
<table class="sample" border=1>
<tr><th>Header</th></tr>
<tr><td>Somecontent</td></tr>
</table>


0
投票

我不是专家,但也许你应该制作表 ID 并使用一些 jquery 函数。


0
投票

th:hover,td:hover {
    background-color: #FFEB3B;
    color: red;
}
<table>
<tr>
<th>Header</th>
<th>Header</th>
</tr>
<tr><td>Somecontent</td>
<td>Somecontent</td>
</tr>
</table>

© www.soinside.com 2019 - 2024. All rights reserved.