首页 > 其他 > 详细

写一个200宽高的div,上下左右居中

时间:2021-04-27 20:13:45      阅读:18      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
html,
body {
height: 100%;
}

 

body {
width: 100%;
position: relative;
}

 

div {
width: 200px;
height: 200px;
background-color: #f00;

 

position: absolute;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
}
</style>
</head>
<body>
<div>

 

</div>
</body>
</html>
 
效果:上下左右都居中
技术分享图片

 

 

 

写一个200宽高的div,上下左右居中

原文:https://www.cnblogs.com/Friday1/p/14709353.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!