【发布时间】:2015-10-10 23:13:06
【问题描述】:
我试图在表单中居中输入按钮,但通常的边距:0 auto;没有做任何事情。这是我的 HTML 的设置方式:
<body>
<div class="container">
<div class="contact-div">
<form id="contact-form">
<div class="input-field">
<input type="button" value="Submit" class="submit-button" />
</div>
</form>
</div>
</div>
</body>
和 CSS:
body {
padding:0;
margin:0;
width:100%;
font-family: Century Gothic,sans-serif;
}
.container {
width:100%;
}
#contact-div {
height:100vh;
width:100%;
background: url("images/contactpic3.jpg") no-repeat center fixed;
background-size: cover;
}
.input-field{
width:60%;
margin:0 auto;
}
.submit-button {
height:40px;
width:200px;
margin:auto;
border:2px black solid;
border-radius:10px;
font-size:1.5em;
text-align:center;
}
这也是一个有问题的 JSFiddle (https://jsfiddle.net/wge66p83/)。从我添加的红色背景颜色可以看出,提交按钮没有居中,只是粘在input-field 的左边缘。我怎样才能让这个输入在我的 div 中居中?
【问题讨论】: