Html代码中的标签换行造成间距问题

目标效果:

问题出现:

问题代码:

Html代码:

<div id="hall_div_operation">
	<div class="hall_operation">
		<div class="label_input">
			<label for="customroomid">自定义房间号:</label>
			<input type="text" id="customroomid" class="form-control" style="width: 194px;"/>
		</div>
		<a id="EnterRoomBtn" class="btn btn-info">进入</a>
	</div>
</div>


CSS代码:

#hall_div_operation{
	clear: both;
	width: 389px;
	height: 60px;
	margin-top: 10px;
}

.hall_operation .label_input{
	float: left;
	font-size: 14px;
	padding-left: 10px;
}

.hall_operation .btn{
	width: 70px;
	float: left;
	margin-left: 10px;
}

#EnterRoomBtn{
	background: #f7f8f8;
	color: #1c90f6;
	border: 1px solid #1c90f6;
	box-shadow: 0px 0px 2px #1c90f6;
}

问题分析:连续几个内联标签或表单元素的换行在浏览器会被解释为一个空格。

解决方法:

方法一:不换行

<div id="hall_div_operation">
	<div class="hall_operation">
		<div class="label_input">
			<label for="customroomid">自定义房间号:</label><input type="text" id="customroomid" class="form-control" style="width: 194px;"/>
		 </div>
		 <a id="EnterRoomBtn" class="btn btn-info">进入</a>
	</div>
</div>


方法二:设置父级块的字体大小为0

若其中还有字体需要显示的话,需要用<span>标签去包裹它,然后再设置字体大小。

Html代码:

<div id="hall_div_operation">
	<div class="hall_operation">
		<div class="label_input">
			<label for="customroomid"><span class="span_font">自定义房间号:<span></label>
			<input type="text" id="customroomid" class="form-control" style="width: 194px;"/>
		</div>
		<a id="EnterRoomBtn" class="btn btn-info">进入</a>
	</div>
</div>

CSS代码:

#hall_div_operation{
	clear: both;
	width: 389px;
	height: 60px;
	margin-top: 10px;
}

.hall_operation .label_input{
	float: left;
	padding-left: 10px;
	font-size: 0;
}

.hall_operation .label_input .span_font{
	font-size: 14px;
}

.hall_operation .btn{
	width: 70px;
	float: left;
	margin-left: 10px;
}

#EnterRoomBtn{
	background: #f7f8f8;
	color: #1c90f6;
	border: 1px solid #1c90f6;
	box-shadow: 0px 0px 2px #1c90f6;
}


方法三:设置 margin-left 为-3px

Html代码:

<div id="hall_div_operation">
	<div class="hall_operation">
		<div class="label_input">
			<label for="customroomid">自定义房间号:</label>
			<input type="text" id="customroomid" class="form-control" style="width: 194px;"/>
		</div>
		<a id="EnterRoomBtn" class="btn btn-info">进入</a>
	</div>
</div>

CSS代码:

#hall_div_operation{
	clear: both;
	width: 389px;
	height: 60px;
	margin-top: 10px;
}

.hall_operation .label_input{
	float: left;
	padding-left: 10px;
	font-size: 14px;
}

.hall_operation .label_input input{
	margin-left: -3px;
}

.hall_operation .btn{
	width: 70px;
	float: left;
	margin-left: 10px;
}

#EnterRoomBtn{
	background: #f7f8f8;
	color: #1c90f6;
	border: 1px solid #1c90f6;
	box-shadow: 0px 0px 2px #1c90f6;
}




  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值