我有一个 ID,它在我的网站顶部显示图像
<div id="Introduction">
当我点击<div>
时它切换类 active
这有效。
但是背景图像似乎没有改变 - 谁能告诉我为什么?
我知道正在添加该类,因为我可以通过检查元素来查看。
#Introduction
{
width: 95%;
height: 280px;
padding-top: 85px;
padding-left: 5%;
background-image: url('background1.jpg');
background-size: cover;
background-position: center center;
transition: all 1s ease-in-out;
}
#Introduction .active
{
background-image: url('background2.jpg');
}
最佳答案
您的选择器中存在错误,您正在检查 .active
是否是 #Introduction
的后代。它应该是#Introduction.active
,没有空格。
关于html - 为什么类不更新ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26566421/