2016-09-18 41 views
0

我有這樣的事情如何取消激活CSS懸停在空區域

enter image description here

我嘗試取消激活的紅色區域懸停,我可以在img位置設置爲絕對的,它發生,但我相信它不是正確的方法。

我提供的完整代碼在這裏https://jsfiddle.net/m6ephL81/1/

<nav id='slideShow_control'> 
       <a href='#'> 
        <figure><img src='img/slide01_thumb.jpg' alt=''><figcaption>توسعه میدان های نفتی توسعه میدان های نفتی</figcaption></figure> 
       </a> 
       <a href='#'> 
        <figure><img src='img/slide02_thumb.jpg' alt=''><figcaption>توسعه میدان های نفتی</figcaption></figure> 
       </a> 
       <a href='#'> 
        <figure><img src='img/slide03_thumb.jpg' alt=''><figcaption>توسعه میدان های نفتی توسعه میدان های نفتی</figcaption></figure> 
       </a> 
       <a href='#'> 
        <figure><img src='img/slide04_thumb.jpg' alt=''><figcaption>توسعه میدان های نفتی</figcaption></figure> 
       </a> 
      </nav> 


#slideShow_control { 
    position: absolute; 
    bottom: 30px; 
    left: 50%; 
    transform: translateX(-50%); 
    z-index: 2; 
} 

#slideShow_control > a { 
    position: relative; 
    display: block; 
    float: left; 
    width: 20px; 
    height: 20px; 
    margin-left: 20px; 
} 

#slideShow_control > a:first-child { 
    margin-left: 0; 
} 

#slideShow_control > a:before { 
    content: ''; 
    display: block; 
    width: 20px; 
    height: 20px; 
    background-color: #09779C; 
} 
#slideShow_control > a:hover:after { 
    content: ''; 
    position: absolute; 
    width: 20px; 
    height: 20px; 
    left:0; 
    top: -20px; 
} 

#slideShow_control > a:hover:before { 
    transition: all 0.2s ease-in-out; 
    background-color: transparent; 
    transform: scale(1.7); 
    box-shadow: 0 0 0 3px #09779C inset; 
} 

#slideShow_control figure { 
    opacity: 0; 
    text-align: center; 
    font-size: 0; 
    position: absolute; 
    bottom: -100%; 
    left: 50%; 
    transform: translateX(-50%) translateY(50%); 
    visibility: hidden; 
    transition: all 0.3s ease-out; 
    z-index: 3; 
    pointer-events: none; 
} 

#slideShow_control figcaption { 
    white-space: nowrap; 
    padding-top: 8px; 
    padding-bottom: 7px; 
    color: #fff; 
    font-size: 0.9rem; 
} 

#slideShow_control img { 
    transition: all 0.3s ease-out; 
} 

#slideShow_control a:hover figure { 
    opacity: 1; 
    visibility: visible; 
    bottom: 30px; 
    transform: translateX(-50%) translateY(0); 
    pointer-events: all; 
} 

我會感謝你的CSS或JS的解決方案。

+1

停用懸停是什麼意思?請詳細說明! –

+0

懸停事件觸發對嵌套元素的空白區域 如果你看到你明白的代碼氨基j –

回答

0

真正長的文字使圖形元素比圖像更寬。看看this fiddle,這樣你就可以看到它。注意第三個數字很大,因爲我在那裏複製並粘貼了更多文本。

#slideShow_control figure { 
    background-color:red; 
    max-width:150px; 
} 

一個快速的解決方案是讓箱子只寬您的圖像,現在你必須弄清楚如何正確設置文本的位置see here

使用這樣的動畫時,在相對父母內使用絕對定位元素是可以的。試圖找出你要設置懸停的人,因爲你實施它的方式很麻煩。

+0

謝謝,它不是我要找的答案,如果你注意到我曾提到我可以通過在img元素上設置絕對位置來解決它,但是我確定有更好的方法 –

+0

好吧,[this]怎麼樣(https://jsfiddle.net/m6ephL81/7/)。只需將'figcaption'設置爲'絕對'並將其與轉換對中。由於'figcaption'現在是絕對的,您還必須增加'#slideShow_control a:hover figure'的'bottom'屬性。我將它設置爲「bottom:60px」,看起來很好。 –

+0

@CameronA另外,我知道你不想使用絕對定位的物品,因爲它通常不被推薦,但是在某些情況下它們非常棒,特別是當你在相對定位的元素中使用它們,以改變位置等。 –