【发布时间】:2018-10-17 16:09:31
【问题描述】:
我有一个需要用户名和密码的登录页面。 我面临一个非常奇怪的问题。 当我将“用户名”作为标签文本放在第一个标签中时,文本位于输入上方,但是当我将“密码”作为第一个标签的文本时,它通常是并排出现的。
“密码”文本代码
<div class="main" style="width: 25%;margin-left: 500px;" align="center">
<div style = "background-color:blue; color:#FFFFFF; padding:3px; "><b>Login</b></div>
<div style = "margin:30px; color: black" class='inv'>
<form action = "" method = "post">
<br/>
<label>Password :</label><input type = "text" id="username" name = "username" class = "box" value="" required/><br /><br />
<label>Password :</label><input type = "password" name = "password" id="password" class = "box" value="" required /><br/><br />
<input type = "submit" value = " Submit " class=".btn-primary" /><br />
</form>
<div style = "font-size:11px; color:#cc0000; margin-top:10px"><?php error_reporting(0);echo $error; ?></div>
</div>
</div>
</div>
“用户名”作为文本的代码
<div class="main" style="width: 25%;margin-left: 500px;" align="center">
<div style = "background-color:blue; color:#FFFFFF; padding:3px; "><b>Login</b></div>
<div style = "margin:30px; color: black" class='inv'>
<form action = "" method = "post">
<br/>
<label>username: :</label><input type = "text" id="username" name = "username" class = "box" value="" required/><br /><br />
<label>Password :</label><input type = "password" name = "password" id="password" class = "box" value="" required /><br/><br />
<input type = "submit" value = " Submit " class=".btn-primary" /><br />
</form>
<div style = "font-size:11px; color:#cc0000; margin-top:10px"><?php error_reporting(0);echo $error; ?></div>
</div>
</div>
请帮忙!!
【问题讨论】:
-
即使“用户名”和“密码”中的字符数相同,但两者的实际宽度却不同。 “用户名”略宽于“密码”。您正在尝试通过使用硬编码的宽度和对齐来适应这一点,这在其他屏幕上无论如何都不起作用。立即修复/解决方法是将父 div 的宽度增加到 26% 或将边距从 30px 减少到 25px。但这仍然看起来不太好,并且可能不适用于其他窗口大小。
标签: html css user-interface alignment