html - 使用 CSS 悬停偶数元素的子元素

标签 html css css-selectors hover

我需要设置悬停在作为“tr”子元素的“a”元素上,该元素由第 nth-child(even) 选择器选取。

基本上我有一个包含多行的普通表格,在每个表格单元格内都有一个“a”链接,我想在鼠标悬停时突出显示该链接,但在偶数行中。

我的 CSS 代码:

.table-striped tr:nth-child(even) td a:hover {
    color: #3c3c3c;
}

而且它不起作用。

我该如何解决这个问题?

.table-striped tr:nth-child(even) td a:hover {
  color: Red;
}
<table class="table-striped">
  <tr>
    <td>Some text here</td>
    <td><a href="#">Click here</a>
    </td>
  </tr>
  <tr>
    <td>Some text here</td>
    <td><a href="#">Click here</a>
    </td>
  </tr>
  <tr>
    <td>Some text here</td>
    <td><a href="#">Click here</a>
    </td>
  </tr>
  <tr>
    <td>Some text here</td>
    <td><a href="#">Click here</a>
    </td>
  </tr>
  <tr>
    <td>Some text here</td>
    <td><a href="#">Click here</a>
    </td>
  </tr>
  <tr>
    <td>Some text here</td>
    <td><a href="#">Click here</a>
    </td>
  </tr>
</table>

最佳答案

您使用的 css 运行良好:

.table-striped tr:nth-child(even) td a:hover {
    color: #3c3c3c;
    color:red;/*for dislay i have use this red color;*/
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<table class="table table-striped">
    <tr>
        <td><a href="#">link 1</a></td>
        <td><a href="#">link 2</a></td>
        <td><a href="#">link 3</a></td>
    </tr>
    <tr>
        <td><a href="#">link 1</a></td>
        <td><a href="#">link 2</a></td>
        <td><a href="#">link 3</a></td>
    </tr>
    <tr>
        <td><a href="#">link 1</a></td>
        <td><a href="#">link 2</a></td>
        <td><a href="#">link 3</a></td>
    </tr>
    <tr>
        <td><a href="#">link 1</a></td>
        <td><a href="#">link 2</a></td>
        <td><a href="#">link 3</a></td>
    </tr>
    <tr>
        <td><a href="#">link 1</a></td>
        <td><a href="#">link 2</a></td>
        <td><a href="#">link 3</a></td>
    </tr>
</table>  

关于html - 使用 CSS 悬停偶数元素的子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31874705/

相关文章:

javascript - Bootstrap 3 - 将鼠标悬停在另一个表中的特定行上时突出显示表行

html - CSS 选框兼容性

javascript - 使用正则表达式通过属性名称和值查找 DOM 元素

javascript - 如果 td 值超过 10,000,则更改 td 颜色

html - 如果表的第二列太长,则使第一列跨度

javascript - 使用 innerHtml 创建包含许多元素的 div 时出错

javascript - 从 iframe 获取 json——而不是 jsonp

css - JQGrid 表头高度

css - 我应该在我的 CSS 定义中为每个元素/类写下完整的层次结构路径吗?

python - 问题: Getting to the element by using CSS selectors attribute 'style' with selenium