2015-12-20 19 views
0

首先對不起的鏈接,我的英語我會嘗試儘可能準確,這裏是我的問題:如何防止一個div不會消失,當你徘徊在純CSS

在我的CSS我創建了一個沒有顯示的div,當我將鼠標懸停在導航欄中的鏈接上時,我使用顯示塊更改了顯示,它是一個簡單的子導航模式。但是,這是我的問題,一旦我離開時我的鏈接懸停,我的子菜單自動消失,所以我如何保持我的子菜單顯示塊,即使我沒有徘徊扳機了,所有的純粹CSS(它是一個exercice對我來說):

這是我在github回購:https://github.com/MehdiAlouafi/Int-gration-Briefing-2

+0

你能把它會更容易小提琴,以幫助 – KoKo

+0

這裏是:) HTTPS ://jsfiddle.net/hv2a18y7/ – MaieonBrix

回答

0

我認爲你做了幾個錯誤。

/* First of all it's better to have your list-item relative. */ 
nav ul > li { 
    position:relative; 
} 

/* Then your .on-hover can have simpler top and left coordinates. */ 
.on-hover { 
    height: 150px; 
    background-color: rgb(243,243,241); 
    width: 165px; 
    position: absolute; 
    left: 0; 
    top: 0; 
    display: none; 
    border-bottom: 1px solid rgba(96, 96, 96, 0.2); 
    z-index: -1; 
} 

/* You want the hovering to be over the entire li.*/ 
nav ul > li:hover .on-hover { 
    display: block; 
} 

你有這樣的懸停工作。這意味着它停止,當你離開#TEST是錨徘徊(<a>)元素

#test:hover + .on-hover { 

工作的jsfiddle:https://jsfiddle.net/3su9jppc/1/

+0

男人...非常感謝...我愛你! 我剛剛開始編碼,就像2個月前一樣,所以這對我來說是新的,但感謝你我今天學習了一些東西! 非常感謝你Yeouu! :) – MaieonBrix