html - 响应式背景图片 bootstrap 3

标签 html css twitter-bootstrap background-image

我正在使用 bootstrap 并试图让我的背景图像响应,但它就是不工作!这是我的代码...

html

<div class="row">
    <div class="bg">
        <img src="../img/home_bg.jpg" alt="home background image">
    </div><!-- /.bg -->
</div><!-- /.row -->

CSS

.bg {
    background-repeat: no-repeat;
    background-position: center center;
    background-attachment: fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

请帮帮我!谢谢你!

最佳答案

您需要阅读更多有关背景图像和内嵌图像之间的区别的信息。您不能将 img 标签设置为背景样式,它是 block 级元素,并随文档流动。背景图像是元素的属性。由于您希望此图像作为整个页面的背景,因此可以将背景图像应用于 html 或 body 元素。

http://jsfiddle.net/8L9Ty/3/

body {
    background: url('http://placekitten.com/900/900');
    background-repeat: no-repeat;
    background-position: center center;
    background-attachment: fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

关于html - 响应式背景图片 bootstrap 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23784128/

相关文章:

html - 字符串替换后得到错误的项目计数

jquery - Fadein, Fadeout 事件一起使用 jquery

Jquery 函数只能在第一次单击时正常工作

css - 垂直滚动的白色 100% 框 CSS 问题

jquery - 如何在旋转木马中居中图像

php - Twitter 播放器卡上的动画 GIF 无法正常工作?

html - 显示 inline-block 影响行高 hover

css - animate.css bounceindown 在 Safari 中不起作用

javascript - 更改 'greyed-out-ness' 的 html Bootstrap 按钮和 javascript 的级别

html - Vue.js:在元素处于正确位置之前不显示元素