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

前端 未结 8 697
暖寄归人
暖寄归人 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

    @Ciro

    You can break the inline svg code with back-slash "\"

    Tested with the code below in Chrome 54 and Firefox 50

    body {
        background: transparent;
        background-attachment:fixed;
        background-image: url(
        "data:image/svg+xml;utf8, \
         \
        I love SVG!");
    }
    

    I even Tested this,

    background-image: url("\
    data:image/svg+xml;utf8, \
       \
         \
         \
          I love SVG! \
         \
      \
    ");
    

    and it works (at least in Chrome 54 & Firefox 50 ==> usage in NWjs & Electron guarenteed)

提交回复
热议问题