简体   繁体   English

调整背景图片的大小取决于屏幕

[英]Background image resize depends on screen

I have bootstrap carousel. 我有引导传送带。 One of the items only have a background image without a content. 其中一项仅具有背景图像而没有内容。 I put a height so it still can be seen without a content. 我放了一个高度,所以即使没有内容也可以看到它。 But when I try to view it on mobile, its not I cannot see the full image. 但是当我尝试在移动设备上查看时,不是,我看不到完整图像。 Just a portion of it. 只是一部分。 How can I make the image resize when the screen resize or in RWD view. 当屏幕调整大小或在RWD视图中时,如何调整图像大小。 I try to put position absolute on the specific item and make the parent div position relative but that item disappear when I put position absolute. 我尝试将绝对位置放在特定项目上,并使父div位置相对,但是当我将绝对位置放到该项目时,该项目就会消失。

Here's my code 这是我的代码

<div id="custom-banner-wrapper" style="position: relative;">
   <div id="custom-banner" class="carousel slide" data-ride="carousel">

     <div class="carousel-inner custom-banner-inner">

     <div id="custom-banner-fullwidth" class="item custom-banner-item active" 
     style='background-color: #2c1946;  background-image: url("./catalog/view/theme/broadwaytheme/images/banner-1.png");  background-repeat:no-repeat; background-position: top center; background-size: cover; position:absolute;'>
      <div class="container">
       <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 custom-banner-caption">

        </div>
      </div>
    </div>
  </div>
</div>
<ol class="carousel-indicators" style="bottom:0px;">
  <li data-target="#custom-banner" data-slide-to="0" class="active"></li>
  <li data-target="#custom-banner" data-slide-to="1"></li>
  <li data-target="#custom-banner" data-slide-to="2"></li>
</ol> </div></div>

You can put 你可以放
background-position:100% 100%; 背景位置:100%100%; max-height:100%; 最大高度:100%; max-width:100% 最大宽度:100%


Then your problem will solved 那你的问题就解决了

您可以使用css样式专有的backgound-size:100% 100%来拉伸div中的图像,也可以使用background-size:contain将图像包含在div中(不包括Stretchig,但不会覆盖整个div

you can use below patch. 您可以使用以下补丁。 in this solution you'll get the full cover of image and the center part of the image in your DIV. 在此解决方案中,您将在DIV中获得图像的完整封面和图像的中心部分。

.your_class { background-size: cover; background-position:center center;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM