enter image description here我正在尝试将一堆输入字段及其各自的标签对齐到 html 页面的中心。请查看我附上的两张图片。第一个显示了我的目标,第二个显示了我已经取得的成就。我的 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>
关于html - 将 html 输入字段及其标签与页面中心对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59481409/