2012-11-28 42 views
0

我有一個HTML結構如下:選擇元件在家長少用CSS

<div class="container"> 
    <label>Name:</label> 
    <div class="controls"> 
    <input type="text" class="formatted-input"></input> 
    </div> 
</div> 

我只能訪問到「格式輸入」級。我需要一種方式,從這個班級到最外面的父母的標籤,並將格式應用到它。這可能使用LESS CSS嗎?

我想出這樣的事情:

.container .formatted-input 
{ 
    & & > label { 
    color: yellow; 
    } 
} 

,但它不工作。有什麼建議麼?

謝謝!

+1

爲什麼爲什麼爲什麼爲什麼?看看這裏:http://stackoverflow.com/questions/1014861/is-there-a-css-parent-selector – thatidiotguy

+0

LESS只編譯爲正常的,有效的,標準的CSS - 所以如果它不能在CSS中完成它可以不能用LESS來完成(並且當前不能用CSS完成「父/上一級兄弟選擇器」)。 –

回答

0

LESS僅僅是一個帶有語法糖釉的CSS。

看起來你只是想獲得以下選擇:

  • .container label
  • .container .formatted-input

如果你希望它們聚集在一起,那麼你需要組織周圍的共性,在這種情況下爲.container

.container { 
    label {...} 
    .formatted-input {...} 
}