Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS sibling selector on class names?

Tags:

dom

css

siblings

<div class="parent">
  <div class="firstChild"></div>
  <div class="secondChild"></div>
  <div class="thirdChild"></div>
  <div class="fourthChild"></div>
<div>

I am trying to style fourthChildbased on if secondChild exists under parent

I thought the below would work but Chrome says no. I dont want to use nth child because the DOM could change based on our program, the below seems very flexible but I'm doing something wrong.

.parent .secondchild ~ .fourthchild
{
     css stuff
}
like image 389
user2733367 Avatar asked Jul 17 '26 18:07

user2733367


2 Answers

It's the correct solution, you just wrongly named your classes in the CSS, you forgot the caps.

.parent .secondChild ~ .fourthChild

http://jsfiddle.net/LeBen/Y6QDr/

like image 189
LeBen Avatar answered Jul 20 '26 08:07

LeBen


It's case sensitive! Do this:

.parent .secondChild ~ .fourthChild
like image 27
Alberto Avatar answered Jul 20 '26 07:07

Alberto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!