2013-07-16 196 views
0

我目前正在一個網站的部分有一個網格的圖像。我試圖設置它,所以當你將鼠標放在圖像上時,另一個div會出現一些不透明的背景和文本。問題是我不能得到鼠標懸停div來匹配父母的相同尺寸。到目前爲止,它在兩個方向上都是粘性的。有什麼建議麼?繼承人一些代碼鼠標移動Div尺寸問題

<div class = 'picture-container'> 
      <div class = 'picture-wrapper' id = 'top-left'> 
       <div class = 'onhover'>hello!</div> 
       <img src = 'ds-map.png' height = '100%' width = '100%'> 
      </div> 
      <div class = 'picture-wrapper' id = 'top-right'> 
       <div class = 'onhover'>hello!</div> 
       <img src = 'ds-map.png' height = '100%' width = '100%'> 
      </div> 
      <div class = 'picture-wrapper' id = 'top-center'> 
       <div class = 'onhover'>hello!</div> 
       <img src = 'ds-map.png' height = '100%' width = '100%'> 
      </div> 
     </div> 

.onhover{ 
    position:absolute; 
    display:none; 
    width:30%; 
    height:100%; 
    background-color:#F5D892; 
    opacity:.4; 
} 


.picture-wrapper{ 
    width:30%; 
    height:100%; 
} 

.picture-wrapper:hover .onhover{ 
    display:block; 
} 

回答

0

這裏是一個jsFiddle

<div class='picture-container'> 
    <div class='picture-wrapper' id='top-left'> 
     <div class='onhover'>hello!</div> 
     <div class="img"> </div> 
    </div> 
    <div class='picture-wrapper' id='top-right'> 
     <div class='onhover'>hello!</div> 
     <div class="img"> </div> 
    </div> 
    <div class='picture-wrapper' id='top-center'> 
     <div class='onhover'>hello!</div> 
     <div class="img"> </div> 
    </div> 
</div> 

.onhover { 
    position:absolute; 
    display:none; 
    width:100px; 
    height:100px; 
    line-height:100px; 
    text-align:center; 
    background-color:#F5D892; 
    opacity:.4; 
} 
.picture-wrapper { 
    width:100%; 
    height:100%; 
} 
.picture-wrapper:hover .onhover { 
    display:block; 
} 
.img 
{ 
    height:100px; 
    width:100px; 
    background:blue; 
} 

看看你的想法

+0

太棒了!非常感謝你的幫助 – nictory