我正在尝试使滑块上的图像在容器内以全宽显示。我曾尝试将英雄文本div分开,但仍然无法正常工作。我已经坚持了很长时间,意识到它可能有些愚蠢,所以堆栈溢出是我的最后选择。请参见下面的代码和显示方式图片:
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";
}
/* 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
}
}
!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)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</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>
答案 0 :(得分:0)
从您发布的屏幕截图中。问题出在您的CSS上。您已给定background-size:覆盖容器而不是内部图像。这就是为什么它不会占用整个空间的原因。您需要为图像使用以下代码,以占用容器的整个空间。
在CSS中:
.mySlides { background-size: cover ; height : 500px; }