css - 图像不适合 Bootstrap 轮播

标签 css twitter-bootstrap image carousel responsive

我几乎完成了一个网站的创建,但我正在为轮播而苦苦挣扎。

我试图让它响应多种设备宽度,但超过 1200 像素时,轮播中的图像无法填满整个宽度。当我删除媒体查询时它工作正常,所以我假设这里发生了一些事情。

我认为一旦媒体查询被忽略,浏览器应该使用不在媒体查询 block 内的 CSS,我的想法是否正确?

标准 CSS

.carousel-indicators li{
    border-radius: 12px;
    width: 14px;
    height: 14px;
}
.carousel-inner{
    width: auto;
    height: 1000px;
}
.carousel-inner img{
    width: 100%;
    height: 100%;
}
}

@media (max-width: 575.98px) {
.carousel-inner{
    width: 100%;
    height: 450px;
}
.carousel-inner img{
    width: auto;
    height: 450px;
    padding-top: 80px;
    transform: translateX(-5rem);
}
}

@media (min-width: 576px) {
.carousel-inner{
    width: 100%;
    height: 450px;
}
.carousel-inner img{
    width: auto;
    height: 450px;
    padding-top: 80px;
    transform: translateX(-5rem);
}
}

@media (min-width: 768px) {
.carousel-inner{
    width: 100%;
    height: 450px;
}
.carousel-inner img{
    width: auto;
    height: 450px;
    padding-top: 80px;
    transform: translateX(-5rem);
}
}
@media (min-width: 992px) {
.carousel-inner{
    width: 100%;
    height: 600px;
}
.carousel-inner img{
    width: auto;
    height: 600px;
    padding-top: 80px;
}
}
@media (min-width: 1200px) {
.carousel-inner{
    width: 100%;
    height: 600px;
}
.carousel-inner img{
    width: auto;
    height: 600px;
    padding-top: 80px;
}
}


<!-- Image SLider & Indicators -->
 <div id="slides" class="carousel slide" data-ride="carousel">
    <ul class="carousel-indicators">
      <li data-target="#slides" data-slide-to="0" class="active"></li>
      <li data-target="#slides" data-slide-to="1"></li>
      <li data-target="#slides" data-slide-to="2"></li>
    </ul>
  <div class="carousel-inner" id="home">
    <div class="carousel-item active">
      <img src="img/warm.jpg">
    </div>
     <div class="carousel-item">
      <img src="img/landscape2.jpg">
    </div>
     <div class="carousel-item">
      <img src="img/river.jpeg">
    </div>
    <div class="carousel-caption">
      <h1 class="display-2">ALIAS PHOTOGRAPHY</h1>
        <h3>My Journey Through Nature...</h3>
        <div class="showcase-buttons">
        <!-- <button type="button" class="btn btn-outline-light btn-lg mr-1">VIEW DEMO</button> -->
        <a href="#gallery"><button type="button" class="btn btn-primary btn-lg">VIEW GALLERY</button></a>
        </div>
      </div>
  </div> 

最佳答案

这不是媒体查询问题,这是因为您将图像高度设置为 600 像素。这限制了它们与高度成比例。如果您想使用全宽图像,您应该尝试使用带有背景图像的 div。

关于css - 图像不适合 Bootstrap 轮播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50142820/

相关文章:

html - 将文本左右定位到单选框

html - 在 Cordova/Ionic 中放大特定的 div

jquery - 是否可以在溢出 div 顶部打开 Bootstrap 下拉菜单?

javascript - 为什么这个 Javascript 图像对象没有添加到图像数组中?

python - 使用opencv,如何去除透明图像中的非对象?

javascript - 在白色背景 div 下推送页脚

html - 在 CSS 中应用过滤器/掩码?

html - 如何使用bootstrap 2.0的响应式特性

html - Bootstrap - 重复图案覆盖背景颜色超大屏幕

android - 如何将 NV21 YUV 转换为 RGB 并返回