如题:如果三个块元素该怎么并列一行?还有块元素如何居中?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
father{
width: 500px;
height: 500px;
background: #000;
}
.son1{
height: 100px;
background: green;
}
.son2{
width:250px;
height: 200px;
background: yellow;
margin-left:auto;
margin-right:auto;
}
.son3{
height: 100px;
background: red;
}
.son2 h1{text-align:center;
line-height:200px;
margin:0;
}
</style>
</head>
<body>
<div class="father">
<div class="son1"></div>
<div class="son2">
<h1>我要居中</h1>
</div>
<div class="son3"></div>
</div>
</body>
</html>
div{
width:100px;
height:100px;
border:2px red solid;
margin:120px;
}
#div1{float:left;}
#div2{float:left;}
#div3{float:right;}
有个笨方法
如下代码可以实现三个 div 元素一行显示。 div{ width:200px; height:200px; border:2px red solid; float:left;} <div id="div1"></div> <div id="div2"></div> <div id="div3"></div>