简体   繁体   English

如何使文字显示在滑块顶部?

[英]how do I get my text to appear on top of my slider?

I have issues with my slider. 我的滑块有问题。 My text h1 does not appear on top of my slider. 我的文本h1不会出现在滑块顶部。 I tried the z-index but it did not work. 我尝试了z-index但是它没有用。 it seems that the image appear next to my slide and not on it. 图像似乎出现在我的幻灯片旁边而不是它上。 在此处输入图片说明

here is my html file: 这是我的html文件:

 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"; } 
 slideshow-container { width: 100%; position: relative; margin: auto; float: left; display: block; margin-top: 94px; } .slideshow-container .slider-text{ width:100%; float:left; display:block; background:#008080; height:510px; } .slideshow-container .slider-text h1 { d color: #fff; font-weight: 400; text-align: center; width: 667px; display: block; margin: 130px auto auto; font-size: 35px; font-weight: 600; } .slideshow-container .slider-text p { color: #fff; font-size: 17px; text-align: center; max-width: 700px; display: block; margin: 15px auto auto; font-weight: 400; letter-spacing: 0.5px; } .slideshow-container .prev, .slideshow-container .next { cursor: pointer; position: absolute; top: 50%; width: auto; padding: 11px 18px; margin-top: -22px; color: white; font-weight: bold; font-size: 18px; transition: 0.6s ease; border-radius: 48px; height: 48px; width: 48px; background: rgba(0,0,0, 0.4); } .slideshow-container .next{ right: 16px; } .slideshow-container .prev{ left: 16px; } .slideshow-container .prev:hover, .slideshow-container .next:hover { background-color: rgba(0,0,0,1); text-decoration:none; } .slider-image { display: flex } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <section class="slideshow-container"> <div class="mySlides fade"> <div class="slider-image"> <img src="image1.jpg" alt="image1"/> <div class="slider-text"> <h1><span> why book an expensive hotel when you can book a cheap apartment</span></h1> <p>Lorem ipsum dolor sit amet, consecteur adipiscing elit. Donec venenatis bibendum nunc ut convallis. Suspendisse in nunc unterdum quam pellentesque.</p> </div> </div> </div> </div> 

I would move the <div id="slider-text"> before the <img> tag and then add the following to make it appear on top : 我将<div id="slider-text"><img>标记之前,然后添加以下内容使其显示在顶部:

#slider-text {
   float: left;
   margin : auto;
   margin-top : 20%;
}

or 要么

#slider-text {
   position: absolute;
   top: 20%;
   left: 0;
   width: 100%;
   text-align : center;
}

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

相关问题 如何使此HTML画布动画显示在图像顶部? - How do I get this HTML canvas animation to appear on top of my image? 如何让我的芯片出现在这个应用程序的右上角以做出反应? - How do I get my chip to appear on the top right corner of this app in react? 如何修正我的文字使其显示在一行上? - How do I fix my text to make it appear on one line? 每当我点击我的图片 slider 上的下一步或上一步时,它会滚动到页面顶部,我该如何停止呢? - Whenever i click next or prev on my image slider it scrolls to the top of page how do i stop this? 如何使网格从文本框中显示 - How I can I get my grid to appear from a text box 如何在我的jQuery图像和文本滑块中添加左/右箭头(下一个/上一个)功能? - How do I add Left/Right Arrow (Next/Previous) functionality to my jQuery image and text slider? 如何在我的图像 slider 上添加文本并使每个图像都不同? - How do I add text over my image slider and make it different for each image? 单击“添加任务”后,如何让我的文本出现在任务下? - How to get my text to appear under tasks after I click “add task”? 如何使解析后的html显示为html而不是纯文本? - How can I get my parsed html to appear as html instead of plain text? 我的slider有问题,没有出现 - Problem with my slider, it does not appear
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM