html - 背景图像高度 100%

标签 html css twitter-bootstrap

我正在寻找我的问题的解决方案。

我正在为移动网站使用 Twitter Bootstrap ,这是我在移动 View 上的结果:

enter image description here

<div class="row">
    <div class="span4">
        <div class="visible-phone" style="background-image: url('http://upload.tapcrowd.com/upload/catalogimages/719/catalogimagecardealer@2x.png');></div>
        <p class="metadataTitle metacell">
        <span style="display: inline-block" class="ellipsis">Car Dealers</span>
        <span style="table-row"></span></p>
        </div>  
    </div>
</div>

我的图片所在的 div 的 css:

background-size:contain;
background-repeat: no-repeat;
background-position: center center;
width: 100%; 
height: 300px;"

但是正如您所看到的,图像和下面的内容之间存在空白,有人知道我该如何解决这个问题吗?

最佳答案

background-size:contain;

https://developer.mozilla.org/en-US/docs/Web/CSS/background-size :

"contain: This keyword specifies that the background image should be scaled to be as large as possible while ensuring both its dimensions are less than or equal to the corresponding dimensions of the background positioning area."

因此您的图像已缩放,因此它完全适合元素 - 您似乎想改用 cover:

"cover: This keyword specifies that the background image should be scaled to be as small as possible while ensuring both its dimensions are greater than or equal to the corresponding dimensions of the background positioning area."

关于html - 背景图像高度 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16852677/

相关文章:

javascript - 无法动态地将 div 内容复制到 dojo contentpane 中

html - www 子域在 Google Chrome 上看起来与主域不同

javascript - 在 jquery 中删除多个选定的行

css - 如何在伪元素中显示缩放的 svg?

html - 如何在 bootstrap 中放置一个容器(两行)和两个容器(在不同的两行)?

html - 优化和压缩 HTML

html - 跨浏览器使用 CSS 样式化链接按钮

html - 填充 HTML 表格列,两个边框?

html - Bootstrap垂直对齐

css - 基于 variables.less 变量值覆盖 bootstrap css