【问题标题】:How to popup content in relative to a div如何相对于 div 弹出内容
【发布时间】:2018-08-20 13:48:01
【问题描述】:
我正在尝试制作多个 div 的网格。我想在任何其他 div 中弹出一些内容。但是这个弹出内容应该正好在悬停的 div 上。每个 div 都应该是动态的。
我找到了一个例子here。请帮我实现这样的系统。
【问题讨论】:
标签:
javascript
html
css
wordpress
【解决方案1】:
您可以定位相对和绝对属性以将 div 覆盖在任何特定 div 上。
请注意父 div 应该是相对的,子/覆盖 div 应该是绝对的。
看看下面的例子。
*{box-sizing:border-box;}
.div{
width:300px;
height:500px;
float:left;
margin:10px;
padding:10px;
position:relative;
color:#000;
border:1px solid #ccc;
}
.div h1{
margin:0;
padding:0;
font-size:17px;
}
.overlay-div{
position:absolute;
top:0;
left:0;
padding:10px;
width:100%;
height:100%;
background:rgba(0,0,0,0.8);
color:#fff;
opacity:0;
visibility:hidden;
-webkit-transition:all 0.5s ease;
-ms-transition:all 0.5s ease;
-o-transition:all 0.5s ease;
transition:all 0.5s ease;
}
.div:hover .overlay-div{
opacity:1;
visibility:visible;
}
<html>
<head>
<title>overlay inside div</title>
</head>
<body>
<div class="div">
<h1>div content will be here</h1>
<div class="overlay-div">Overlay Content will be here</div>
</div>
<div class="div">
<h1>div content will be here</h1>
<div class="overlay-div">Overlay Content will be here</div>
</div>
<div class="div">
<h1>div content will be here</h1>
<div class="overlay-div">Overlay Content will be here</div>
</div>
<div class="div">
<h1>div content will be here</h1>
<div class="overlay-div">Overlay Content will be here</div>
</div>
</body>
</html>
【讨论】:
-
您好,非常感谢您的回复。实际上我想要的结构是 [link(gostream.site) 我不想覆盖在图像上。我想弹出另一个可能位于页脚下方的 div。请检查上述网站的来源。