一、通常方法
html
<body>
账号等:<input type="text"name=""><br>
密 码:<input type="text" name="">
</body>
css
//文本框的样式
input{
width: 200px ;
height: 25px;
background-color: red ;
margin-bottom: 5px;
}
我们一般会想到通过使用 加空格的方式来对齐文本框,但是通过实践表明这样做无法得到严格左对齐的效果。
--效果--
二、给文字设置浮动,添加宽高
html
<body>
<span>账号等:</span><input type="text"name=""><br>
<span>密码:</span><input type="text"name="">
</body>
css
//文字设置左浮动,加宽高
span{
float: left;
width: 60px;
height: 25px;
}
//文本框的样式
input{
width: 200px ;
height: 25px;
background-color: red ;
margin-bottom: 5px;
}
--效果--