我有3个div.其中2个在聚焦时会改变颜色.当其中两个div聚焦时,还可以对另一个div执行操作吗?
div {
border: 1px solid;
margin: 5px;
width: 300px;
height: 50px;
padding: 2px;
}
.myClass:focus {
background-color: yellow;
outline: none;
}
Focus me!
You can focus me too!
I cannot be focused, but want to change my color, when one of the other divs above me get focused.
因此,当2个上部div中的1个聚焦时,我希望底部的第3个div改变其颜色.
在这里你可以看看:https://jsfiddle.net/ogpvvwtg/
当然,您可以使用通用兄弟选择器~
.myClass:focus ~ .anotherClass { background-color: red; outline: none; }
div {
border: 1px solid;
margin: 5px;
width: 300px;
height: 50px;
padding: 2px;
}
.myClass:focus {
background-color: yellow;
outline: none;
}
.myClass:focus ~ .anotherClass {
background-color: red;
outline: none;
}
Focus me!
You can focus me too!
I cannot be focused, but want to change my color, when one of the other divs above me get focused.