旋转木马正在与英雄图像和导航栏合并



我正在制作一个有趣的小网站。。。我在以下方面的帮助下创建了英雄图像和导航栏https://www.w3schools.com还尝试添加旋转木马,但它似乎正在Navbar和Hero Image之间融合。。。

参考编号:无旋转木马

与旋转木马:合并!

我想实现的是这个,但它应该在它下面,而不是合并在…中

我尝试了很多方法,搜索了整个StackOverFlow网站,但我似乎有一个愚蠢的大脑,无法理解这个愚蠢的问题。

以下是一些源代码,以备您需要:CSS

.hero-image{
background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url("heroimage.jpg");
height: 50%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
}
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
transition-duration: 0.4s;
cursor: pointer;
}
.hero-text{
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-family: 'Ubuntu', sans-serif;
}
nav {
background-color: black;
height: 50px;
}
nav a {
float: right;
color: white;
background-color: 1a1a1a;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 16px;
font-family: 'Open Sans', sans-serif;
}
nav a:hover {
background-color: #3b86ff;
}
* {box-sizing:border-box}
/* Slideshow container */
.slideshow-container {
max-width: 1000px;
position: fixed;
margin: auto;
z-index:4;
}
/* Hide the images by default */
.mySlides {
display: none;
}
/* Next & previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}
/* Caption text */
.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
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 {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active, .dot:hover {
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}
}

HTML

<html>
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Ubuntu:wght@300&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300&family=Ubuntu:wght@300&display=swap" rel="stylesheet">
<link rel="stylesheet" href="styles.css">
<title>
Checkmate - Chess Tournaments Online
</title>
<link rel = "icon" href ="CheckmateIcon.jpeg" type = "image/x-icon">
</head>
<body>
<div class="hero-image">
<div class="hero-text">
<h1 style="font-size:50px">Checkmate</h1>
<p>Chess Tournaments Online</p>
</div>
</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>>
<nav>
<a href=#>Tournaments</a>
<a href=#>Event Plan</a>
<a href=#>Register</a>
<nav>
<div class="slideshow-container">
<div class="mySlides fade">
<div class="numbertext">1 / 3</div>
<img src="img1.jpg" style="width:100%">
<div class="text">Caption Text</div>
</div>
<div class="mySlides fade">
<div class="numbertext">2 / 3</div>
<img src="img2.jpg" style="width:100%">
<div class="text">Caption Two</div>
</div>
<div class="mySlides fade">
<div class="numbertext">3 / 3</div>
<img src="img3.jpg" style="width:100%">
<div class="text">Caption Three</div>
</div>
<a class="prev" onclick="plusSlides(-1)">&#10094;</a>
<a class="next" onclick="plusSlides(1)">&#10095;</a>
</div>
<br>
<div style="text-align:center">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>
</body>
</html>

告诉我做错了什么TT_TT

从这里我可以看到,您在幻灯片放映容器上使用position:fixed,而没有赋予它top属性。它将坚持top

试试这个

/*幻灯片展示容器*/

.slideshow-container {
max-width: 1000px;
position: fixed;
margin: auto;
z-index:4;
top:50px;
}
<body>
<nav>
<a href="#">Tournaments</a>
<a href="#">Event Plan</a>
<a href="#">Register</a>
<nav>
<div class="hero-image">
<div class="hero-text">
<h1 style="font-size: 50px">Checkmate</h1>
<p>Chess Tournaments Online</p>
</div>
</div>
</nav>
</nav>

<div class="slideshow-container">
<div class="mySlides fade">
<div class="numbertext">1 / 3</div>
<img
src="https://cdn.pixabay.com/photo/2021/05/06/10/27/tulips-6233077__480.jpg"
style="width: 100%"
/>
<div class="text">Caption Text</div>
</div>
<div class="mySlides fade">
<div class="numbertext">2 / 3</div>
<img
src="https://cdn.pixabay.com/photo/2021/05/06/10/27/tulips-6233077__480.jpg"
style="width: 100%"
/>
<div class="text">Caption Two</div>
</div>
<div class="mySlides fade">
<div class="numbertext">3 / 3</div>
<img
src="https://cdn.pixabay.com/photo/2021/05/06/10/27/tulips-6233077__480.jpg"
style="width: 100%"
/>
<div class="text">Caption Three</div>
</div>
<a class="prev" onclick="plusSlides(-1)">&#10094;</a>
<a class="next" onclick="plusSlides(1)">&#10095;</a>
</div>
<br />
<div style="text-align: center">
<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>

最新更新