在 Bootstrap 5 中,轮播电影整页而不仅仅是他的图像
in Boostrap 5, carousel moves full page instead of just his images
我正在学习 bootstrap 5,我尝试按照 Bootstrap 5 Bootstrap 5 Carousel. but when i simply copied their code and used in my template i got unexpected error.my carousel moving full page content instead of his images. Content after Carousel Div also moves when Carousel moves and when i put more div or section on page full page moves along Carousel move. here is my code Codepen Demo
的官方文档创建简单的轮播
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<link rel="stylesheet" href="icons/fontawesome.min.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" />
<style>
/*** Slider Box ***/
.sliderbox {
margin-left: 0;
padding: 0;
background-color: yellow;
}
.carousel-inner .carousel-item {
background-color: darkkhaki;
margin: 0;
margin-left: 0;
padding: 0;
}
.carousel-caption {
bottom: 20%;
padding-right: 80%;
width: 25%;
text-align: left;
}
.slider-image-heading {
font-family: Montserrat-Bold;
font-weight: 300;
font-size: xx-large;
color: white;
letter-spacing: 3px;
}
.slider-image-text {
margin-top: 40px;
letter-spacing: 2px;
}
.slider-image-btn {
background-color: #56e0cd;
}
.slider-image-btn:hover {
background-color: black;
color: white;
border-color: white;
}
.carousel-control-prev-icon {
background-color: black;
border-radius: 50%;
}
.getrugdiv {
background-color: #215f6a;
width: auto;
}
</style>
</head>
<body>
<div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/austin-fireworks.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>First slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/taj-mahal_copy.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Second slide label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/ibiza.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Third slide label</h5>
<p>Some representative placeholder content for the third slide.</p>
</div>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
<div class="container-fluid getrugdiv">
<h1> Boot Your Trip Now</h1>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js"></script>
</body>
</html>
给你...
经过反复试验,我发现从 .carousel-inner .carousel-item {...}
中删除 margin: 0;
后轮播开始工作(即白色 space 不会每次都出现幻灯片已更改)。
所以,改变这个...
.carousel-inner .carousel-item {
background-color: darkkhaki;
margin: 0;
margin-left: 0;
padding: 0;
}
...进入这个。
.carousel-inner .carousel-item {
background-color: darkkhaki;
margin-left: 0;
padding: 0;
}
请参阅下面的代码段。
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<link rel="stylesheet" href="icons/fontawesome.min.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" />
<style>
/*** Slider Box ***/
.sliderbox {
margin-left: 0;
padding: 0;
background-color: yellow;
}
.carousel-inner .carousel-item {
background-color: darkkhaki;
margin-left: 0;
padding: 0;
}
.carousel-caption {
bottom: 20%;
padding-right: 80%;
width: 25%;
text-align: left;
}
.slider-image-heading {
font-family: Montserrat-Bold;
font-weight: 300;
font-size: xx-large;
color: white;
letter-spacing: 3px;
}
.slider-image-text {
margin-top: 40px;
letter-spacing: 2px;
}
.slider-image-btn {
background-color: #56e0cd;
}
.slider-image-btn:hover {
background-color: black;
color: white;
border-color: white;
}
.carousel-control-prev-icon {
background-color: black;
border-radius: 50%;
}
.getrugdiv {
background-color: #215f6a;
width: auto;
}
</style>
</head>
<body>
<div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/austin-fireworks.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>First slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/taj-mahal_copy.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Second slide label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/ibiza.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Third slide label</h5>
<p>Some representative placeholder content for the third slide.</p>
</div>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
<div class="container-fluid getrugdiv">
<h1> Boot Your Trip Now</h1>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js"></script>
</body>
</html>
我正在学习 bootstrap 5,我尝试按照 Bootstrap 5 Bootstrap 5 Carousel. but when i simply copied their code and used in my template i got unexpected error.my carousel moving full page content instead of his images. Content after Carousel Div also moves when Carousel moves and when i put more div or section on page full page moves along Carousel move. here is my code Codepen Demo
的官方文档创建简单的轮播<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<link rel="stylesheet" href="icons/fontawesome.min.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" />
<style>
/*** Slider Box ***/
.sliderbox {
margin-left: 0;
padding: 0;
background-color: yellow;
}
.carousel-inner .carousel-item {
background-color: darkkhaki;
margin: 0;
margin-left: 0;
padding: 0;
}
.carousel-caption {
bottom: 20%;
padding-right: 80%;
width: 25%;
text-align: left;
}
.slider-image-heading {
font-family: Montserrat-Bold;
font-weight: 300;
font-size: xx-large;
color: white;
letter-spacing: 3px;
}
.slider-image-text {
margin-top: 40px;
letter-spacing: 2px;
}
.slider-image-btn {
background-color: #56e0cd;
}
.slider-image-btn:hover {
background-color: black;
color: white;
border-color: white;
}
.carousel-control-prev-icon {
background-color: black;
border-radius: 50%;
}
.getrugdiv {
background-color: #215f6a;
width: auto;
}
</style>
</head>
<body>
<div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/austin-fireworks.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>First slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/taj-mahal_copy.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Second slide label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/ibiza.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Third slide label</h5>
<p>Some representative placeholder content for the third slide.</p>
</div>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
<div class="container-fluid getrugdiv">
<h1> Boot Your Trip Now</h1>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js"></script>
</body>
</html>
给你...
经过反复试验,我发现从 .carousel-inner .carousel-item {...}
中删除 margin: 0;
后轮播开始工作(即白色 space 不会每次都出现幻灯片已更改)。
所以,改变这个...
.carousel-inner .carousel-item {
background-color: darkkhaki;
margin: 0;
margin-left: 0;
padding: 0;
}
...进入这个。
.carousel-inner .carousel-item {
background-color: darkkhaki;
margin-left: 0;
padding: 0;
}
请参阅下面的代码段。
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<link rel="stylesheet" href="icons/fontawesome.min.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" />
<style>
/*** Slider Box ***/
.sliderbox {
margin-left: 0;
padding: 0;
background-color: yellow;
}
.carousel-inner .carousel-item {
background-color: darkkhaki;
margin-left: 0;
padding: 0;
}
.carousel-caption {
bottom: 20%;
padding-right: 80%;
width: 25%;
text-align: left;
}
.slider-image-heading {
font-family: Montserrat-Bold;
font-weight: 300;
font-size: xx-large;
color: white;
letter-spacing: 3px;
}
.slider-image-text {
margin-top: 40px;
letter-spacing: 2px;
}
.slider-image-btn {
background-color: #56e0cd;
}
.slider-image-btn:hover {
background-color: black;
color: white;
border-color: white;
}
.carousel-control-prev-icon {
background-color: black;
border-radius: 50%;
}
.getrugdiv {
background-color: #215f6a;
width: auto;
}
</style>
</head>
<body>
<div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/austin-fireworks.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>First slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/taj-mahal_copy.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Second slide label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/ibiza.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Third slide label</h5>
<p>Some representative placeholder content for the third slide.</p>
</div>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
<div class="container-fluid getrugdiv">
<h1> Boot Your Trip Now</h1>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js"></script>
</body>
</html>