[英]With CSS, can I change the property of a child element when I hover on a parent element?
I have a div and a span inside of it (with some text and a border). 我里面有一个div和一个span(带有一些文本和边框)。
<div id='div1'>
<span id='span1' style='border-right: 1px black solid'>Some text</span>
</div>
What I want to do is: when I hover my mouse over that div, I would like to remove the border from the span. 我想做的是:当我将鼠标悬停在那个div上时,我想从范围中删除边框。 And when I move out of the div, I want the border to come back as it was. 当我离开div时,我希望边界恢复原状。
Can I do this with CSS or should I resort to JS/jQuery? 我可以使用CSS还是使用JS / jQuery?
Thanks a lot in advance. 非常感谢提前。
You don't need JavaScript, you can use css: 您不需要JavaScript,可以使用CSS:
#div1:hover #span1 {
border-width: 0;
}
Quite simply :-) 很简单:-)
You can't use :hover for inline styles, so you'll have to move them to style tags or style sheets. 不能将:hover用于内联样式,因此必须将它们移至样式标签或样式表。
#div1:hover span{
border:0;
}
#div1 span{
border-right: 1px black solid;
}
Yes it's rather easy to target the selector after a :hover state selector. 是的,在:hover状态选择器之后将选择器作为目标很容易。 jsfiddle created here: http://jsfiddle.net/wigster/a4V8Q/ jsfiddle在这里创建: http : //jsfiddle.net/wigster/a4V8Q/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.