由于某些未知原因,当我将margin-left添加到.basic-info h1时,它也适用于.bottomContent中的h1。因此,bottomContent中的h1也会给出80px的余量。意思是当我做.bottomContent h1 {padding-left:80px}时,这在理论上应该是唯一应用的,但它不是,所以填充左边是bottomContent中的h1。将CSS margin-left应用于不正确的类标题
作为一个简单的解决方案,我可以删除bottomContent h1,并将CSS保留为.basic-info,但显然我做错了什么。
HTML
div class = "basic-info">
<div class ="image"> <img src = "logo.jpg" alt = "this is an image"> </div>
<div class = "inside-info">
<h1> Know better. Book better. Go better. </h1>
<p>See the latest reviews and compare the lowest hotel prices from 200+ hotel booking sites to help you make the most of your trip
See the latest reviews and compare the lowest hotel prices from 200+ hotel booking sites to help you make the most of your trip
See the latest reviews and compare the lowest hotel prices from 200+ hotel booking sites to help you make the most of your trip
See the latest reviews and compare the lowest hotel prices from 200+ hotel booking sites to help you make the most of your trip
See the latest reviews and compare the lowest hotel prices from 200+ hotel booking sites to help you make the most of your trip</p>
</div>
</div>
<div class = "bottomContent">
<h1> Top hotels: Recommendations </h1>
<div class ="number-one">
<img src = "smallimages.jpg" alt = "this is an image ">
<img src = "smallimages.jpg" alt = "this is an image ">
<img src = "smallimages.jpg" alt = "this is an image ">
</div>
</div>
CSS
.basic-info p,h1{
margin-left:80px;
width:50%;
}
.bottomContent h1{
margin-left:80px;
}