2012-11-28 15 views

Antwort

69

Das ist LESS, nicht CSS.

Mit dieser Syntax können Sie Modifikatoren für den Nestnotenselektor definieren.

.clearfix { 
    &:before { 
    content: ''; 
    } 
} 

Will kompilieren:

.clearfix:before { 
    content: ''; 
} 

Mit dem &, die verschachtelten Selektoren .clearfix:before kompilieren.
Ohne es kompilieren sie zu .clearfix :before.

+0

Ich frage mich nur - wie sind Sie sicher, dass es nicht SASS/SCSS ist? – KatieK

+8

@KatieK: Bootstrap ist in weniger geschrieben, nicht SASS – SLaks

7

Ein verschachteltes & wählt das übergeordnete Element sowohl in SASS als auch in LESS aus. Es ist nicht nur für Pseudo-Elemente, es kann mit jeder Art von Selektor verwendet werden.

z.B.

h1 { 
    &.class { 

    } 
} 

entspricht:

h1.class { 

} 
+0

Ja @anthonygore, stimme ich Ihnen zu. –

1
In SCSS & LESS 

a { 
    text-decoration: underline; 
    @include padding(15px); 
    display: inline-block; 

    & img { 
       padding-left: 7px; 
       margin-top: -4px; 
      } 
} 


is Equal to in CSS : 

a { 
    text-decoration: underline; 
    @include padding(15px); 
    display: inline-block; 
} 

a img { 
    padding-left: 7px; 
    margin-top: -4px; 
    }