Jor*_*tos 38 html javascript css jquery twitter-bootstrap
我试图为图像(宽度:100%)和固定高度做一个全宽度的自举旋转木马,但如果我将宽度设置为100%,自动高度也是100%
我不确定问题是否在我的文件中
<div id="myCarousel" class="carousel slide">
<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>
<!-- Carousel items -->
<div class="carousel-inner">
<div class="active item">
<%= image_tag "slider/slide-bg-1.jpg", class: "tales" %>
</div>
<div class="item">
<%= image_tag "slider/slide-bg-2.jpg", class: "tales" %>
</div>
<div class="item">
<%= image_tag "slider/slide-bg-3.jpg", class: "tales" %>
</div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
Run Code Online (Sandbox Code Playgroud)
和我的CSS文件
.tales {
width: 100%;
height: 200px;
}
Run Code Online (Sandbox Code Playgroud)
Edu*_*nda 67
你想让它响应吗?如果你那么我会建议如下:
.tales {
width: 100%;
}
.carousel-inner{
width:100%;
max-height: 200px !important;
}
Run Code Online (Sandbox Code Playgroud)
但是,响应性地处理此问题的最佳方法是使用类似的媒体查询:
/* Smaller than standard 960 (devices and browsers) */
@media only screen and (max-width: 959px) {}
/* Tablet Portrait size to standard 960 (devices and browsers) */
@media only screen and (min-width: 768px) and (max-width: 959px) {}
/* All Mobile Sizes (devices and browser) */
@media only screen and (max-width: 767px) {}
/* Mobile Landscape Size to Tablet Portrait (devices and browsers) */
@media only screen and (min-width: 480px) and (max-width: 767px) {}
/* Mobile Portrait Size to Mobile Landscape Size (devices and browsers) */
@media only screen and (max-width: 479px) {}
Run Code Online (Sandbox Code Playgroud)
小智 9
如果您使用bootstrap 4 Alpha并且Chrome中的图像高度出错,我有一个解决方案:bootstrap 4的文档说明了这一点:
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img class="d-block img-fluid" src="..." alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="..." alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="..." alt="Third slide">
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
解:
解决方案是在图像周围放置"div",使用类".container",如下所示:
<div class="carousel-item active">
<div class="container">
<img src="images/proyecto_0.png" alt="First slide" class="d-block img-fluid">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
小智 8
我推荐以下Bootstrap 3
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
min-height: 500px; /* Set slide height here */
}
Run Code Online (Sandbox Code Playgroud)
小智 7
我知道这是一个较旧的帖子,但Bootstrap仍然活着并踢!
与@ Eduardo的帖子略有不同,我不得不修改:
#myCarousel.carousel.slide {
width: 100%;
max-width: 400px; !important
}
Run Code Online (Sandbox Code Playgroud)
当我只修改时.carousel-inner {},实际图像是固定大小但左/右控件显示不正确地显示在侧面div.