2012-08-05 78 views
1

這應該是微不足道的一個div內容,但考慮到粒度與我的造型我的標記,我無法獲得在中心試圖對齊在中央

標記的內容基本上是:

<div class = "rectangle" id = "login"> 
    <form> 
    <!-- bunch of labels and corresponding input fields --> 
    </form> 
</div> 

樣式表基本上是:

.rectangle{ border:1px solid #ccc; width:500px; padding: 10px;} 
#login{margin:auto;} 
#login form {margin:auto;} 

這遺憾的是不中心對齊的內容我的形式。它們更接近於包含父元素(div類矩形)的左側。我在這裏做錯了什麼?

+0

你想要將所有輸入集中在表單中嗎? – atlavis 2012-08-05 20:47:14

回答

5

試試這個

CSS

.rectangle{ 
    border:1px solid #ccc; 
    width:500px; 
    padding: 10px; 
    text-align:center; 
} 

HTML

<div class = "rectangle" id = "login"> 
    <form> 
     <input type="text" name="txt1" /> 
     <input type="text" name="txt2" />   
    </form> 
</div>​ 

DEMO