html - CSS 悬停属性不适用于嵌套 div
问题描述
我一直在做一个网页。我已经拿了一个 div 并且它有一个 h1 标题。我正在尝试提供相同的悬停(之前和之后)效果,但是我编写的代码似乎对我不起作用。请您向我解释一下,为什么它不起作用以及解决方法是什么?
这是HTML:
body,
html {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
background-repeat: space;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
animation: fadeInAnimation ease 2s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
@keyframes fadeInAnimation {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.section-intro {
overflow: hidden;
position: relative;
width: 100%;
height: 100%;
margin-right: auto;
margin-left: auto;
background-repeat: no-repeat;
background-size: cover;
justify-content: center;
justify-items: center;
display: flex;
background-image: url('../images/cc2dea0.jpg');
/**nimation: slide ease 4s infinite;**/
}
.intro-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.intro-content h1:hover::before {
color: palegreen;
}
.intro-content h1:hover::after {
color: palegreen;
}
<div class="section-intro">
<div class="nav-bar">
/**anchor links**/
</div>
<div class="intro-content">
<h1>
h1 Header
</h1>
</div>
</div>
解决方案
我相信您的代码不起作用,因为 ::before 和 ::after 伪元素必须具有“content:;” 在它们上设置的属性(最好是 content:""; "" 为空白)。此外,没有给出给定的高度或宽度,因此元素没有空间来显示您的颜色。最后,我相信您的意思是背景颜色而不是 ::after 和 ::before 的颜色,因为颜色是前文。
推荐阅读
- pandas - Pandas:从不同列中的元素替换部分字符串
- c - C中的计算器-一次计算后if语句不再起作用
- node.js - 如何使强大的不保存到nodejs和express app上的var /文件夹
- java - 我怎样才能让这个乘法方法返回一个没有重复指数的多项式?
- javascript - 将 unit8array 转换为“stream.Readable”或“Buffer”或“string”
- java - 通过 RequestMapping 选择 Controller Bean 实例
- python - 如何在 Python 3.7+ 中一次流式传输对象
- android - 为什么我不能从数组中得到正确的日期?
- android - 使用 getKey() 时显示所有键
- python - 如果其中一列中有字符串,我们如何根据多个条件对数据框进行数字过滤?