繁体   English   中英

如何在自动幻灯片放映右侧对齐文本?

[英]How to align text to the right of automatic slideshow?

我无法将文字与我创建的自动幻灯片放映对齐。 我希望文本显示在幻灯片的右侧,但要低一些。

我是HTML / CSS的新手,请原谅我的无能。

尝试解决此问题时,我只能找到有关对齐单个图像旁边的文本的信息。 我试过使用float: left; 但我没有得到想要的结果。

任何帮助是极大的赞赏。

<html>
<head>
<style>

* {box-sizing: border-box;}
body {font-family: Verdana, sans-serif;}
.mySlides {display: none;}
img {vertical-align: middle;}

.slideshow-container {
  max-width: 600px;
  position: relative;
  margin-left: 110px;
}

.text {
  color: #f2f2f2;
  font-size: 15px;
  padding: 8px 12px;
  position: absolute;
  bottom: 8px;
  width: 100%;
  text-align: center;
}

.numbertext {
  color: #f2f2f2;
  font-size: 12px;
  padding: 8px 12px;
  position: absolute;
  top: 0;
}

.dot {
  height: 15px;
  width: 15px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

.active {
  background-color: #717171;
}

.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}
}
</style>
</head>

<body>
<h2 style="font-size: 15px; margin-left: 900px; display: inline;">Here     but lower. How??</h2>

<div class="slideshow-container">

 <div class="mySlides fade">
 <div class="numbertext">1 / 3</div>
  <img src="https://upload.wikimedia.org/wikipedia/commons/f/f9/Phoenicopterus_ruber_in_S%C3%A3o_Paulo_Zoo.jpg" style="width: 750px" height="350px">
  <div class="text">Caption Text</div>
</div>

<div class="mySlides fade">
  <div class="numbertext">2 / 3</div>
  <img src="http://blog.eternalvigilance.me/wp-content/uploads/2013/10/dont-tread-on-me.png" style="width: 750px" height="350px">
  <div class="text">Caption Two</div>
</div>

<div class="mySlides fade">
  <div class="numbertext">3 / 3</div>
<img src="https://natgeo.imgix.net/factsheets/thumbnails/Nature-Ocean-Wave.jpg?auto=compress,format&w=1024&h=560&fit=crop" style="width: 750px" height="350px">
  <div class="text">Caption Three</div>
</div>

</div>
<br>

<div style="margin-left: 450px">
  <span class="dot"></span> 
  <span class="dot"></span> 
  <span class="dot"></span> 
</div>

<script>
var slideIndex = 0;
showSlides();

function showSlides() {
  var i;
  var slides = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("dot");
  for (i = 0; i < slides.length; i++) {
    slides[i].style.display = "none";  
  }
  slideIndex++;
  if (slideIndex > slides.length) {slideIndex = 1}    
  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";
  setTimeout(showSlides, 4000); // Change image every 4 seconds
}
</script>
</div>
</body>
</html>

现在,我了解了标题文本的要求。 您的输出应如下所示 在此处输入图片说明

您需要在HTML节点及其CSS声明中添加div包装器。 这是您的代码。

 <html> <head> <style> * {box-sizing: border-box;} body {font-family: Verdana, sans-serif;} .mySlides {display: none;} img {vertical-align: middle;} .slideshow-container { position: relative; } .text { color: #f2f2f2; font-size: 15px; padding: 8px 12px; position: absolute; bottom: 8px; width: 100%; text-align: center; } .numbertext { color: #f2f2f2; font-size: 12px; padding: 8px 12px; position: absolute; top: 0; } .dot { height: 15px; width: 15px; margin: 0 2px; background-color: #bbb; border-radius: 50%; display: inline-block; transition: background-color 0.6s ease; } .active { background-color: #717171; } .fade { -webkit-animation-name: fade; -webkit-animation-duration: 1.5s; animation-name: fade; animation-duration: 1.5s; } .container .box { margin:50px; display:table; } .container .box .box-row { display:table-row; width : 120%; } .container .box .box-cell.box1 { text-align:justify; } .container .box .box-cell { display:table-cell; } .container .box .box-cell.box2 { text-align:justify; padding-left: 10px; } @-webkit-keyframes fade { from {opacity: .4} to {opacity: 1} } @keyframes fade { from {opacity: .4} to {opacity: 1} } </style> </head> <body> <div class="container"> <div class="box"> <div class="box-row"> <div class="slideshow-container box-cell box1"> <div class="mySlides fade"> <div class="numbertext">1 / 3</div> <img src="https://upload.wikimedia.org/wikipedia/commons/f/f9/Phoenicopterus_ruber_in_S%C3%A3o_Paulo_Zoo.jpg" style="width: 750px" height="350px"> <div class="text">Caption Text</div> </div> <div class="mySlides fade"> <div class="numbertext">2 / 3</div> <img src="http://blog.eternalvigilance.me/wp-content/uploads/2013/10/dont-tread-on-me.png" style="width: 750px" height="350px"> <div class="text">Caption Two</div> </div> <div class="mySlides fade"> <div class="numbertext">3 / 3</div> <img src="https://natgeo.imgix.net/factsheets/thumbnails/Nature-Ocean-Wave.jpg?auto=compress,format&w=1024&h=560&fit=crop" style="width: 750px" height="350px"> <div class="text">Caption Three</div> </div> </div> <div class="box-cell box2"> <h2 style="font-size: 15px;">Here but lower. How??</h2> </div> </div> </div> </div> <br> <div style="margin-left: 450px"> <span class="dot"></span> <span class="dot"></span> <span class="dot"></span> </div> <script> var slideIndex = 0; showSlides(); function showSlides() { var i; var slides = document.getElementsByClassName("mySlides"); var dots = document.getElementsByClassName("dot"); for (i = 0; i < slides.length; i++) { slides[i].style.display = "none"; } slideIndex++; if (slideIndex > slides.length) {slideIndex = 1} 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"; setTimeout(showSlides, 4000); // Change image every 4 seconds } </script> </div> </body> </html> 

如果仍然无法解决您的问题,请在评论中让我知道。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM