我怎样才能重复CSS伪元素?

时间:2017-08-22 09:06:31

标签: html css html5 css3 pseudo-element

我有代码:



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

div:before {
  content: 'sale';
  color: white;
}

<div></div>
&#13;
&#13;
&#13;

我想用伪元素填充div:

&#13;
&#13;
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;
}
&#13;
<div></div>
&#13;
&#13;
&#13;

我可以使用 repeat-content 之类的内容吗?我不想手动重复这个词,而div也很敏感。

1 个答案:

答案 0 :(得分:3)

不,没有&#34;重复内容&#34;或类似CSS的东西。你的第二个片段是现在实现这种效果的唯一方法。不过,这样的重复会很好。

理论上,CSS中有element()函数makes it possible使用一个HTML元素(但不是伪元素)作为另一个HTML元素的背景(包括重复背景)。不幸的是,它仅在Firefox中受支持。