当我有一个滑块时,白色 space 向右

White space to right when I have a slider

所以我想在下面添加一个包含内容的滑块菜单。好吧,我已经完成了所有的菜单,并且滑块可以工作,但是右边只有一个小的白色 space 可以使它滚动。这真的没什么大不了的,但它确实让我烦恼。如果你们能帮我解决这个问题,那将不胜感激。

$('span.nav-btn').click(function() {


  $(window).resize(function() {
    if ($(window).width() > 1000) {

      $('ul.nav').removeAttr('style');
    }
  })
});
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 */

.slideshow-container {
  width: 100%;
  position: relative;
}
/* Next & previous buttons */

.prev,
.next {
  cursor: pointer;
  position: absolute;
  top: 0;
  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;
}
/* 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: 13px;
  width: 13px;
  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,
body {
  padding: 0;
  margin: 0;
  font-family: "Roboto", sans-serif;
}
.nav {
  background-color: #E74C3C;
  color: #fff;
  margin: 0;
  list-style: none;
  height: 100%;
}
.nav > li {
  display: inline-block;
}
.nav > li > a {
  text-decoration: none;
  font-size: 40px;
  color: #fff;
  padding-left: 10px;
  padding-right: 10px;
  padding-bottom: 25px;
  padding-top: 15px;
  font-weight: bold;
}
.nav li:hover {
  background-color: rgb(255, 0, 0);
  margin: 0;
  padding;
  0;
}
h2 {
  font-size: 100px;
}
.content {
  /*
 width: 100%;*/
  background-color: #333;
}
.contentArea {
  width: 1000px;
  background-color: #fff;
}
@media (max-width: 1000px) {
  .nav {
    text-align: left;
    display: none;
  }
  .nav > li {
    display: block;
  }
  .nav > li > a {
    font-size: 80px;
    line-height: 150px;
  }
  .nav-btn {
    display: block;
    background-color: #333;
    color: #FFF;
    font-size: 150px;
    text-align: center;
    cursor: pointer;
    height: 200px;
  }
  .nav-btn:before {
    content: "Menu";
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<div class="container">
  <!-- Begin Navigation -->
  <nav>
    <span class="nav-btn"></span>
    <ul class="nav">
      <li><a href="#home">HOME</a>
      </li>
      <li><a href="#about">ABOUT</a>
      </li>
      <li><a href="#projects">PROJECTS</a>
      </li>
      <li><a href="#videos">VIDEOS</a>
      </li>
      <li><a href="#contact">CONTACT</a>
      </li>
    </ul>
  </nav>
  <!-- End Navigation -->

  <!-- Begin Content -->
  <div class="content">

    <div class="slideshow-container">
      <div class="mySlides fade">
        <div class="numbertext">1 / 3</div>
        <img src="http://www.placecage.com/c/460/460" style="width:100%">
        <div class="text">Caption Text</div>
      </div>
      <div class="mySlides fade">
        <div class="numbertext">2 / 3</div>
        <img src="http://www.placecage.com/g/460/460" style="width:100%">
        <div class="text">Caption Two</div>
      </div>
      <div class="mySlides fade">
        <div class="numbertext">3 / 3</div>
        <img src="http://www.placecage.com/460/460" 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>

    <!-- Begin Content Area -->
    <div class="contentArea">
      <p>hi</p>
    </div>
    <!-- End Content Area -->
  </div>
  <!-- End Content -->
</div>

我将滑块 css 和主 css 放在不同的文件中,因为我想保持它的整洁。

此外,如果您想查看该站点,可以访问此处。 jumpymotionpictures.net

我建议您在 CSS 中添加以下内容:

body {
  overflow-x: hidden;
}

这将通过隐藏它来简单地停止 x 轴上的溢出...

因此您将无法滚动,也无法看到白色 space!

这有几个原因。

  1. 您的 contentArea 的宽度固定为 1000 像素,请尝试将其更改为其他值,例如 100%。这将有助于较小的屏幕。

  2. 有一个 class text 的容器。它的 box-sizing 在大多数浏览器上默认为 content-box,这从宽度计算中排除了填充。当容器的宽度设置为 100% 并且它有填充时,填充将添加到 100% 的顶部。 要将填充添加到容器的宽度,请将此添加到 text class 样式:box-sizing: border-box;

$('span.nav-btn').click(function() {


  $(window).resize(function() {
    if ($(window).width() > 1000) {

      $('ul.nav').removeAttr('style');
    }
  })
});
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 */

.slideshow-container {
  width: 100%;
  position: relative;
}
/* Next & previous buttons */

.prev,
.next {
  cursor: pointer;
  position: absolute;
  top: 0;
  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;
}
/* 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;
  box-sizing: border-box;
}
/* 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: 13px;
  width: 13px;
  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,
body {
  padding: 0;
  margin: 0;
  font-family: "Roboto", sans-serif;
}
.nav {
  background-color: #E74C3C;
  color: #fff;
  margin: 0;
  list-style: none;
  height: 100%;
}
.nav > li {
  display: inline-block;
}
.nav > li > a {
  text-decoration: none;
  font-size: 40px;
  color: #fff;
  padding-left: 10px;
  padding-right: 10px;
  padding-bottom: 25px;
  padding-top: 15px;
  font-weight: bold;
}
.nav li:hover {
  background-color: rgb(255, 0, 0);
  margin: 0;
  padding;
  0;
}
h2 {
  font-size: 100px;
}
.content {
  /*
 width: 100%;*/
  background-color: #333;
}
.contentArea {
  width: 100%;
  background-color: #fff;
}
@media (max-width: 1000px) {
  .nav {
    text-align: left;
    display: none;
  }
  .nav > li {
    display: block;
  }
  .nav > li > a {
    font-size: 80px;
    line-height: 150px;
  }
  .nav-btn {
    display: block;
    background-color: #333;
    color: #FFF;
    font-size: 150px;
    text-align: center;
    cursor: pointer;
    height: 200px;
  }
  .nav-btn:before {
    content: "Menu";
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<div class="container">
  <!-- Begin Navigation -->
  <nav>
    <span class="nav-btn"></span>
    <ul class="nav">
      <li><a href="#home">HOME</a>
      </li>
      <li><a href="#about">ABOUT</a>
      </li>
      <li><a href="#projects">PROJECTS</a>
      </li>
      <li><a href="#videos">VIDEOS</a>
      </li>
      <li><a href="#contact">CONTACT</a>
      </li>
    </ul>
  </nav>
  <!-- End Navigation -->

  <!-- Begin Content -->
  <div class="content">

    <div class="slideshow-container">
      <div class="mySlides fade">
        <div class="numbertext">1 / 3</div>
        <img src="http://www.placecage.com/c/460/460" style="width:100%">
        <div class="text">Caption Text</div>
      </div>
      <div class="mySlides fade">
        <div class="numbertext">2 / 3</div>
        <img src="http://www.placecage.com/g/460/460" style="width:100%">
        <div class="text">Caption Two</div>
      </div>
      <div class="mySlides fade">
        <div class="numbertext">3 / 3</div>
        <img src="http://www.placecage.com/460/460" 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>

    <!-- Begin Content Area -->
    <div class="contentArea">
      <p>hi</p>
    </div>
    <!-- End Content Area -->
  </div>
  <!-- End Content -->
</div>