css - 2 Bootstrap 网站不是背景图片没有响应

标签 css twitter-bootstrap background-image

<分区>


想改进这个问题吗? 通过 editing this post 添加细节并澄清问题.

关闭 7 年前

我创建了 2 个网站 - 如何让标题背景图片在移动设备上正确调整大小?在移动设备上查看时,图像两边都被截断了。

我在每个标题部分都有这段代码:

这是每个的代码:

segregatedsunday.com

    #h {
    background: url(../img/header.jpg) no-repeat center top;
    padding-top: 180px;
    text-align:center;
    background-attachment: relative;
    background-position: center center;
    min-height: 700px;
    width: 100%;
    color: white;

    -webkit-background-size: 100%;
    -moz-background-size: 100%;
    -o-background-size: 100%;
    background-size: 100%;

    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

whitehatdev.co

 #headerwrap {
    background: url(../img/header_bg.jpg) no-repeat center top;
    margin-top: -50px;
    padding-top:120px;
    text-align:center;
    background-attachment: relative;
    background-position: center center;
    min-height: 650px;
    width: 100%;

    -webkit-background-size: 100%;
    -moz-background-size: 100%;
    -o-background-size: 100%;
    background-size: 100%;

    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

最佳答案

我正在查看您的第一个示例,它通常看起来不错。额外的 100% 背景大小的东西不适合这种情况。当我将 jsfiddle 拖动得越来越大和越来越小时,图像会像“封面”一样动态调整大小。哞!

jsfiddle

 #headerwrap {
    background: url(http://www.glitters20.com/wp-content/uploads/2012/11/Funny-Cow-37.gif) no-repeat center top;
    margin-top: -50px;
    padding-top:120px;
    text-align:center;
    background-attachment: relative; 
    background-position: center center;
    min-height: 250px;
    width: 100%;

    /* -webkit-background-size: 100%;
    -moz-background-size: 100%;
    -o-background-size: 100%;
    background-size: 100%; */

    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

你不会混淆掩护和收容吧?目前尚不清楚您要实现的目标。 Cover 和 Contain 将保持纵横比,因此图像不会失真。

contain

The contain value specifies that regardless of the size of the containing box, the background image should be scaled so that each side is as large as possible while not exceeding the length of the corresponding side of the container.

cover

The cover value specifies that the background image should be sized so that it is as small as possible while ensuring that both dimensions are greater than or equal to the corresponding size of the container.

关于css - 2 Bootstrap 网站不是背景图片没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30960233/

上一篇:CSS 悬停覆盖在重叠到 div 上的箭头上

下一篇:css - 多个 CSS 媒体查询不起作用

相关文章:

html - 我无法将 div 置于图像的中心

c# - 在 Bootstrap 中对齐列。第一个瓷砖需要大

css - 将背景位置从屏幕向左推

javascript - JavaScript如何让进度条缓慢移动

html - 具有百分比宽度的 DIV 不起作用(无边框,无边距/填充)

html - 过渡在页面加载时无法正确显示

html - Bootstrap,无法将我的图像和文本并排放置在 3 组中

javascript - 按范围将指令插入到另一个指令中

html - 背景大小移动图像

:root 中的 CSS 背景图像渐变