【发布时间】:2014-06-15 22:42:17
【问题描述】:
我正在为我的网站制作一个自定义图库,并且我已经将概述部分与所有缩略图一起使用。单击缩略图时,屏幕上会显示完整图片,但我无法将其与屏幕中心对齐。
请注意,每张图片都有不同的尺寸。
这是我到目前为止所做的:
.overlay{
cursor: pointer;
display: none;
position: fixed;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: black;
z-index:1001;
-moz-opacity: 0.8;
opacity:.80;
filter: alpha(opacity=80);
}
.popup {
display: none;
position: absolute;
margin: 0 auto;
border: 8px solid orange;
background-color: #eee;
z-index:1002;
overflow: auto;
}
.galleryentity{
display: table;
margin-bottom: 35px;
float: left;
width: 259px;
height: 250px;
background-color: #2B3039;
margin-right: 30px;
position: relative;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
-webkit-box-shadow: 0px 3px 5px 2px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 0px 3px 5px 2px rgba(50, 50, 50, 0.75);
box-shadow: 0px 3px 5px 2px rgba(50, 50, 50, 0.75);
}
.gallerylink{
display: block;
height: 100%;
width: 100%;
text-decoration: none;
}
这里是 HTML:
<div class="galleryarea">
<div class="galleryframe">
<div class="galleryentity" style="background-image:url('pic1.jpg');">
<a href="javascript:void(0)" class="gallerylink" onclick = "document.getElementById('pic1').style.display='block';document.getElementById('fade').style.display='block'"></a>
<div id="pic1" class="white_content"><img class="pic1.jpg"></div>
</div>
.
.
.
</div>
</div>
谢谢。
【问题讨论】:
-
如果你使用 jQuery 并且如果你有不同尺寸的图像,你为什么不试试 jQuery 位置选项:jqueryui.com/position。您可以相对于屏幕或任何元素定位元素,左、中、右、下、上等。试一试
-
嗯,看起来很复杂……我试试
-
嗯,这并不复杂。文档使它变得复杂。试试这个链接:css-tricks.com/jquery-ui-position-function。就像简单的英语一样简单!
-
不要使用 0% ,0 就够了。
-
@KamleshKushwaha 好的,这样吗?
$(".popup").position({ "my": "center center", "at": "center center", "of": $("body") });
标签: html css popup alignment center