Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS selector for element with two classes not working

I am trying to style these elements, and the element with two classes can't be style different than the one with one class. I've tried to select it with .red.balls also, but it doesn't work.

.ballsAll {
  display: block;
  margin-left: 14%;
}
.red {
  background-color: red;
}
.balls {
  background-color: white;
}
<div class='ballsAll'>
  <p>
    <span class='balls'>22</span>
    <span class='balls red'>11</span>
  </p>
</div>
like image 246
frontendgirl Avatar asked Feb 03 '26 21:02

frontendgirl


2 Answers

Declare .balls before .red, Like this:

.ballsAll {
  display: block;
  margin-left: 14%;
}
.balls {
  background-color: white;
}
.red {
  background-color: red;
}


<div class='ballsAll'>
  <p>
    <span class='balls'>22</span>
    <span class='balls red'>11</span>
  </p>
</div>
like image 97
ttA01 Avatar answered Feb 06 '26 11:02

ttA01


Use this code:

.ballsAll {
  display: block;
  margin-left: 14%;
}
.red.balls {
  background-color: red;
}
.balls {
  background-color: white;
}
<div class='ballsAll'>
  <p>
    <span class='balls'>22</span>
    <span class='balls red'>11</span>
  </p>
</div>
like image 44
Naqash Malik Avatar answered Feb 06 '26 13:02

Naqash Malik



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!