如何在图像上方设置子弹指示器?
.mySlides {display:none}
/* Slideshow container */
.slideshow-container {
width: 100%;
position: absolute;
margin: auto;
z-index: -1;
}
/* Caption text */
.text {
color: #f2f2f2;
font-size: 15px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* The dots/bullets/indicators */
.dot {
height: 13px;
width: 13px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active {
background-color: #717171;
}
/* Fading animation */
.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}
}
/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
.text {font-size: 11px}
}
<!--Slide Show Starts-->
<div class="slideshow-container">
<div class="mySlides fade">
<div class="numbertext">Acharya Tulsi</div>
<img src="https://www.w3schools.com/css/trolltunga.jpg" style="width:100%">
</div>
<div class="mySlides fade">
<div class="numbertext">Acharya Mahapragya</div>
<img src="https://www.planwallpaper.com/static/images/download-happy-janmashtami-hd-images.jpg" style="width:100%">
</div>
<div class="mySlides fade">
<div class="numbertext">Acharya Mahashraman</div>
<img src="https://wallpaperbrowse.com/media/images/free_high_resolution_images_for_download-1.jpg" style="width:100%">
</div>
<div class="text" style="text-align:center">
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
<!--Slide Show Ends-->
<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, 2000); // Change image every 2 seconds
}
</script>
<div>
<h2><center>Directory</center></h2>
<form>
<div>
<input type="text" placeholder="Type Sirname to get details" id=""><br><center><input type="submit" Value="Search" id=""></center>
</div>
</form>
</div>
我需要某种方式像图像
此外,如果我清除文本框并提交按钮,我将拥有我想要的相同内容。
答案 0 :(得分:1)
更清洁的解决方案是使用bootstrap's carousel。
这是一个有效的演示:
.carousel-caption {
top: 0;
bottom: auto;
}
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="https://www.w3schools.com/css/trolltunga.jpg" alt="Slide 1">
<div class="carousel-caption">
Acharya Tulsi
</div>
</div>
<div class="item">
<img src="https://www.planwallpaper.com/static/images/download-happy-janmashtami-hd-images.jpg" alt="Slide 2">
<div class="carousel-caption">
Acharya Mahapragya
</div>
</div>
<div class="item">
<img src="https://wallpaperbrowse.com/media/images/free_high_resolution_images_for_download-1.jpg" alt="image three">
<div class="carousel-caption">
Acharya Mahashraman
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
<div>
<h2><center>Directory</center></h2>
<form>
<div>
<input type="text" placeholder="Type Sirname to get details" id="">
<br>
<center>
<input type="submit" Value="Search" id="">
</center>
</div>
</form>
</div>
&#13;
答案 1 :(得分:0)
您必须关闭slideshow-container
div并设置position: relative
。
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, 2000); // Change image every 2 seconds
}
&#13;
.mySlides {display:none}
/* Slideshow container */
.slideshow-container {
width: 100%;
position: relative;
margin: auto;
z-index: -1;
}
/* Caption text */
.text {
color: #f2f2f2;
font-size: 15px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* The dots/bullets/indicators */
.dot {
height: 13px;
width: 13px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active {
background-color: #717171;
}
/* Fading animation */
.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}
}
/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
.text {font-size: 11px}
}
&#13;
<!--Slide Show Starts-->
<div class="slideshow-container">
<div class="mySlides fade">
<div class="numbertext">Acharya Tulsi</div>
<img src="https://www.w3schools.com/css/trolltunga.jpg" style="width:100%">
</div>
<div class="mySlides fade">
<div class="numbertext">Acharya Mahapragya</div>
<img src="https://www.planwallpaper.com/static/images/download-happy-janmashtami-hd-images.jpg" style="width:100%">
</div>
<div class="mySlides fade">
<div class="numbertext">Acharya Mahashraman</div>
<img src="https://wallpaperbrowse.com/media/images/free_high_resolution_images_for_download-1.jpg" style="width:100%">
</div>
<div class="text" style="text-align:center">
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
</div> <!-- CLOSING TAG -->
<div>
<h2><center>Directory</center></h2>
<form>
<div>
<input type="text" placeholder="Type Sirname to get details" id=""><br><center><input type="submit" Value="Search" id=""></center>
</div>
</form>
</div>
&#13;
答案 2 :(得分:0)
像这样更改.text
css。增加底部像素
.text{
bottom: 120px;
}
.mySlides {display:none}
/* Slideshow container */
.slideshow-container {
width: 100%;
position: absolute;
margin: auto;
z-index: -1;
}
/* Caption text */
.text {
color: #f2f2f2;
font-size: 15px;
position: absolute;
bottom: 120px;
width: 100%;
text-align: center;
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* The dots/bullets/indicators */
.dot {
height: 13px;
width: 13px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active {
background-color: #717171;
}
/* Fading animation */
.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}
}
/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
.text {font-size: 11px}
}
<!--Slide Show Starts-->
<div class="slideshow-container">
<div class="mySlides fade">
<div class="numbertext">Acharya Tulsi</div>
<img src="https://www.w3schools.com/css/trolltunga.jpg" style="width:100%">
</div>
<div class="mySlides fade">
<div class="numbertext">Acharya Mahapragya</div>
<img src="https://www.planwallpaper.com/static/images/download-happy-janmashtami-hd-images.jpg" style="width:100%">
</div>
<div class="mySlides fade">
<div class="numbertext">Acharya Mahashraman</div>
<img src="https://wallpaperbrowse.com/media/images/free_high_resolution_images_for_download-1.jpg" style="width:100%">
</div>
<div class="text" style="text-align:center">
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
<!--Slide Show Ends-->
<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, 2000); // Change image every 2 seconds
}
</script>
<div>
<h2><center>Directory</center></h2>
<form>
<div>
<input type="text" placeholder="Type Sirname to get details" id=""><br><center><input type="submit" Value="Search" id=""></center>
</div>
</form>
</div>