答案 0 :(得分:1)
您可以使用position: absolute;
:
<div class="container">
<img src="img/car.png" class="car car-1">
<img src="img/car.png" class="car car-2">
</div>
CSS:
.container {
position: relative;
background: url(img/parking.png) no-repeat top left / 100% auto;
width: ...; height: ...;
}
.car {
position: absolute;
}
.car-1 {
top: ...; left: ...;
}
.car-2 {
top: ...; left: ...;
}
答案 1 :(得分:1)
这是一个简单的基本示例,说明如何使用纯html和css:
.car-park {
width: 1200px;
height:439px;
background: url('https://i.stack.imgur.com/n2BwR.png') 0 0 no-repeat;
position: relative;
}
.car {
background: url('https://i.stack.imgur.com/rZYO1.png') 0 0 no-repeat;
width: 19px;
height:40px;
position: absolute;
}
.car-1 {
top: 50px;
left: 195px;
}
.car-2 {
top: 295px;
left: 295px;
}
&#13;
<div class="car-park">
<div class="car car-1"></div>
<div class="car car-2"></div>
</div>
&#13;
您还可以像这样控制汽车的尺寸:
.car {
background: url('https://i.stack.imgur.com/rZYO1.png') 0 0 no-repeat;
background-size: contain;
width: 19px;
height:40px;
}
.car-lg {
width: 22.8px;
height:48px;
}
.car-xl {
width: 28.8px;
height:60px;
}
.margin-bottom-10 {
margin-bottom: 10px;
}
&#13;
<div class="car margin-bottom-10"></div>
<div class="car car-lg margin-bottom-10"></div>
<div class="car car-xl margin-bottom-10"></div>
&#13;
这是将背景设置为100%宽度的方式:
body {
height: 100vh;
}
.car-park {
width: 100%;
height: calc(100% * 1020 / 439);
max-height: 439px;
background: url(https://i.stack.imgur.com/n2BwR.png) 0 0 no-repeat;
background-size: contain;
position: relative;
}
&#13;
<div class="car-park"></div>
&#13;