1

I have following code:

.button { 
   &[aria-label*='first']::after { content: 'some text'; } 
}

It checks if button has aria-label and if it is 'first', it will append 'some text'. I would like to style 'some text' with colors , but 'some' to have black color, and 'text' to have red color. Is that possible and how?

Vikast
  • 695
  • 1
  • 6
  • 12

1 Answers1

0

Although you can't use HTML content in the pseudo elements, well, as an alternative, you can use both ::after and ::before for this case. But please note, there are only those two. So, this is the way you go:

.button[aria-label*='first']::after {
  position: relative;
  content: 'some';
  left: 1em;
  color: #fcc;
}

.button[aria-label*='first']::before {
  position: relative;
  content: 'text';
  left: 6.5em;
  color: #ccf;
}
<div class="button" aria-label='first-button'>Hi</div>

Better way:

.button[aria-label*='first']::after {
  content: 'some';
  color: #f00;
}

.button[aria-label*='first']::before {
  content: 'text';
  color: #ccf;
}
<button class="button" aria-label='first-button'></button>
Praveen Kumar Purushothaman
  • 154,660
  • 22
  • 177
  • 226
  • 1
    You actually can use HTML in the `content` property, kind of...here is an answer of mine: https://stackoverflow.com/a/36073310/2827823 – Ason Jun 28 '17 at 14:36
  • Nice, but I already have 'before' occupied with image &::before { content: url('../../assets/icon.png'); } , so I tried this it is working, but it replaces my image. Can you tell me how to put both image and this part of the text, and I will accept your answer. Thanks! – Vikast Jun 28 '17 at 14:38
  • @Vikast Ha! Like I have told you already, you can have only two pseudo elements. In your case, I guess, you gotta follow the trick used by LGSon by his answer. You take the call. I guess it is better that way. – Praveen Kumar Purushothaman Jun 28 '17 at 14:39