要实现“标题后面没有出现背景悬停”的效果,可以使用CSS来添加样式。以下是一个包含代码示例的解决方法:
HTML代码:
Title
Content
CSS代码:
.container {
position: relative;
}
.container::after {
content: "";
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 0;
background-color: transparent;
transition: background-color 0.3s ease;
z-index: -1;
}
.container:hover::after {
height: 100%;
background-color: rgba(0, 0, 0, 0.2);
}
解释:
position: relative;
将容器设为相对定位,以便后续设置绝对定位的伪元素的位置。::after
伪元素来创建一个与容器同宽、高度为0的元素,并将其设为绝对定位。top
属性设为100%,使其从容器底部开始。background-color
设为透明,使其初始状态下不可见。transition
属性来实现伪元素背景色的渐变过渡效果。z-index: -1;
将伪元素放置在容器的下方,以确保它不会覆盖容器中的内容。:hover
选择器来在鼠标悬停时改变伪元素的尺寸和背景色。这样,当鼠标悬停在容器上方时,伪元素的尺寸会从0增加到与容器等高,并显示背景色,从而实现了“标题后面没有出现背景悬停”的效果。
上一篇:标题后面的背景悬浮
下一篇:标题后商店页面的简短描述