【发布时间】:2021-07-03 06:00:18
【问题描述】:
我有如下的 css 和 html 代码。
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
ul {
list-style-type: none;
}
.container {
width: 1000px;
margin: 0 auto;
}
.top-content {
width: 100%;
height: 100px;
background-color: gray;
}
nav ul {
display: flex;
justify-content: space-around;
}
nav ul li:hover {
cursor: pointer;
color: red;
}
main {
width: 100%;
height: 500px;
background: green;
}
nav ul li:hover .top-content {
background: red;
}
nav ul li:hover main {
background: red;
}
<div class="container">
<div class="top-content"></div>
<nav>
<ul>
<li>Lorem</li>
<li>Lorem</li>
<li>Lorem</li>
<li>Lorem</li>
<li>Lorem</li>
</ul>
</nav>
<main></main>
</div>
当我将鼠标悬停在 li 元素上时,我想要将 .top-content 类和 main 元素涂成红色。但据我了解,我的选择器有问题。如何仅使用 css 更改这些元素的颜色?
【问题讨论】:
-
你能改变你的html结构吗?如果不是,你不能只在 Css 中做到这一点
-
你能举个例子吗?