浮动模型元素的位置排列
怎样将浮动模型的元素居中显示?
2017-01-16
浮动只针对html标签设置靠左靠右浮动样式,float浮动样式没有靠中(浮动居中)的样式。你如果想让两个div居中可以试试在这两个外面再套一个div对这个div运用层模型定位,再使用margin慢慢调整。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>浮动模型</title>
<style type="text/css">
div{
border:2px red solid;
width:200px;
height:400px;
float:left;
margin:8px 44px;
}
span{
border:2px blue solid;
width:600px;
height:420px;
position:absolute;
margin-left:320px;
text-align:center;
}
</style>
</head>
<body>
<span>
<div id="div1">栏目1</div>
<div id="div2">栏目2</div>
</span>
</body>
</html>
举报