twitter-bootstrap 如何在引导响应式页面中为 div 加载背景图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20159300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 19:18:44 来源:igfitidea点击:
How to load a background image for a div in bootstrap responsive page
提问by Rama Priya
I need to load a background image for the center div.
我需要为 center 加载背景图像div。
HTML:
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:
CSS:
@import url('http://getbootstrap.com/dist/css/bootstrap.css');
回答by edlugz
Add backgroud:url('url-to-your-image');to the inline style of the div element
添加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>
回答by whereDragonsDwell
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style="background-image:url('paper.gif');">
<h1>Hello World!</h1>
</div>
</body>
</html>
That's one way of setting the background image.
这是设置背景图像的一种方式。
<!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>
That's another method. Hope it helps!
那是另一种方法。希望能帮助到你!

