第一种:使用浮动 float
<style>
.box{
width: 600px;
height: 600px;
border: 1px solid black;
}
.box1{
width: 300px;
height: 300px;
background-color: red;
float: left;
margin-top: 150px;
}
.box2{
width: 300px;
height: 300px;
background-color: yellow;
float: right;
margin-top: 150px;
}
</style>
第二种 使用定位position
<style>
.box{
width: 600px;
height: 600px;
border: 1px solid black;
position: relative;
}
.box1{
width: 300px;
height: 300px;
background-color: red;
position: absolute;
left: 0;
top: 125px;
}
.box2{
width: 300px;
height: 300px;
background-color: yellow;
position: absolute;
right: 0;
top: 125px;
}
</style>
</head>
<body>
<div class="box">
<div class="box1"></div>
<div class="box2"></div>
</div>
</body>