2015-01-14 123 views
0

我有一個div的3個div,我想中心的底部。我試過了在網上找到的每一個提示(你可以在我的代碼中看到...),但沒有任何效果。 這應該相當容易,但它不會居中。居中一個div div,html

.container { 
position: relative; 
width: 968px; 
margin: 0 auto; 
text-align: center; 
} 

.text  { 
position: absolute; 
width: 968px; 
height: 100px;"> 
}  

.bg_image  { 
position: absolute; 
width: 968px; 
height: 545px; 
top: 150px; 
background-image: url(x.jpg); 
} 

.bg_image2  { 
position: absolute; 
display: block; 
width: 50%; 
margin: 0 auto; 
height: 200px; 
top: 545px; 
background-image: url(x.png); 
background-repeat: no-repeat; 
} 
+0

這個問題一天約3次。嘗試使用搜索功能。 – Mardzis

+0

一遍又一遍。 [在div中水平居中div](http://stackoverflow.com/questions/114543/horizo​​ntally-center-a-div-in-a-div) – Mardzis

+0

歡迎來到SO!文本中存在拼寫錯誤(雙引號)。另外,請提供一個給我們一個基礎的原型(jsfiddle.net或codepen.io)。請相應地編輯您的問題。 – pixeline

回答

0

首先在你的CSS代碼有一個在的.text錯誤高度後,刪除此「>:100像素; 其次,我們不能回答這個問題,如果你不添加HTML代碼

+0

我知道你還不能評論,但這不是一個答案。你可能想考慮刪除它。 –

0

我。希望這個例子的代碼可以幫助你..

<!DOCTYPE html> 
    <html > 
    <head> 
    <style type="text/css"> 
    #outer{ position:fixed; top:0; left:0; width:100%; height:100%; } 
    #inner1{ width: 50%; height: 20%; top: 25%; margin: 0 auto; position: relative; background:orange; } 
    #inner2{ width: 50%; height: 40%; top: 25%; margin: 0 auto; position: relative; background:red; } 
    </style> 
    </head> 
     <body> 
     <div id=outer> 
      <div id=inner1> </div> 
      <div id=inner2> </div> 
     </div> 
     </body> 
</html> 
0

給一個fixed width如(寬度:100像素)。和margin:0 auto;要在中心,使兩者股利

這將爲你工作。

.centerDiv{ 
width:100px; /*as per your choice but width should be fixed.*/ 
height:100px; /*as per your choice even you can add auto*/ 
margin:0 auto; /*this is important to make div in center.*/ 
}