aftab
aftab

Reputation: 693

How can I use css properties with different classes?

I have different css classes based on different actions. Everything is working good, but when I apply activeBackground class based on condition its making div background-color to green but border-left-color is not coming green its still using .arrow-div class. How can I resolve this issue and apply .activebackground class when needed?

HTML

<div class="text-arrow" ng-class="{'activeBackground': applyActiveFile, 'completeBackground':applyComplete}">File Selection
  <span class="arrow-div"></span>
</div>

CSS

.text-arrow {
    background-color:#BABABA;
    color:#fff;
    display:inline-block;
    padding-left:45px;
}
.arrow-div {
    border-style: dashed;
    border-color: transparent;
    border-width: 0.15em;
    display: -moz-inline-box;
    display: inline-block;    /* Use font-size to control the size of the arrow. */
    font-size: 100px;
    height: 0;
    line-height: 0;
    position: relative;
    vertical-align: middle;
    width: 0;
    background-color:#fff;   /* change background color acc to bg color */ 
    border-left-width: 0.2em;
    border-left-style: solid;
    border-left-color: #BABABA;
    left:0.25em;
}
.activeBackground{
     background-color: green;
     border-left-color: green !important;
}

Upvotes: 2

Views: 54

Answers (1)

Ketzak
Ketzak

Reputation: 628

It appears to me that you're applying .arrow-div and .activeBackground to different elements, and the way your code is written, .activeBackground can't override .arrow-div because it's being applied to a different element (the parent). To affect the child element (the span containing the arrow) you need to set up a css rule that directly targets any child .arrow-div of .activeBackground.

My solution was to simply modify your css like so, providing a way to change the arrow div:

.activeBackground{
    background-color: green;
}
.activeBackground .arrow-div{
    border-left-color: green;
}

Here's a fiddle of it in action: https://jsfiddle.net/cupno5g9/

Upvotes: 4

Related Questions