gpt4 book ai didi

javascript - 英雄 slider 图像未显示全宽

转载 作者:行者123 更新时间:2023-11-28 00:14:27 25 4
gpt4 key购买 nike

我试图让 slider 上的图像在容器内全宽显示。我试过分离英雄文本 div,但它仍然不起作用。我多年来一直坚持这个,并意识到它可能是愚蠢的,所以堆栈溢出是我最后的选择。请参阅下面的代码和显示方式的图像:

Display Image

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)">&#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>

最佳答案

根据您发布的屏幕截图。问题出在你的CSS上。您已将 background-size: 覆盖到容器而不是内部图像。这就是为什么它不会占用整个空间的原因。您需要以下代码让您的图像占用容器的整个空间。

在 CSS 中:

.mySlides { background-size: cover ; height : 500px; }

关于javascript - 英雄 slider 图像未显示全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55197037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com