灯箱图片不居中
lightbox images not centering
我有一个问题,我的灯箱图片没有居中。图像没有以页面为中心,也没有以它们所在的列为中心。我看不出在哪里可以将其居中,因为它看起来是正确的。我将不胜感激任何人的帮助。
网站是http://temp1.absolutehtml.co.uk/gallery.html
HTML
<a class="lightbox" href="#image1">
<img src="../images/pexels-photo (1).jpg" alt="image1"/>
</a>
<!-- lightbox -->
<div class="lightbox-target" id="image1">
<img src="../images/pexels-photo (1).jpg" alt="image1"/>
<a class="lightbox-close" href="#"></a>
</div>
CSS
/* Styles the lightbox, removes it from sight and adds the fade-in transition */
.lightbox-target {
position: fixed;
top: -100%;
width: 100%;
background: rgba(0,0,0,.7);
width: 100%;
opacity: 0;
-webkit-transition: opacity .5s ease-in-out;
-moz-transition: opacity .5s ease-in-out;
-o-transition: opacity .5s ease-in-out;
transition: opacity .5s ease-in-out;
overflow: hidden;
}
/* Styles the lightbox image, centers it vertically and horizontally, adds the zoom-in transition and makes it responsive using a combination of margin and absolute positioning */
.lightbox-target img {
margin: auto;
position: absolute;
top: 0;
left:0;
right:0;
bottom: 0;
max-height: 0%;
max-width: 0%;
border: 3px solid white;
box-shadow: 0px 0px 8px rgba(0,0,0,.3);
box-sizing: border-box;
-webkit-transition: .5s ease-in-out;
-moz-transition: .5s ease-in-out;
-o-transition: .5s ease-in-out;
transition: .5s ease-in-out;
}
/* Styles the close link, adds the slide down transition */
a.lightbox-close {
display: block;
width:50px;
height:50px;
box-sizing: border-box;
background: white;
color: black;
text-decoration: none;
position: absolute;
top: -80px;
right: 0;
-webkit-transition: .5s ease-in-out;
-moz-transition: .5s ease-in-out;
-o-transition: .5s ease-in-out;
transition: .5s ease-in-out;
}
/* Provides part of the "X" to eliminate an image from the close link */
a.lightbox-close:before {
content: "";
display: block;
height: 30px;
width: 1px;
background: black;
position: absolute;
left: 26px;
top:10px;
-webkit-transform:rotate(45deg);
-moz-transform:rotate(45deg);
-o-transform:rotate(45deg);
transform:rotate(45deg);
}
/* Provides part of the "X" to eliminate an image from the close link */
a.lightbox-close:after {
content: "";
display: block;
height: 30px;
width: 1px;
background: black;
position: absolute;
left: 26px;
top:10px;
-webkit-transform:rotate(-45deg);
-moz-transform:rotate(-45deg);
-o-transform:rotate(-45deg);
transform:rotate(-45deg);
}
/* Uses the :target pseudo-class to perform the animations upon clicking the .lightbox-target anchor */
.lightbox-target:target {
opacity: 1;
top: 0;
bottom: 0;
}
.lightbox-target:target img {
margin-top: 4%;
max-height: 90%;
max-width: 90%;
margin-left: auto;
margin-right: auto;
}
.lightbox-target:target a.lightbox-close {
margin-top: 5%;
margin-right: 6%;
top: 0px;
}
图像在其容器内居中,但容器超出了屏幕。您将其设置为 position: fixed
和 width: 100%
,使其与视口一样宽。但是你没有设置 left
或 right
,所以它的水平位置就是那个元素自然出现的地方。
添加这个将解决您的问题:
.lightbox-target {
left: 0px;
}
将此添加到样式:
.ril-image-current { max-width: none !important; }
我有一个问题,我的灯箱图片没有居中。图像没有以页面为中心,也没有以它们所在的列为中心。我看不出在哪里可以将其居中,因为它看起来是正确的。我将不胜感激任何人的帮助。
网站是http://temp1.absolutehtml.co.uk/gallery.html
HTML
<a class="lightbox" href="#image1">
<img src="../images/pexels-photo (1).jpg" alt="image1"/>
</a>
<!-- lightbox -->
<div class="lightbox-target" id="image1">
<img src="../images/pexels-photo (1).jpg" alt="image1"/>
<a class="lightbox-close" href="#"></a>
</div>
CSS
/* Styles the lightbox, removes it from sight and adds the fade-in transition */
.lightbox-target {
position: fixed;
top: -100%;
width: 100%;
background: rgba(0,0,0,.7);
width: 100%;
opacity: 0;
-webkit-transition: opacity .5s ease-in-out;
-moz-transition: opacity .5s ease-in-out;
-o-transition: opacity .5s ease-in-out;
transition: opacity .5s ease-in-out;
overflow: hidden;
}
/* Styles the lightbox image, centers it vertically and horizontally, adds the zoom-in transition and makes it responsive using a combination of margin and absolute positioning */
.lightbox-target img {
margin: auto;
position: absolute;
top: 0;
left:0;
right:0;
bottom: 0;
max-height: 0%;
max-width: 0%;
border: 3px solid white;
box-shadow: 0px 0px 8px rgba(0,0,0,.3);
box-sizing: border-box;
-webkit-transition: .5s ease-in-out;
-moz-transition: .5s ease-in-out;
-o-transition: .5s ease-in-out;
transition: .5s ease-in-out;
}
/* Styles the close link, adds the slide down transition */
a.lightbox-close {
display: block;
width:50px;
height:50px;
box-sizing: border-box;
background: white;
color: black;
text-decoration: none;
position: absolute;
top: -80px;
right: 0;
-webkit-transition: .5s ease-in-out;
-moz-transition: .5s ease-in-out;
-o-transition: .5s ease-in-out;
transition: .5s ease-in-out;
}
/* Provides part of the "X" to eliminate an image from the close link */
a.lightbox-close:before {
content: "";
display: block;
height: 30px;
width: 1px;
background: black;
position: absolute;
left: 26px;
top:10px;
-webkit-transform:rotate(45deg);
-moz-transform:rotate(45deg);
-o-transform:rotate(45deg);
transform:rotate(45deg);
}
/* Provides part of the "X" to eliminate an image from the close link */
a.lightbox-close:after {
content: "";
display: block;
height: 30px;
width: 1px;
background: black;
position: absolute;
left: 26px;
top:10px;
-webkit-transform:rotate(-45deg);
-moz-transform:rotate(-45deg);
-o-transform:rotate(-45deg);
transform:rotate(-45deg);
}
/* Uses the :target pseudo-class to perform the animations upon clicking the .lightbox-target anchor */
.lightbox-target:target {
opacity: 1;
top: 0;
bottom: 0;
}
.lightbox-target:target img {
margin-top: 4%;
max-height: 90%;
max-width: 90%;
margin-left: auto;
margin-right: auto;
}
.lightbox-target:target a.lightbox-close {
margin-top: 5%;
margin-right: 6%;
top: 0px;
}
图像在其容器内居中,但容器超出了屏幕。您将其设置为 position: fixed
和 width: 100%
,使其与视口一样宽。但是你没有设置 left
或 right
,所以它的水平位置就是那个元素自然出现的地方。
添加这个将解决您的问题:
.lightbox-target {
left: 0px;
}
将此添加到样式:
.ril-image-current { max-width: none !important; }