我在让html文档中的幻灯片显示正常工作时遇到问题。我正在尝试将幻灯片放在我的homebody div中,以便布局与我的其他网页相同。此外,我的上一页和下一页按钮不会出现在我想要的图像旁边。附件是我的幻灯片放映和家庭容器div的代码示例的链接。任何帮助,将不胜感激。
enter code here
https://jsfiddle.net/deandretodd/km5npyrr/#&togetherjs=LvuLT6Uvf9
答案 0 :(得分:0)
不确定'homebody'是什么意思。
.slideshow-container
)中移除了浮动并应用了margin: auto;
,因此它将居中top: 50%; margin-top: 50%;
将它们推向屏幕太远。将position: relative
应用于幻灯片展示容器(.slideshow-container
),使后面/下一个箭头的相对父级位置自己,移除margin-top
CSS并将transform: translateY(-50%);
应用于它们所以它们在幻灯片中垂直居中。 这是你想要的吗? https://jsfiddle.net/km5npyrr/2/
.slideshow-container {
width: 650px;
margin: auto;
position: relative;
}
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
color: white;
font-weight: bold;
transform: translateY(-50%);
font-size: 18px;
transition: 0.6 ease;
border-radius: 0 3px 3px 0;
}
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
}
.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: relative;
bottom: 8px;
width: 100%;
text-align: center;
}
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
.dot {
cursor: pointer;
height: 13px;
width: 13px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active,
.dot:hover {
background-color: #717171;
}
.dots {
clear: both;
}
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
@-webkit-keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
@keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
body p {
margin-bottom: 20px;
}
<div class="slideshow-container">
<div class="mySlides fade">
<div class="numbertext">1 / 3</div>
<img src="http://www.w3schools.com/css/img_fjords.jpg" style="width:100%">
<div class="text">Caption</div>
</div>
<div class="mySlides fade">
<div class="numbertext">2 / 3</div>
<img src="http://www.jqueryscript.net/images/Simplest-Responsive-jQuery-Image-Lightbox-Plugin-simple-lightbox.jpg" style="width:100%">
<div class="text">Caption</div>
</div>
<div class="mySlides fade">
<div class="numbertext">3 / 3</div>
<img src="http://cdn.arstechnica.net/wp-content/uploads/2016/02/5718897981_10faa45ac3_b-640x624.jpg" style="width: 100%">
<div class="text">Caption</div>
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
<div style="text-align:center" class="dots">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>
<script>
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {
slideIndex = 1
}
if (n < 1) {
slideIndex = slides.length
}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " active";
}
</script>