响应形式的输入之间的距离

时间:2018-09-11 16:31:09

标签: html css forms

我需要一个像素完美的表格。我可以做吗?:
-小输入之间的距离恰好是5px?
-保持左右0的距离
-保持5px以上的距离
-保持表单的响应速度

如示例所示,我无法达到第一个条件。

form {
	position: relative;
	margin: 40px auto;
	text-align: center;
	width: 85%; max-width: 350px;
}	
input {
	display: block;
	width: 100%;
	box-sizing: border-box;
	padding: 7px 15px; margin-bottom: 5px;
	border-radius:5px 5px 5px 5px;
	-moz-border-radius:5px 5px 5px 5px;
	-webkit-border-radius:5px 5px 5px 5px;
	font-size: 14px;
	outline: none;
	color: #bbb;
	border: 0;
	background-color: whiteSmoke;
}	
#mes-any {
	display: inline-block;
	width: 49%;
	float: left;
}
#cvc {
	display: inline-block;
	width: 49%;
	float: right;
}
<form action='externs/select-insert.php' method='post'>
	<input type='text' id='card' name='card' value=''>
	<input type='text' id='mes-any'name='mes-any' value=''>
	<input type='text' id='cvc'name= 'cvc' value=''>
</form>

2 个答案:

答案 0 :(得分:1)

也许使用 calc()来获取宽度:

form {
	position: relative;
	margin: 40px auto;
	text-align: center;
	width: 85%; max-width: 350px;
}	
input {
	display: block;
	width: 100%;
	box-sizing: border-box;
	padding: 7px 15px; margin-bottom: 5px;
	border-radius:5px 5px 5px 5px;
	-moz-border-radius:5px 5px 5px 5px;
	-webkit-border-radius:5px 5px 5px 5px;
	font-size: 14px;
	outline: none;
	color: #bbb;
	border: 0;
	background-color: whiteSmoke;
}	
#mes-any {
	display: inline-block;
	width: calc(50% - 2.5px);
	float: left;
}
#cvc {
	display: inline-block;
	width: calc(50% - 2.5px);
	float: right;
}
<form action='externs/select-insert.php' method='post'>
	<input type='text' id='card' name='card' value=''>
	<input type='text' id='mes-any'name='mes-any' value=''>
	<input type='text' id='cvc'name= 'cvc' value=''>
</form>

答案 1 :(得分:1)

您可以使用CSS calc(50% - 2.5px)

form {
	position: relative;
	margin: 40px auto;
	text-align: center;
	width: 85%; max-width: 350px;
}	
input {
	display: block;
	width: 100%;
	box-sizing: border-box;
	padding: 7px 15px; margin-bottom: 5px;
	border-radius:5px 5px 5px 5px;
	-moz-border-radius:5px 5px 5px 5px;
	-webkit-border-radius:5px 5px 5px 5px;
	font-size: 14px;
	outline: none;
	color: #bbb;
	border: 0;
	background-color: whiteSmoke;
}	
#mes-any {
	display: inline-block;
	width: calc(50% - 2.5px);
	float: left;
}
#cvc {
	display: inline-block;
	width: calc(50% - 2.5px);
	float: right;
}
<form action='externs/select-insert.php' method='post'>
	<input type='text' id='card' name='card' value=''>
	<input type='text' id='mes-any'name='mes-any' value=''>
	<input type='text' id='cvc'name= 'cvc' value=''>
</form>