将绝对 div 定位在相对容器内
我有一个图像,想要在该图像悬停时显示翻转弹出 div。下面是我的代码;
<div class="wrapper">
<ul class="popup">
<li><a href="#"Link 1</a></li>
<li><a href="#"Link 2</a></li>
<li><a href="#"Link 3</a></li>
<li><a href="#"Link 4</a></li>
</ul>
<img src="iOpenPopupOnHover.gif" /
</div>
<div class="wrapper">
<ul class="popup">
<li><a href="#"Link 1</a></li>
<li><a href="#"Link 2</a></li>
<li><a href="#"Link 3</a></li>
<li><a href="#"Link 4</a></li>
</ul>
<img src="iOpenPopupOnHover.gif" /
</div>
...
现在我使用position:relative作为包装器,使用position:absolute作为弹出窗口。这是因为我想将弹出窗口定位在每个图像的顶部/中心。
现在的问题是,虽然绝对位置似乎是相对于图像计算的,但弹出窗口完全包含在包装器 div 中,并且一些弹出链接的农作物种类。我希望显示完整的弹出窗口...我该如何解决这个问题?
下面是CSS
.wrapper {
float: left;
position: relative;
}
.popup {
display: none;
width: 80px;
background-color: red;
position: absolute;
bottom: 105px;
left: 10px;
}
I have an image and want to show a rollover popup div on hover of that image. Below is my code;
<div class="wrapper">
<ul class="popup">
<li><a href="#"Link 1</a></li>
<li><a href="#"Link 2</a></li>
<li><a href="#"Link 3</a></li>
<li><a href="#"Link 4</a></li>
</ul>
<img src="iOpenPopupOnHover.gif" /
</div>
<div class="wrapper">
<ul class="popup">
<li><a href="#"Link 1</a></li>
<li><a href="#"Link 2</a></li>
<li><a href="#"Link 3</a></li>
<li><a href="#"Link 4</a></li>
</ul>
<img src="iOpenPopupOnHover.gif" /
</div>
...
Now I use position:relative for the wrapper and position: absolute for the popup. This is bcoz I want to position the popup at the top/center with respect to each image..
Now the issue is while the absolute position seems to be getting calculated with respect to the image, the popup is completely contained within the wrapper div and kind of crops some of the popup links. I want the complete popup to get displayed...How do I fix this?
Below is the CSS
.wrapper {
float: left;
position: relative;
}
.popup {
display: none;
width: 80px;
background-color: red;
position: absolute;
bottom: 105px;
left: 10px;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西吗?
Something like this?