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

编程知识 行业动态 更新时间:2024-06-13 00:22:28

目标效果:

问题出现:

问题代码:

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;
}




更多推荐

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

本文发布于:2023-04-02 14:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/8890dde80ff33326e9edbc9ae4fdad39.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:间距   换行   代码   标签   Html

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!