1、使用css float
我们对div设置一个float浮动属性即可解决不并排显示,只要你的并排p盒子总宽度小于或等于最外层盒子宽度即可实现多个p对象并排显示。
注意:①设置float属性;②并排总宽度小于外层宽度。
2、使用css display同行显示
我们加入display:inline即可解决实现同行并排显示div盒子对象。
对div标签设置div{ display:inline}样式,
使用css float的实例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
padding: 0;
margin: 0;
text-decoration: none;
}
.box{
width: 500px;
height: 220px;
border-radius: 10px;
background-color: rgb(247,249,250);
border: 1px solid transparent;
}
.box:hover{
border: 1px solid red;
}
.box1{
width: 220px;
height: 220px;
float: left;
}
.box2{
width: 280px;
height: 220px;
float: left;
padding-top: 10px;
}
.p1{
width: 200px;
height: 200px;
padding: 10px;
border-radius: 20px;
}
img{
vertical-align: middle;
}
a{
color: black;
line-height: 1.6;
}
a:hover{
color: red;
}
.p2{
width: 65px;
height: 20px;
font-size: 15px;
border: 1px solid orangered;
color: orangered;
text-align: center;
line-height: 20px;
border-radius: 5px;
margin-top: 10px;
}
.p3{
color: orangered;
font-size: 20px;
margin-top: 75px;
}
</style>
</head>
<body>
<div class="box">
<div class="box1"><img src="./1.jpg" alt="" class="p1"></div>
<div class="box2">
<img src="./2.png" alt=""><a href="#">usmile电动牙刷1号刷情侣男女成人声波全自动学生党礼物</a>
<div class="p2">
送运费险
</div>
<div class="p3">
<span>¥</span> 309
</div>
</div>
</div>
</body>
</html>
实验截图