首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >主人公滑块图像不显示全宽

主人公滑块图像不显示全宽
EN

Stack Overflow用户
提问于 2019-03-16 20:55:51
回答 1查看 184关注 0票数 0

我正在尝试让我的滑块上的图像在容器内显示全宽。我已经尝试过分离主人公-文本div,但它仍然不起作用。我已经在这个问题上坚持了很长时间,并且意识到这可能是一些愚蠢的事情,所以堆栈溢出是我最后的选择。请看下面的代码和它如何显示的图片:

Display Image

代码语言:javascript
复制
var slideIndex = 1;
showSlides(slideIndex);

// Next/previous controls
function plusSlides(n) {
  showSlides(slideIndex += n);
}

// Thumbnail image controls
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";
}
代码语言:javascript
复制
/* HERO IMAGE STARTS */
.hero-image {
  background-image: linear-gradient(rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0.8));
  height: 500px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  position: relative;
}

.hero-text {
  text-align: center;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
}

.hero-text h1 {
  text-transform: uppercase;
  font-weight: 600;
}

.hero-text .button {
  font-size: 13px;
  padding: 14px 30px !important;
}

/* BLOCKS STARTS */
.border-bottom {
  border-bottom: 1px solid #dee2e6 !important;
}

.no-gutters {
  margin-right: 0;
  margin-left: 0;
}

.padding-5 {
  padding: 3rem !important;
}

.height-100 {
  height: 100% !important;
}

.width-100 {
  width: 100% !important;
}

.bg-light {
  background-color: #f8f9fa !important;
}

.display-block {
  display: block !important;
}

.marginbottom-3 {
  margin-bottom: 1rem !important;
}

.block-feature h2 {
  text-transform: uppercase;
  font-size: 16px;
  position: relative;
  padding-bottom: 20px;
  margin-bottom: 20px;
}

.block-feature h2::after {
  position: absolute;
  content: "";
  width: 50px;
  height: 2px;
  bottom: 0;
  background: #763797;
  left: 0;
}

display-4 {
  font-size: 3.5rem;
  font-weight: 300;
  line-height: 1.2;
}

* {
  box-sizing: border-box
}

/* 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: 16px;
  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);
  color: #763797;
}

/* 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
  }
}
代码语言:javascript
复制
!doctype html>
<html class="no-js" lang="en" dir="ltr">

<head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>GloboGym</title>
  <link rel="stylesheet" href="assets/css/foundation.css">
  <link rel="stylesheet" href="assets/css/app.css">
  <link rel="stylesheet" href="assets/css/style.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <link rel="stylesheet" href="assets/fonts/flaticon/font/flaticon.css">
</head>

<body>

  <!-- HERO AREA STARTS -->
  <section>
    <div class="hero-image">
      <div class="hero-text mySlides fade" style="background-image: url(assets/img/banner-bg.jpg);">
        <h1>From Only £14.99 A Month, Everybody Is Welcome</h1>
        <a href="membership.html" class="button">Join Now</a>
      </div>
      <div class="hero-text mySlides fade" style="background-image: url(assets/img/banner-bg1.jpg);">
        <h1>From Only £14.99 A Month, Everybody Is Welcome</h1>
        <a href="membership.html" class="button">Join Now</a>
      </div>
      <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
      <a class="next" onclick="plusSlides(1)">&#10095;</a>
    </div>
  </section>
  <!-- HERO AREA ENDS -->
  <script src="assets/js/vendor/jquery.js"></script>
  <script src="assets/js/vendor/what-input.js"></script>
  <script src="assets/js/vendor/foundation.js"></script>
  <script src="assets/js/app.js"></script>
  <script src="assets/js/vendor/globogym-scrips.js"></script>
</body>

</html>

EN

回答 1

Stack Overflow用户

发布于 2019-03-16 21:08:52

从你发布的截图中。问题出在你的css上。你给了容器背景大小:封面,而不是里面的图片。这就是为什么它不会占据整个空间的原因。您需要为您的图像编写以下代码,以占据容器的整个空间。

在CSS中:

代码语言:javascript
复制
.mySlides { background-size: cover ; height : 500px; }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55197037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档