0

I want to change the font color if it have specific class.

HTML:

    <p class="status">  
      test
      <span class="has-this">test</span> (all turn to red)
    </p>

    <p class="status"> 
      <span>test</span> 
    </p>

SCSS:

.status {
        font-size: 25px;
        color: blue;
        height: 30px;
        line-height: 30px;
        padding-right: 10px;
        .has-this & {
            color: red;
        }
    }

If it has 'has-this' class inside I want to change font color to red. Is it possible to achieve this by using css only ?(no js) The status dynamically generate some with has-this some not .

Here my codepen http://codepen.io/anon/pen/ZbGyZm

Sahal Saad
  • 80
  • 6

4 Answers4

0

Add below Css:

.status span {
  color: gray;
}
Ivin Raj
  • 3,237
  • 2
  • 17
  • 46
  • I think you need to re-read the OP. All this will do is make the text in `span`s which are children to `.status` `grey`. – Hidden Hobbes Sep 08 '15 at 07:47
0

You don't need to use the & character just do this:

.status {
    ....
    .has-this {
      ....
    }
}

The & character represents the parent selector and renders it as it is when scss is compiled, for example:

.status {
   ...
    &:after{
   ...
   }
}

becomes:

.status{ ... }
.status:after{ ... }
Imran Bughio
  • 4,215
  • 2
  • 24
  • 50
0

i have done the code you can see... HTML part

  <span class="a">test</span> 
  <h1 class="h1">jkcldjf</h1>



  <span class="a">test</span> k

</div>

SCSS part...

.status {
        font-size: 25px;
        color: blue;
        height: 30px;
        line-height: 30px;
        padding-right: 10px;
        & .a {
            color: green;
        }
       & .h1
         {
           color:green;
         }
    }
Pardeep Jain
  • 71,130
  • 29
  • 141
  • 199
0

Edit Your CSS like

.status {
    font-size: 25px;
    color: blue;
    height: 30px;
    line-height: 30px;
    padding-right: 10px;
    .has-this {
        color: red;
    }
}
Lalji Tadhani
  • 12,597
  • 2
  • 19
  • 36