我一直在使用JavaScript控件构建CSS库,我正在使用纵向和横向图片。我可以让它们在主页面的中心对齐<div>
我已将图像和控件分组到一个较小的容器中但是我不能让两种类型的图像都沿着该容器内的两个轴居中
以下是我在jsfiddle的第一次努力,请看看所有建议,包括重定向到我可能错过的类似问题,欢迎使用。
<div class="image-wrap">
<div id="pic-gallery">
<div class="gal-butt">
<a onclick="plusDivs(-1)">❮</a>
</div>
<div class="pic_ver">
<a target="_blank" href="images/katie_Holding.gif">
<img class="mySlides" src="images/katie_Holding.gif" border="1" alt="" width="200" height="300">
</a>
</div>
<div class="pic_hor">
<a target="_blank" href="images/Mindees_1.gif">
<img class="mySlides" src="images/Mindees_1.gif" border="1" alt="" width="300" height="200">
</a>
</div>
<div class="pic_hor">
<a target="_blank" href="images/Mindees_2.gif">
<img class="mySlides" src="images/Mindees_2.gif" border="1" alt="" width="300" height="200">
</a>
</div>
<div class="pic_hor">
<a target="_blank" href="images/Mindees_3.gif">
<img class="mySlides" src="images/Mindees_3.gif" border="1" alt="" width="300" height="200">
</a>
</div>
<div class="gal-butt">
<a onclick="plusDivs(-1)">❯</a>
</div>
</div>
</div>
#pic-gallery {
margin-left: 330px;
width: 400px;
height: 400px;
border: 1px solid black;
align-items: center;
display: flex;
}
.image-wrapper {
margin: auto;
align-items: center;
justify-content: center;
}
.gal-butt {
font-size: 2.5em;
}
#pic-ver {
padding-top: 50px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 100px;
}
#pic-hor {
padding-top: 100px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 50px;
}
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {
slideIndex = 1
}
if (n < 1) {
slideIndex = x.length
}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex - 1].style.display = "block";
}
答案 0 :(得分:0)
将margin: auto
添加到.gal-butt
以水平居中该元素。这是一个关于中心事物https://www.w3.org/Style/Examples/007/center.en.html
#pic-gallery {
margin-left: 330px;
width: 400px;
height: 400px;
border: 1px solid black;
align-items: center;
display: flex;
}
.image-wrapper {
margin: auto;
align-items: center;
justify-content: center;
}
.gal-butt {
font-size: 2.5em;
margin: auto;
}
#pic-ver {
padding-top: 50px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 100px;
}
#pic-hor {
padding-top: 100px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 50px;
}
<div class="image-wrap">
<div id="pic-gallery">
<div class="gal-butt">
<a onclick="plusDivs(-1)">❮</a>
</div>
<div class="pic_ver">
<a target="_blank" href="images/katie_Holding.gif">
<img class="mySlides" src="images/katie_Holding.gif" border="1" alt="" width="200" height="300">
</a>
</div>
<div class="pic_hor">
<a target="_blank" href="images/Mindees_1.gif">
<img class="mySlides" src="images/Mindees_1.gif" border="1" alt="" width="300" height="200">
</a>
</div>
<div class="pic_hor">
<a target="_blank" href="images/Mindees_2.gif">
<img class="mySlides" src="images/Mindees_2.gif" border="1" alt="" width="300" height="200">
</a>
</div>
<div class="pic_hor">
<a target="_blank" href="images/Mindees_3.gif">
<img class="mySlides" src="images/Mindees_3.gif" border="1" alt="Katie holding Mindee" width="300" height="200">
</a>
</div>
<div class="gal-butt">
<a onclick="plusDivs(-1)">❯</a>
</div>
</div>
</div>
<script>
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {
slideIndex = 1
}
if (n < 1) {
slideIndex = x.length
}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex - 1].style.display = "block";
}
</script>