1

HTML:

<div class="card"></div>

Scss

.card{
  &:before {
    content: 'Text inserted before via CSS';
   }
}

This adds content before the div. but how can i add the content from SCSS.

This was not working

.card{ content: 'Text inserted via CSS';  }

enter image description here

3
  • Your question is quite confusing.. your scss is working fine I think. card{ content: 'Text inserted via CSS'; } this code won't work, you need to add &:before then content property Commented Apr 26, 2020 at 6:04
  • yes :before and :after works fine. but I want to update only the content. Any work arounds in css Commented Apr 26, 2020 at 6:15
  • 2
    1. Content won't work without before or after. 2. If wanna change text of content, add a data attribute in html like data-text="custom text" then in content you can use it like this content: attr(data-text). But note here also you will have to use before or after. Commented Apr 26, 2020 at 9:02

2 Answers 2

1

The content property only applies to CSS pseudo-elements such as :before and :after

You should use JQuery for this purpose:

$('.card').text("Text inserted before via JQuery");
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your response. I'm trying to do in css/scss, with out other library
@upog But I tell you that surely you can not do it with css/scss.
1

Try something like this.

.card:before{
      content:attr(data-content);
    }
    
 <div class="card" data-content="Text inserted before via CSS"></div>
    
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.