簡體   English   中英

將鼠標懸停在元素上並同時顯示另一個元素

[英]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;
}

我想做的是每當我將鼠標懸停在Ab div和相應的按鈕應該顯示。 另外,我希望它使鼠標在按鈕上時, A的背景仍然是灰色的,就像我將鼠標懸停在它上面一樣。 我似乎無法弄清楚。 有任何想法嗎?

相關的JSFiddle: http : //jsfiddle.net/sn19k1wz/3/

您可以通過更改AB位置來做到這一點

<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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM