【问题标题】:Banner Image not responsive on mobile devices横幅图像在移动设备上无响应
【发布时间】:2019-12-02 13:17:11
【问题描述】:

我有带有折叠/打开选项的垂直侧菜单栏。当我们关闭侧边栏时,滑块图像会相应地调整大小并占据屏幕的整个宽度。它在桌面上运行良好。

但在移动设备上,未显示完整的横幅图像。显示了图像的某些部分。我想调整图像大小并显示完整图像而不是它的一部分。

我已尝试使用 width 属性、background-size 选项,其值为覆盖/包含。但不工作。使用包含值,可以在移动设备上看到完整的图像,但图像上方和下方有巨大的空白区域(大约 100 像素)。

以下是 html 和 css 代码。

HTML 代码:

 <!-- Banner -->
        <section class="main-banner">
          <div class="container-fluid">
            <div class="row">
              <div class="col-md-12">
                <div class="banner-content">
                  <div class="row">
                    <div class="col-md-12">
                      <div class="banner-caption">
                        <h4>Hello, this is your <em>Website</em> Theme.</h4>
                        <span>AWESOME HTML5 &amp; CSS3 TEMPLATE</span>
                        <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
                        <div class="primary-button">
                          <a href="#">Read More</a>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </section>

CSS如下:

/* Banner */

.main-banner .container-fluid {
    padding-left: 0px;
    padding-right: 0px;
    width:100%;
}
.main-banner .banner-content {
    background-image: url(../images/main-banner.jpg);   
    background-repeat:no-repeat;
    background-size:cover;
    background-position:center center;
}

.main-banner .banner-content .banner-caption {
    max-width: 450px;
    background-color: rgba(250,250,250,0.0);
    margin: 50px;
    padding: 50px;
}

.main-banner .banner-content .banner-caption h4 {
    font-size: 38px;
    font-weight: 700;
    color: #31323a;
    letter-spacing: 0.25px;
    margin: 0px;
    opacity:0;
}

.main-banner .banner-content .banner-caption em {
    font-style: normal;
    color: #DB214C;
    opacity:0;
}

.main-banner .banner-content .banner-caption span {
    font-size: 15px;
    color: #aaaaaa;
    letter-spacing: 0.5px;
    display: inline-block;
    margin-top: 20px;
    margin-bottom: 20px;
    opacity:0;
}

.main-banner .banner-content .banner-caption p {
    margin-bottom: 30px;
    opacity:0;
}

我不需要banner-caption,所以可以去掉....

感谢您的宝贵帮助。

示例JSFIDDLE

在这里您可以通过调整预览窗格的大小来查看图像

【问题讨论】:

  • 尝试在 JSfiddle 上创建一个演示,以便复制您的问题。
  • 您是否尝试使用media quires进行设置
  • @Awais 是的,我试过 background-size:contain;使用媒体查询而不是背景大小:封面;但没有解决问题。
  • 您能否为您的代码创建一个sn-p
  • 我不太明白你的问题。如果您希望背景具有 100%,它将导致:1. 当高度也是 100% 时拉伸或 2. 当高度为自动时,图像下方和上方的空白

标签: html css banner


【解决方案1】:

你试过了吗

@media(max-width:768px){
    .main-banner .banner-content {
    background-image: url(../images/main-banner.jpg);   
    background-repeat:no-repeat;
    background-size:100% 100%;
    background-position:center center;
    }
}

这可能是工作

【讨论】:

  • 它适用于背景大小:100% 50%;但是图像下方有巨大的空白区域......大约100px
  • @DrJManish 背景大小:100% 50%;表示背景的宽度设置为元素的 100%,高度设置为元素的 50%,因此其他 50% 的高度将是透明的。
  • @RickyStefano 是的,你是对的......但背景大小:100% 100%;图像被垂直拉伸..我们如何解决它?
  • 你必须改变图像大小或降低高度值我不知道任何其他方法来获得封面图像质量也许你可以使用 srcset
猜你喜欢
  • 2020-04-30
  • 2015-12-13
  • 1970-01-01
  • 2014-04-24
  • 2023-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-22
相关资源
最近更新 更多