Is there a way to use use text as the background with CSS?

前端 未结 8 665
暖寄归人
暖寄归人 2020-11-28 03:48

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?

8条回答
  •  有刺的猬
    2020-11-28 04:27

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

    Text to have as background
    Normal contents

    And then the CSS:

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

    Here's an example of it.

提交回复
热议问题