2017-02-18 25 views
0

我有一個以頁面爲中心的表單,並且元素在窗體中居中。但是,我希望文本在我的表單中與輸入框的左邊緣對齊。換句話說,我希望文本的第一個字母從輸入框的左邊開始。請參見下面的代碼和圖像:如何修復文本到居中文本框css的左邊緣

<!DOCTYPE HTML> 
<html lang="en"> 
<head> 
<meta charset="UTF-8"> 
<title>Log In</title> 
</head> 
<style type="text/css"> 
#wrapper{ 
    border:1px solid black; 
    max-width:200px; 
    max-height:200px; 
    display-webkit-box; 
    margin-left:auto; 
    margin-right:auto; 
    padding:5px; 
    border-radius:5px; 
} 
#login input{ 
    display:-webkit-box; 
    margin-left:auto; 
    margin-right:auto; 
} 
#login span{ 

} 
</style> 
<body> 

<div id="wrapper"> 
<form id="login" action="#" method="POST"> 
<span>User Names:</span><br> 
<input type="text"><br> 
<span>Password:</span><br> 
<input type="password"><br> 
<input type="submit" value="Log In"> 
</form> 
</div> 

</body> 
</html> 

Image Here

+0

text.align:左.. – scaisEdge

+0

可能重複的[CSS:左,中心和右對齊同一行上的文本](http://stackoverflow.com/questions/13694062/css-left-center-right-align同上) –

回答

0

不理想,但它的工作原理。它將適用於此示例,因爲您的網站使用固定大小。

#login span{ 
    margin-left: 17px; 
    text-align: left; 
} 

如果它是一個敏感的網站,它不會工作就像this.μ

圖片:http://prntscr.com/eaewe0

+0

謝謝,這對我正在做的事情完美無缺。 –

+0

我很好奇,但是如果有另一種定位技術可以使用,但它並不是什麼大問題 –

+0

另一種方式是這樣的,它使您的輸入固定寬度,並將您的div更改爲: #login input { display:-webkit-box; margin-left:auto; margin-right:auto; width:160px; } #登錄{ margin-left:auto; margin-right:auto; width:160px; } –

0

<!DOCTYPE HTML> 
 
<html lang="en"> 
 
<head> 
 
<meta charset="UTF-8"> 
 
<title>Log In</title> 
 
</head> 
 
<style type="text/css"> 
 
#wrapper{ 
 
    font-family: sans-serif; 
 
    border:1px solid black; 
 
    max-width:200px; 
 
    margin-left:auto; 
 
    margin-right:auto; 
 
    padding:5px; 
 
    border-radius:5px; 
 
} 
 
#login input{ 
 
    display:-webkit-box; 
 
    margin-left:auto; 
 
    margin-right:auto; 
 
} 
 

 
    
 
</style> 
 
<body> 
 

 
<div id="wrapper"> 
 
<form id="login" action="#" method="POST"> 
 
    User Names:&nbsp;<input type="text"><br> 
 
    Password:&nbsp;<input type="password"><br> 
 
    <input type="submit" value="Log In"> 
 
</form> 
 
</div> 
 

 
</body> 
 
</html>