2017-10-01 1 views
0

Ich habe das folgende scss Ausschnitt. Wenn .child vorhanden ist, möchte ich die .container eine Farbe von yellow habe ich Code an anderer Stelle haben, die mit .child auf sie das Element entfernt fügt/entferntSCSS Stil Eltern nur, solange Kind anwesend ist

.container { 
    height: 100%; 
    color: red; 
    :global { 
    .child { 
     background-color: black; 
    } 
    .container .child { <=== This obviously doesn't work but 
          I need .container to be yellow only when child is present 
     color: yellow; 
    } 

    } 
} 

Wie gebe ich, dass in SCSS?

+2

Mögliches Duplikat von [Gibt es einen CSS-Elternselektor?] (Https://stackoverflow.com/questions/1014861/is-there-a-css-parent-selector) – Quentin

Antwort

2

Obwohl Sie SCSS verwenden, können wir immer noch nicht die Tatsache umgehen, dass There is currently no way to select the parent of an element in CSS. Fügen Sie in Ihrem Code, der das Element mit der child-Klasse hinzufügt oder hinzufügt, dem übergeordneten Element container eine zusätzliche Klasse hinzu, damit Sie sie farbig darstellen können.