[英]Bootstrap carousel caption
我正在使用以下代碼實現輪播。 在這個我想要兩個標題作為每個輪播幻燈片。 所以我將再添加一個標題 div,但它無法正常工作。我需要一個旋轉木馬左上角的標題,另一個旋轉木馬底部。 我不知道 css 所以請幫助任何人。
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="la.jpg" alt="Los Angeles" style="width:100%;">
<div class="carousel-caption">
<h3>Los Angeles</h3>
<p>LA is always so much fun!</p>
</div>
</div>
<div class="item">
<img src="chicago.jpg" alt="Chicago" style="width:100%;">
<div class="carousel-caption">
<h3>Chicago</h3>
<p>Thank you, Chicago!</p>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
我認為以下示例會對您有所幫助,
使標題為 100% 寬度和高度,並覆蓋 h3 和 p 文本的一些屬性(使用不同視圖的媒體查詢)
.carousel-caption { width:100%; height:100%; left:0 !important; } .carousel-caption h3 { text-align:left; margin-left:30px; } .carousel-caption p { margin-top:40%; } @media screen and (max-width: 479px) { .carousel-caption p { margin-top:20%; } } @media screen and (min-width: 480px) and (max-width: 640px){ .carousel-caption p { margin-top:30%; } } @media screen and (min-width: 641px) { .carousel-caption p { margin-top:40%; } }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div id="myCarousel" class="carousel slide" data-ride="carousel"> <!-- Indicators --> <ol class="carousel-indicators"> <li data-target="#myCarousel" data-slide-to="0" class="active"></li> <li data-target="#myCarousel" data-slide-to="1"></li> <li data-target="#myCarousel" data-slide-to="2"></li> </ol> <!-- Wrapper for slides --> <div class="carousel-inner"> <div class="item active"> <img src="https://www.w3schools.com/bootstrap/la.jpg" alt="Los Angeles"> <div class="carousel-caption"> <h3>Los Angeles</h3> <p>LA is always so much fun!</p> </div> </div> <div class="item"> <img src="https://www.w3schools.com/bootstrap/chicago.jpg" alt="Chicago"> <div class="carousel-caption"> <h3>Chicago</h3> <p>Thank you, Chicago!</p> </div> </div> <div class="item"> <img src="https://www.w3schools.com/bootstrap/ny.jpg" alt="New York"> <div class="carousel-caption"> <h3>New York</h3> <p>We love the Big Apple!</p> </div> </div> </div> <!-- Left and right controls --> <a class="left carousel-control" href="#myCarousel" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left"></span> <span class="sr-only">Previous</span> </a> <a class="right carousel-control" href="#myCarousel" data-slide="next"> <span class="glyphicon glyphicon-chevron-right"></span> <span class="sr-only">Next</span> </a> </div>
可能這會有所幫助。
例如這里> https://jsfiddle.net/devefrontend/21036h5c/10/
<div class="carousel-caption">
<h3 class="text-right">Los Angeles</h3>
<p class="text-right">LA is always so much fun!</p>
</div>
和CSS
.carousel-caption {
width:100%;
height:100%;
left:0;
padding: 50px;
}
這部分是我所需要和幫助的。 謝謝。
.carousel-caption {
width:100%;
height:100%;
left:0 !important;
}
.carousel-caption h3 {
text-align:left;
margin-left:30px;
}
.carousel-caption p {
margin-top:40%;
}
@media screen and (max-width: 479px) {
.carousel-caption p {
margin-top:20%;
}
}
@media screen and (min-width: 480px) and (max-width: 640px){
.carousel-caption p {
margin-top:30%;
}
}
@media screen and (min-width: 641px) {
.carousel-caption p {
margin-top:40%;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.