有没有办法使用文本使用与CSS背景的方法吗?

有没有办法使用文本使用与CSS背景的方法吗?

问题描述:

我想用动态文本作为我的标签某些元素的背景。正因为如此,我可以用图像(动态文本)。我如何只用CSS或JavaScript做呢?

I would like to use dynamic text as background of certain elements in my tag. Because of this, I can use images (dynamic text). How do I do it with just CSS or JavaScript?

您可以有你的相对定位的元素里面绝对定位的元素:

You can have an absolutely positioned element inside of your relative positioned element:

<div id="container">
    <div id="background">
    Text to have as background
    </div>
    Normal contents
</div>

和则CSS:

#container {
   position: relative;
}

#background {
   position: absolute;
   top: 0;
   left: 0;
   bottom: 0;
   right: 0;
   z-index: -1;
   overflow: hidden;
}

下面的的一个例子。