2013-11-23 38 views
0

我需要爲中心加載背景圖像div如何在自舉響應頁面中爲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'); 

回答

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> 
+0

請記住,要使圖像可見,div將需要最小高度或內容填充區域。 –

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> 

這是另一種方法。希望能幫助到你!