2010-06-09 35 views
1

這應該是容易的,但它的證明很難...CSS/HTML爲中心的文本框

我的元素我想中心正是這種<input type="text">

我不希望文本爲中心,只是在文本框中在外部分區內。

這是我嘗試它不工作

<div class ="temp123"> 
    <input type="text" /> 
</div> 

其中:

.temp123 
{ 
margin: 0 auto; 
margin-left: auto; 
margin-right: auto; 
} 

文本框仍然在左邊。

外div有一個固定的300像素和本身使用margin: 0 auto;

回答

4
.temp123{ 
    text-align:center; 
} 
.temp123 > input{ 
    text-align:left; 
} 

或者乾脆中心(而不是測試):

.temp123 > input{ 
    margin: 0 auto; 
    margin-left: auto; 
    margin-right: auto; 
} 
+0

後者沒有工作,但你的第一個建議工作的一種享受! – Robert 2010-06-09 11:35:14

1

在你的CSS,你要選擇的div的保證金,div之外的空間。

你需要選擇它像.temp123 input {...}

希望有所幫助。

4

也許我沒有得到這個問題,但這個應該這樣做。

<style> 
.temp123 
{ 
margin: 0 auto; 
margin-left: auto; 
margin-right: auto; 
text-align:center; 
} 
</style> 
<div class ="temp123"> 
    <input type="text" /> 
</div>