为什么这些div样式破坏了我的网站布局?

时间:2017-04-21 19:54:34

标签: html css

这是我的主要代码:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/*SLIDESHOW*/
body {
    background-color: #150a35;
}
* {box-sizing:border-box}
body {font-family: Verdana,sans-serif;}
.mySlides {display:none}

/* Slideshow container */
.slideshow-container {
  max-width: 1000px;
  position: relative;
  margin: auto;
}


/* The dots/bullets/indicators */
.dot {
  height: 13px;
  width: 13px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 100%;
  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}
}

/* SLIDESHOW */
/* Navigation list */
body {margin: 0;}

ul.topnav {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #7c4dff;
}

ul.topnav li {float: left;}

ul.topnav li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

ul.topnav li a:hover:not(.active) {background-color: #111;}

ul.topnav li a.active {background-color: #4CAF50;}

ul.topnav li.right {float: right;}

@media screen and (max-width: 600px){
    ul.topnav li.right, 
    ul.topnav li {float: none;}
}

</style>
</head>

<body>
<ul class="topnav">
  <li><a class="active" href="#hyperkeys">Hyper-Keys</a></li>
  <li><a href="#home">Home</a></li>
  <li><a href="#games">Games</a></li>
  <li class="right"><a href="#tos">Terms of Service</a></li>
  <li class="right"><a href="#contact">Contact</a></li>
  <li class="right"><a href="#contact">FAQ</a></li>
</ul>

<br>
<br>
<div class="slideshow-container">

<div class="mySlides fade">
  <img src="1.png" style="width:100%">
</div>

<div class="mySlides fade">
  <img src="2.png" style="width:100%">
</div>

<div class="mySlides fade">
  <img src="3.png" style="width:100%">
</div>

</div>
<br>

<div style="text-align:center">
  <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, 2000); // Change image every 2 seconds
}
</script>
<br>

</body>
</html> 

这就是它的样子:

enter image description here

但是当我将其添加到<head>

div {
    padding: 15px 30px; 
    background: #7c4dff;
    width: 430px;
    border-radius: 8px;
}

这发生在网站上:

enter image description here

所有事情都重叠,你无法理解任何事情。我做错了什么?

1 个答案:

答案 0 :(得分:2)

使用

div {
    padding: 15px 30px; 
    background: #7c4dff;
    width: 430px;
    border-radius: 8px;
}

更改页面上的每个div 以匹配这些属性。 所有5个,无论任何课程。

您需要更加具体的CSS选择器。

div.thisdiv {
    padding: 15px 30px; 
    background: #7c4dff;
    width: 430px;
    border-radius: 8px;
}

<div class="thisdiv" style="text-align:center">
  <span class="dot"></span> 
  <span class="dot"></span> 
  <span class="dot"></span> 
</div>
相关问题