CSS - 第一个孩子选择器比类选择器更强
问题描述:
我想通过将类添加到由第一个孩子选择器样式化的列表元素来触发CSS动画。但是不知何故,当前的风格不会被增加的类所覆盖。CSS - 第一个孩子选择器比类选择器更强
HTML
<ul class="start">
<li id="box" >move up onHover</li>
</ul>
<div id="button">hover</div>
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
$('#button').hover(function() {
$('#box').addClass('change');
})
谢谢你,但是这也是不好用“li.class”我读了计算器 – user2520410
它不坏,如果你要覆盖更具体的风格,这是不是真的坏CSS,但在jQuery选择器可能会导致一些额外的工作,但它也不是很糟糕。 – adeneo