展开全部
让div左右居中可以使用百分比绝对定位,与外补丁负值的方法,负值的大小为其自身宽度高度除以二,样式如下:
<style type="text/css">
.main{
position:absolute;
top:50%;
left:50%;
width:200px;
height:100px;
margin-top:-50px;
margin-left:-100px;
border:1px solid red;
line-height:30px;
font-size:16px;
text-align:center;
}
</style>
<style type="text/css">
.main{
position:absolute;
top:50%;
left:50%;
width:200px;
height:100px;
margin-top:-50px;
margin-left:-100px;
border:1px solid red;
line-height:30px;
font-size:16px;
text-align:center;
}
</style>
展开全部
<div style="width:500px;margin:0 auto">这样即可左右局中</div>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<html>
<head>
<style>
.信春哥{
margin-left:auto;
margin-right:auto;
width:200px;
background-color:red;
height:100px;
}
</style>
</head>
<body>
<div class="信春哥"></div>
</body>
</html>
要注意
要想层居中
margin-left:auto;
margin-right:auto;
是生效关键
同时层必须设置
width
才能居中
<head>
<style>
.信春哥{
margin-left:auto;
margin-right:auto;
width:200px;
background-color:red;
height:100px;
}
</style>
</head>
<body>
<div class="信春哥"></div>
</body>
</html>
要注意
要想层居中
margin-left:auto;
margin-right:auto;
是生效关键
同时层必须设置
width
才能居中
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询