引导轮播宽度和高度
Bootstrap carousel width and height
我试图为图像做一个全宽(宽度: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>
和我的 CSS 文件
.tales {
width: 100%;
height: 200px;
}
你想让它响应起来吗?如果你是,那么我只会推荐以下内容:
.tales {
width: 100%;
}
.carousel-inner{
width:100%;
max-height: 200px !important;
}
但是,响应式处理此问题的最佳方法是使用如下媒体查询:
/* 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) {}
使用 bootstrap 4 Alpha 并且 chrome 中图像的高度有错误,我有一个解决方案:引导程序 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>
溶液:
解决方案是在图像周围放置"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>
我为Bootstrap 3推荐以下内容
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
min-height: 500px; /* Set slide height here */
}
这是一个较旧的帖子,但 Bootstrap 还活着并且还在踢!
与@Eduardo的帖子略有不同,我不得不修改:
#myCarousel.carousel.slide {
width: 100%;
max-width: 400px; !important
}
当我只修改.carousel-inner {}
时,实际图像是固定大小的,但左/右控件在div
一侧显示不正确。
我遇到了同样的问题。
当我的幻灯片向左动画时,我的身高更改为其原始高度(在响应式网站中)
所以我只用CSS修复了它:
.carousel .item.left img{
width: 100% !important;
}
我创建了一个适合我的响应式示例,我发现它非常简单,请查看我的轮播填充:
.carousel-fill {
height: -o-calc(100vh - 165px) !important;
height: -webkit-calc(100vh - 165px) !important;
height: -moz-calc(100vh - 165px) !important;
height: calc(100vh - 165px) !important;
width: auto !important;
overflow: hidden;
display: inline-block;
text-align: center;
}
.carousel-item {
text-align: center !important;
}
我的导航高度+页脚小于 165px 的头发,因此该值对我有用。 取下适合您的值,我从引导中覆盖了 .carousel 项目,因此请确保按视频居中。
我的轮播看起来像这样,请注意视频标签上的"轮播填充"。
<div>
<div id="myCarousel" class="carousel slide carousel-fade text-center" 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>
<li data-target="#myCarousel" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="carousel-item active">
<video autoplay muted class="carousel-fill">
<source src="~/Video/CATSTrade.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<div class="carousel-caption">
<h2>CATS IV Trade engine</h2>
<p>Automated trading for high ROI</p>
</div>
</div>
<div class="carousel-item">
<video muted loop class="carousel-fill">
<source src="~/Video/itrs.mp4" type="video/mp4">
</video>
<div class="carousel-caption">
<h2>Machine learning</h2>
<p>Machine learning specialist</p>
</div>
</div>
<div class="carousel-item">
<video muted loop class="carousel-fill">
<source src="~/Video/frequency.mp4" type="video/mp4">
</video>
<div class="carousel-caption">
<h3>Low latency development</h3>
<p>Create ultra fast systems with our consultants</p>
</div>
</div>
<div class="carousel-item">
<img src="~/Images/data pipeline faded.png" class="carousel-fill" />
<div class="carousel-caption">
<h3>Big Data</h3>
<p>Maintain, generate, and host big data</p>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#myCarousel" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#myCarousel" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
如果有人需要像我一样控制视频,我会像这样启动和停止视频:
<script language="JavaScript" type="text/javascript">
$(document).ready(function () {
$('.carousel').carousel({ interval: 8000 })
$('#myCarousel').on('slide.bs.carousel', function (args) {
var videoList = document.getElementsByTagName("video");
switch (args.from) {
case 0:
videoList[0].pause();
break;
case 1:
videoList[1].pause();
break;
case 2:
videoList[2].pause();
break;
}
switch (args.to) {
case 0:
videoList[0].play();
break;
case 1:
videoList[1].play();
break;
case 2:
videoList[2].play();
break;
}
})
});
</script>
我发现,如果您只想更改图像所占元素的高度,这将是有帮助的代码。
.carousel-item {
height: 600px !important;
}
但是,这不会使图像的大小动态化,它只会将图像裁剪为其大小。
只需将height="400px"放入图像属性中,例如
<img class="d-block w-100" src="../assets/img/natural-backdrop.jpg" height="400px" alt="First slide">
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- ExtJS——在展开/折叠时调整面板高度
- 分析高度属性时出现意外值{{specs.height}}.index.html
- 单击页面上的链接后高度发生变化
- 不加载宽度和高度的角度pintura
- 查找元素高度,包括边距
- 如何自动调整标签的高度以适应内容
- Javascript高度问题
- 使用JavaScript根据窗口/视口的高度动态调整图像大小
- 如何计算每个元素's的高度,并将这些值用作函数中的变量
- 如果宽度是百分比,如何设置以px为单位的图像高度
- 通过jquery设置最小高度
- 文档就绪提供了错误的选择器高度
- 调整缩放窗口高度提升缩放
- 根据图像高度添加类
- 检测非移动页面上的移动设备屏幕宽度和高度
- 更改代码镜像中TextArea的高度和宽度
- 获取iframe内容的宽度-高度
- 在android中显示固定高度的webview内的大型内容
- 使用javascript设置iframe的高度