簡體   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