【发布时间】:2021-12-04 00:16:23
【问题描述】:
我想更改容器的背景图像,以便当我将鼠标悬停在 div 中的链接上时,背景图像会发生变化。
阅读stackoverflow 和其他sources,这应该可以,但我已经在 Chrome 和 Edge 中进行了测试。目前两者都没有工作。
#container {
width: 50%;
height: 300px;
position: relative;
}
#text {
position: absolute;
font-size: 3em;
z-index: 5;
}
#text:hover~#background {
background-image: url("http://lorempixel.com/400/200/food/");
}
#background {
width: 100%;
background-image: url("http://lorempixel.com/400/200/animal/");
background-position: center;
background-size: cover;
height: 100%;
opacity: 0.5;
position: absolute;
}
<div id="container">
<div id="background"></div>
<div id="text"><a href="http://www.google.ca">Google</a></div>
</div>
【问题讨论】:
-
Css 不能让你以你想要的方式“备份” - 你能改变你的 HTML 吗?
标签: html css hover containers background-image