css 利用 position + margin 实现固定盒子横向纵向居中的方法
发布时间:2020-12-23 14:32:25 作者:352328759
我要评论
这篇文章主要介绍了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固定盒子横向纵向居中内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!
相关文章

CSS 同级元素position:fixed和margin-top共同使用的问题
这篇文章主要介绍了CSS 同级元素position:fixed和margin-top共同使用的问题的相关资料,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-09-13
这篇文章主要介绍了使用CSS实现盒子水平垂直居中的方法(8种),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来2020-11-11
这篇文章主要介绍了CSS盒子居中的常用的几种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学2020-03-31




最新评论