7

I have code:

div {
  position: relative;
  background: blueviolet;
  height:100px;
}

div:before {
  content: 'sale';
  color: white;
}
<div></div>

I want to fill the div with pseudo-element:

div {
  position: relative;
  background: blueviolet;
  height: 100px;
}

div:before {
  content: 'sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale sale ';
  color: white;
}
<div></div>

Can I do this with something like repeat-content? I dont want to repeat the word manually and the div is responsive.

3
  • Possible duplicate of How to repeat an item multiple times in HTML or CSS? Commented Aug 22, 2017 at 9:08
  • You can't do this with content: ... and pure css. Commented Aug 22, 2017 at 9:11
  • @the4kman, No, Don't want to make the same, so I can have too many words, it is not only 5 stars. Read the question carefully before putting a minus sign! I am asking about multiple repetitions Commented Aug 22, 2017 at 9:12

1 Answer 1

6

No, there is no such thing as "repeat-content" or something similar in CSS. Your second snippet is the only way to achieve this effect now. Such repetition would be gzipped well, though.

In theory, there is the element() function in CSS that makes it possible to use one HTML element (but not pseudo element) as a background for another (including repeating background). Unfortunately, it is supported only in Firefox.

Sign up to request clarification or add additional context in comments.

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.