2013-07-16 197 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