2017-06-14 32 views
1

由于某些未知原因,当我将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; 

    } 

回答

2

margin-left: 80px被应用到.basic-info ph1,因为你在那里有一个逗号。你需要做这样的事情,它的工作...

.basic-info p, .basic-info h1 { 
    margin-left:80px; 
    width:50%; 
} 
0

我觉得你想给保证金左.inside-H1的信息不.bottomContent H1 ,这样你们可以给CSS如.. .basic-info .inside-info h1{ margin-left:80px; }

这不适用于bottomContent中的h1。