如何在引导响应页面中加载div的背景图像

时间:2013-11-23 06:18:45

标签: twitter-bootstrap responsive-design

我需要为中心div加载背景图片。

HTML

<div class="container">
    <div class="row">
        <div class="col-lg-12">text
            <div class="row">
                <div class="col-md-8 col-md-offset-2 col-sm-8 col-sm-offset-2 col-xs-8 col-xs-offset-2" style="background:red;color:white">TEXT with background image</div>
            </div>
        </div>
    </div>
</div>

CSS

@import url('http://getbootstrap.com/dist/css/bootstrap.css');

2 个答案:

答案 0 :(得分:0)

backgroud:url('url-to-your-image');添加到div元素的内联样式

<div 
    class="col-md-8 col-md-offset-2 col-sm-8 col-sm-offset-2 col-xs-8 col-xs-offset-2"
    style="background:red;color:white; background:url('url-to-your-image')"
>TEXT with background image</div>

答案 1 :(得分:0)

<!DOCTYPE html>
<html>
<head>
</head>

<body>

<div style="background-image:url('paper.gif');">
<h1>Hello World!</h1>
</div>
</body>

</html>

这是设置背景图像的一种方法。

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#bgimg {
    background-image: url('paper.gif');
}
</style>
</head>

<body>

<div id="bgimg">
<h1>Hello World!</h1>
</div>
</body>

</html>

这是另一种方法。希望它有所帮助!