enter image description here我正在尝试将一堆输入字段及其各自的标签对齐到html页面的中心。请查看我所附的2张图片。第一个显示我要实现的目标,第二个显示我已经取得的成就。我的html代码很好,但是我无法找出CSS代码来实现这一目标。以下是使我接近目标的CSS代码(图1)。我需要帮助的部分是与表单标签和表单输入方面有关的CSS代码。
body{
background-color: white;
}
#container{
background-color: lightblue;
width: 60%;
height: 700px;
margin-left: auto;
margin-right: auto;
margin-top:50px;
text-align: center;
padding-top: 1px;
}
#form{
background-color: whitesmoke;
width: 90%;
heigth:auto;
text-align: center;
margin-left:auto;
margin-right:auto;
margin-top:10px;
}
#form label{
font-family:sans-serif;
font-size: 12px;
display: inline-block;
text-align:justify-all;
}
#form input{
display: inline-block;
text-align: justify;
}
如果需要在中心对齐输入字段,最简单的方法是使用margin : 0 auto;
CSS属性。请在下面的代码参考中找到:
div.container {
width: 300px;
height:300px;
border:1px solid black;
background: lightblue
}
input[type="text"] {
display: block;
margin : 0 auto;
}
<html>
<head>
</head>
<body>
<div class='container'>
<input type='text' name='sample' value='sample'>
</div>
</body>
</html>