作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我希望我的注册和后退按钮(都是输入类型:提交)位于中心。问题是即使我使用 margin: auto 也无法正常工作。请注意我已经为此输入设置了宽度。
* {
margin: 0;
padding: 0;
}
body {
font-size: 14px;
background-image: url("StockSnap_FS24L3X9BH.jpg");
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
.container {
width: 50%;
margin: 10px auto;
display: block;
}
.row {
width: 80%;
margin: 10px auto;
padding: 20px;
}
input:not([type=submit]):not([name=age]) {
width: 50%;
clear: left;
}
label {
display: inline-block;
width: 150px;
float: left;
text-align: left;
}
input[type=submit] {
width: 100px;
margin: 0 auto;
}
input[name=age] {
width: 60px;
}
#gender {
width: 100px;
}
<?php
include_once("code2_registration.php");
?>
<div class="container">
<h1 style="text-align: center"> Membership Forum </h1>
<div class="row">
<form action="register.php" method="POST">
<p> Please fill the following form to complete the registration. </p> <br/>
<label>Username:</label> <input type="text" name="username" /> <br/><br/>
<label>Password:</label> <input type="password" name="password" /> <br/><br/>
<label>First Name:</label> <input type="text" name="firstName" /> <br/><br/>
<label>Last Name:</label> <input type="text" name="lastName"> <br/><br/>
<label>Email Address:</label> <input type="text" name="email"> <br/><br/>
<label>Sex: </label><select name="gender" id="gender">
<option value="male"> Male </option>
<option value="female"> Female </option>
<option value="others"> Others </option>
<option value="others"> Prefer not to say </option>
</select> <br/><br/>
<label>Age:</label> <input type="number" name="age"> <br/><br/>
<input type="submit" name="submit" value="Sign Up" id="submit">
<input type="submit" name="back" value="Back" id="back">
</form>
</div>
</div>
最佳答案
使用这个
<div class="container">
<h1 style="text-align: center"> Membership Forum </h1>
<div class="row">
<form action="register.php" method="POST">
<p> Please fill the following form to complete the registration. </p> <br/>
<label>Username:</label> <input type="text" name="username" /> <br/><br/>
<label>Password:</label> <input type="password" name="password" /> <br/><br/>
<label>First Name:</label> <input type="text" name="firstName" /> <br/><br/>
<label>Last Name:</label> <input type="text" name="lastName"> <br/><br/>
<label>Email Address:</label> <input type="text" name="email"> <br/><br/>
<label>Sex: </label><select name="gender" id="gender">
<option value="male"> Male </option>
<option value="female"> Female </option>
<option value="others"> Others </option>
<option value="others"> Prefer not to say </option>
</select> <br/><br/>
<label>Age:</label> <input type="number" name="age"> <br/><br/>
<div class="center">
<input type="submit" name="submit" value="Sign Up" id="submit">
<input type="submit" name="back" value="Back" id="back">
</div>
</form>
</div>
</div>
.center {
text-align: center;
}
* {
margin: 0;
padding: 0;
}
body {
font-size: 14px;
background-image: url("StockSnap_FS24L3X9BH.jpg");
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
.container {
width:50%;
margin: 10px auto;
display: block;
}
.row {
width:80%;
margin: 10px auto;
padding: 20px;
}
input:not([type=submit]):not([name=age])
{
width: 50%;
clear:left;
}
label {
display: inline-block;
width: 150px;
float: left;
text-align: left;
}
input[type=submit] {
width: 100px;
margin: 0 auto;
}
input[name=age] {
width:60px;
}
#gender {
width:100px;
}
关于html - 如何将 2 个输入文本彼此靠近居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42436343/
我是一名优秀的程序员,十分优秀!