CSS - 悬停时,突出显示元素(以及内部元素)

标签 css

我正在使用字体图标,我正在尝试获取图标以及 <a>当鼠标悬停在它周围时,标签会改变颜色。

<div class="container">
    <ul>
        <li>
            <a href="#">
                <i class="fa fa-user-circle fa-lg"></i>
            </a>
        </li>
    </ul> 
</div>

还有 CSS:

.container {
    background-color: blue;
    width: 100%;
    position: fixed;
    top: 0;
}

.container a {
    padding: 20px;
    text-decoration: none;
    cursor: pointer;
    transition: background-color cubic-bezier(.170, .70, .49, 1) .5s,
    color cubic-bezier(.170, .70, .49, 1) .3s;
}

所以当<a>标签悬停,我想要 <a>标签以及内部 <i>使用 <a> 改变颜色的标签得到它的 background-color改变了,并且<i>有它的color变了。我尝试了以下方法:

.container a:hover {
    background-color: purple;
    color: red;
}

这将得到 background-color在悬停时变为紫色,但是 <i> <a> 内的标签标签不会变成红色。

最佳答案

那是因为您没有选择 <i> .

.container a:hover {
    background-color: purple;
    color: red;
}

.container a:hover > i {
    color: red;
}

您必须选择 <i><a>里面

关于CSS - 悬停时,突出显示元素(以及内部元素),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46706233/

相关文章:

html - 如何水平使用带有 3 个 div 标签的内联 block

html - 如何摆脱子菜单下划线

html - 使用 twitter-bootstrap 可调整大小的图像

html - DIV溢出问题

html - CSS 的粘性页脚错误

jquery - 如何使用 jquery 将图像标题渲染为灯箱标题?

html - 在纯 css 中创建右侧带有小文本标签的图像

javascript - 如何使用 knockout 同时应用过滤和分页?

javascript - 找到最远的 DIV 的最便宜的方法?

html - 使用 css 将网页内容居中的最佳方法是什么?