[英]CSS - first-child selector stronger than class selector
I want to fire a CSS animation by adding a class to an list element that is styled by a first-child selector. 我想通过将类添加到由第一个子选择器设置样式的列表元素来触发CSS动画。 But somehow the current style is not overwritten by the added class.
但不知何故,当前的风格不会被添加的类覆盖。
HTML HTML
<ul class="start">
<li id="box" >move up onHover</li>
</ul>
<div id="button">hover</div>
CSS CSS
.start li:first-child{
height:100px;
width:100px;
background: red;
opacity: 1;
transform: translate(0, 190px);
transition: all 2.0s linear;
}
.change{
opacity: 1;
transform: translate(0, 0px);
}
#button{
width: 80px;
height: 20px;
padding: 4px;
margin-left: 333px;
border:solid 1px black;
background: grey;
cursor: pointer;
color: white;
}
JS JS
$('#button').hover(function() {
$('#box').addClass('change');
})
.start li:first-child
overrides styling of .change
.start li:first-child
覆盖.change
样式
Change 更改
.change{}
to 至
.start li.change{}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.