css 利用 position + margin 实现固定盒子横向纵向居中的方法

css 利用 position + margin 实现固定盒子横向纵向居中的方法,第1张

css 利用 position + margin 实现固定盒子横向纵向居中的方法

margin:auto; + position: absolute; 上下左右:0
一看 demo 就懂的啦

<!DOCTYPE html>
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta charset="utf-8">
	<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
	<title>利用 position + margin 实现固定盒子横向纵向居中</title>
	<style>
		body * {
			outline: 1px #ff0000 solid;
		}

		.father {
			width: 500px;
			height: 300px;
			position: relative;
		}

		.father .son {
			width: 180px;
			height: 140px;
			/*  */
			position: absolute;
			right: 0;
			bottom: 0;
			top: 0;
			left: 0;
			margin: auto;
		}
	</style>
</head>

<body>
	<div class="father">
		<div class="son">margin:auto + 上下左右:0</div>
	</div>
</body>

</html>

//end

到此这篇关于css 利用 position + margin 实现固定盒子横向纵向居中的方法的文章就介绍到这了,更多相关css固定盒子横向纵向居中内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/615681.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-14
下一篇 2022-04-14

发表评论

登录后才能评论

评论列表(0条)

保存