简体   繁体   English

为什么我的表tr td:hover只适用于th标题行?,不适用于任何其他行?

[英]Why does my table tr td:hover only work for the th header row?, not for any other rows?

I have this code in jsfiddle and I would like the rows to highlight when I hover over them. 在jsfiddle中这个代码,当我将鼠标悬停在它们上面时,我希望这些行能够突出显示。 I have tried the usual technique that works for me, but on this one, it only highlights the th header row, and not the table rows. 我已经尝试了平时的技术,为我的作品,但就这一个,这既突出了th标题行,而不是table行。

View the code in JSFiddle. 在JSFiddle中查看代码。

Basically, I've tried the usual: 基本上,我试过平常:

table tr:hover{background-color: yellow;}

But this only highlights the table tr th Row only, and not the rows of the table, I have no idea why it's doing this. 但是这只突出了tr th行的表,而不是表的行,我不知道它为什么这样做。

Check out the code in JSFiddle. 查看JSFiddle中的代码。

I'm not sure either why it doesn't work as it is, but removing td in #main_content table tr td seems to do the job. 我不知道为什么要么它不工作,因为它是,但除去td#main_content table tr td似乎做的工作。 So change 所以改变

#main_content table tr td
{
    color: #666;
    border-right: 1px solid #eee;
    background-color: #fafafa;
}

to

#main_content table tr
{
    color: #666;
    border-right: 1px solid #eee;
    background-color: #fafafa;
}

You need to modify the CSS code, as so: 您需要修改CSS代码,如下所示:

#main_content table tr:hover td
{

        color: #666;
        border-right: 1px solid #eee;
        background-color: #ffcc11;
}

the :hover is the main thing. :hover是主要的事情。

Hope this helps 希望这可以帮助

That's because your td 's background color is overriding the tr's background color. 那是因为你的td的背景颜色覆盖了tr的背景颜色。 So, you need to change the following 因此,您需要更改以下内容

#main_content table tr td     
{
    color: #666;
    border-right: 1px solid #eee;
    background-color: #fafafa;
}

to 

#main_content table tr td
{
    color: #666;
    border-right: 1px solid #eee;
}

#main_content table tr           // apply the color to the tr instead of the td this way it can get overridden
{
    background-color: #fafafa;
}

In CSS, change 在CSS中,改变

#main_content table tr td
{
        color: #666;
        border-right: 1px solid #eee;
        background-color: #fafafa;
}

to

#main_content table tr
{
        color: #666;
        border-right: 1px solid #eee;
        background-color: #fafafa;
}

as seen in http://jsfiddle.net/jhuntdog/NPrSU/12/embedded/result/ http://jsfiddle.net/jhuntdog/NPrSU/12/embedded/result/所示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的TR中没有装满TD或TH标签,为什么我的文本在表格内? - Why is it that my text is inside my table when my TR is not filled with any TD or TH tags? 为什么冻结行标题时td不填充父tr? - Why td not filling parent tr when freezing row header? 将表,tr,td标记附加到innerHTML不会创建表行 - Appending table, tr, td tags to innerHTML does not create table rows 仅从td表中搜索而不从标题中搜索(th) - Searching Only From td table not from Header (th) 如何解析包含两者的行的 HTML 表<th>和<td>标签下的<tr>标签? - How to parse HTML table with rows contaning both <th> and <td> tags under the <tr> tag? CSS不用于表TR中的TH悬停 - CSS use not for TH hover in table TR 为什么边距填充在表 td 和 tr 中不起作用? - why the margin padding doesn't work in table td and tr? 使用tr:hover css选择器将样式应用于表行在IE 8中不起作用(如果* tr&gt; td&gt; div&gt;输入文本*鼠标悬停操作) - Applying style to Table row with tr:hover css selector is not working in IE 8 (in case of *tr>td>div>input text* mouse hover action) 为什么CSS行悬停在具有交替行的表中(在IE中)? - Why does CSS row hover remain in table with alternating rows (in IE)? CSS-表-TH悬停设置TD可见性 - CSS - Table - TH hover set TD visibility
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM