bootstrap 右浮动_Bootstrap的Float浮动属性

这篇博客介绍了如何在Bootstrap中实现响应式浮动和清除浮动。内容包括使用float响应式样式在不同设备断点上切换浮动效果,以及通过clearfix类来清除容器内的浮动内容,确保元素正确换行显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

98e9fdb50aa568e73f09e5f37d5f7bda.png

使用我们的响应式float浮动通用样式,能在任何设备断点(浏览器尺寸)上切换浮动。

class描述
.float-left左浮动
.float-right右浮动
.float-none不浮动
<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
		integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
	<title></title>
	<style>
		.f div div,.pos div {
			width: 5rem;
			height: 5rem;
			background: #ccc;
		}
		.pos div{
			background: wheat;
			border: 1px solid #000;
		}
		body{
			height: 5000px;
		}
	</style>
</head>

<body>
	<div class="container">
		<!-- 浮动 -->
		<div class="row border f">
			<div class="col">
				<!-- 3.x的版本里的浮动是.pull-left/.pull-right -->
				<div class="float-left">左浮动</div>
				<div class="float-right">右浮动</div>
				<div class="float-left float-none">不浮动</div>
			</div>
		</div>
	</div>
</body>

</html>

fb71d9995abef63109487a11f3c3975e.png

响应式的浮动,float-{breakpoint}-*:

class
.float-sm-left / right / none
.float-md-left / right / none
.float-lg-left / right / none
.float-xl-left / right / none

清除浮动 clearfix

通过添加.clearfix实用程序,快速轻松地清除容器内浮动的内容(使元素换行呈现)。

float类样式是通过添加.clearfix到父元素上来达达到清除目标。

<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
		integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
	<title></title>
	<style>
		.f div div,.pos div {
			width: 5rem;
			height: 5rem;
			background: #ccc;
		}
		.pos div{
			background: wheat;
			border: 1px solid #000;
		}
		body{
			height: 5000px;
		}
	</style>
</head>

<body>
	<div class="container">
		<!-- 清除浮动,clearfix -->
		<div class="row d-block border mt-1 clearfix">
			<div class="float-left" style="width: 100px;height: 100px;background: #ccc;">左浮动</div>
			<div class="float-right" style="width: 100px;height: 100px;background: #ccc;">右浮动</div>
		</div>
	</div>
</body>

</html>

没有清除浮动之前

60362cd53910eb32fb15c8fb8df9dab1.png

清除浮动之后

0f598da3bdfdc4d8ab24b6586a623066.png
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值