首页 > 其他 > 详细

用两种方法来实现一个背景色为红色,宽度为800px,高度为400px的<DIV>在浏览器中居中

时间:2015-11-04 21:18:45      阅读:394      评论:0      收藏:0      [点我收藏+]

第一种方法

<style>
div{
margin: 0 auto;
background-color: yellow;
width: 50em;
height: 25em;
text-align: center;
}
</style>
</head>
<body>
<div>
div居中
</div>
</body>

第二种方法

<style>
div{
position: absolute;
left: 50%;
margin-left: -25em;
background-color: yellow;
width: 50em;
height: 25em;
text-align: center;
}
</style>
</head>
<body>
<div>
div居中
</div>
</body>

 

用两种方法来实现一个背景色为红色,宽度为800px,高度为400px的<DIV>在浏览器中居中

原文:http://www.cnblogs.com/chenchuen/p/4937086.html

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