[英]Hovering on element and making another element appear at the same time
我已經嘗試解決了很長時間,但似乎無法理解。 我有以下HTML:
<div class="b">
<button>Show when I hover</button>
</div>
<div class="A">When I hover over this the background should change</div>
與相應的CSS:
.b {
float: right;
display: none;
}
.A {
float: left;
display: inline;
width: 1000px;
}
.A:hover {
background: gray;
}
.A:hover + .b {
display: block;
}
我想做的是每當我將鼠標懸停在A
, b
div和相應的按鈕應該顯示。 另外,我希望它使鼠標在按鈕上時, A
的背景仍然是灰色的,就像我將鼠標懸停在它上面一樣。 我似乎無法弄清楚。 有任何想法嗎?
相關的JSFiddle: http : //jsfiddle.net/sn19k1wz/3/
您可以通過更改A
和B
位置來做到這一點
<div class="A">When I hover over this the background should change</div>
<div class="b">
<button>Show when I hover</button>
</div>
更改div的位置,將div標記懸停在第一個
像這樣 :
<div class="A">When I hover over this the background should change</div>
<div class="b">
<button>Show when I hover</button>
</div>
嘗試這樣: 演示
.A {
display: inline-block;
width: 1000px;
position: relative;
}
.b {
display: none;
position: absolute;
z-index: 999;
right: 0;
top:6px;
}
.A:hover {
background: gray;
}
.A:hover + .b {
display: block;
background: red;
cursor:pointer;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.