标签中的特定文本会干扰对齐

时间:2018-10-17 16:09:32

标签: html css user-interface alignment

我有一个登录页面,其中包含用户名和密码。 我面临一个非常奇怪的问题。 当我在第一个标签中将“用户名”作为标签文本时,文本位于输入上方,但是当我将“密码”作为第一个标签的文本时,通常会并排出现。

"Username" as text
"password" as text

“密码”为文本的代码

 <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>

请帮助!

2 个答案:

答案 0 :(得分:0)

请减小输入字段的大小,也许会有所帮助。

答案 1 :(得分:0)

就像@Nawed Khan所说,问题的根源来自于您的硬编码样式。 特别是,这条线会导致宽度随视口(浏览器窗口的大小)缩放,并且左边距div向侧面推500px,因此不会在其他浏览器或调整浏览器大小时。

<div class="main" style="width: 25%;margin-left: 500px;" align="center">

最简单的解决方法是增加宽度。

<div class="main" style="width: 500px;margin: 0 auto;" align="center">

暂时将其赋予硬值即可。

但这引入了针对不同屏幕的一套缩放警告,因此,如果您认真考虑使其适用于不同屏幕,请考虑研究自适应设计。

相关问题