【发布时间】:2022-01-06 02:37:01
【问题描述】:
我试图让 text-info 元素仅在我只使用 CSS 而没有 JS 将鼠标悬停在容器元素上时才显示,但它不起作用,希望得到一些建议。
我假设它与显示 flex 而不是显示块有关,所以我也尝试过,但没有帮助。
请注意,即使没有悬停,文本也不会显示在页面上,我不知道为什么。
body {
color: #2f80ed;
font-family: Avenir, Helvetica, Arial, sans-serif;
margin: 0;
display: flex;
height: 100vh;
}
p {
margin: 0;
}
.container {
width: 520px;
margin: auto;
}
.container img {
width: 100%;
}
.text {
width: 400px;
margin: 0 auto;
cursor: pointer;
}
.text-code {
text-align: center;
font-size: 120px;
font-weight: 400;
}
.container:hover+.text-info {
display: flex;
}
.text-info {
display: none;
text-align: center;
font-size: 20px;
font-weight: 400;
opacity: 0;
transition: opacity .4s ease-in-out;
}
footer {
width: 100%;
position: absolute;
bottom: 30px;
}
footer p {
margin: auto;
font-size: 16px;
}
footer a {
color: #2f80ed;
}
<div class="container">
<img src="empty-boxes.svg" alt="error" />
<div class="text">
<p class="text-code">404</p>
<p class="text-info">
404 is an error.
</p>
</div>
</div>
<footer>
<p>Go back.</p>
<a href="https://google.com"></a>
</footer>
【问题讨论】: