[英]CSS: Hovering over child of element should affect different element
I want users to be able to hover
over a button
within a different div
, which then changed the background-color
of the div
below.我希望用户能够将
hover
在不同div
的button
,然后更改下面div
的background-color
。
My current code is as followed:我目前的代码如下:
.delSeperator button:hover+.linkField { background-color: rgba(255, 0, 0, 0.2); } .seperator { color: #000000; background-color: #e4e8eb; min-height: 0.5rem; margin: 1rem 0rem 1rem 0rem; }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <div id="delSeperator_0" class="row delSeperator"> <div class="col-xs-10 mb-0"> <div class='seperator vertical-center'></div> </div> <div class="col-xs-1 mb-0"><button type="button" class="btn btn-danger" onclick="delField('linkField', this.closest('.row')); delField('delSeperator', this.closest('.row'));"><i class="fa fa-minus" aria-hidden="true"></i></button></div> </div> <div class="row linkField" id="linkField_0"> <div class="col-xs-6 mb-0"> <div class="form-group"><label for="txt_link[0]["bezeichnung"]" class="">Bezeichnung</label><input id="txt_link[0]["bezeichnung"]" type="text" maxlength="200" name="link[0]["bezeichnung"]" class="form-control"></div> </div> <div class="col-xs-6 mb-0"> <div class="form-group"><label for="txt_link[0]["url"]" class="">URL</label><input id="txt_link[0]["url"]" type="url" maxlength="500" name="link[0]["url"]" class="form-control"></div> </div> </div>
Changing the Hover-CSS to将 Hover-CSS 更改为
.delSeperator:hover + .linkField {
background-color: rgba(255,0,0,0.2);
}
works so that when you hover over the whole .delSeperator
, the .linkField
gets the background property.工作,以便当您将鼠标悬停在整个
.delSeperator
, .linkField
获得背景属性。
When I change the code to当我将代码更改为
.delSeperator button:hover {
background-color: rgba(255,0,0,0.2);
}
it works so that when you hover
over the button
, the button
gets the background
property.它的工作原理是,当您将
hover
在button
, button
会获得background
属性。
But I can't seem to combine these two.但我似乎无法将这两者结合起来。 Is there any way to achieve what I need?
有什么方法可以实现我所需要的吗?
You can workaround this issue by playing with the pointer-events
property您可以通过使用
pointer-events
属性来解决此问题
i got this to work with the following CSS:我让它与以下 CSS 一起使用:
.delSeperator:hover + .linkField {
background-color: rgba(255,0,0,0.2);
}
.delSeperator {
pointer-events: none
}
.delSeperator button {
pointer-events: initial
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.