HTML/CSS: “See Through Background” Text?

前端 未结 1 600
执笔经年
执笔经年 2020-12-14 02:46

Ok, is this possible.

I have a background image. On top of that, I have a transparent grey box for content. I\'d like to have title at the top in text, that is bas

相关标签:
1条回答
  • 2020-12-14 03:04

    One way is to use -webkit-background-clip: text;: demo here (webkit only obviously).

    Using position, we can sync both backgrounds:

    #container, #container h1 {
        background: url(bg.png)
    }
    
    #container {
        position: relative;
    }
    
    #container #gray {
        background: rgba(0,0,0,.8);
        padding-top: 8em;
    }
    
    #container h1 {
        font-size: 8em;
        padding-top: /* padding + border of div */;
        position: absolute;
        -webkit-text-fill-color: transparent;
        -webkit-background-clip: text;
    }​
    

    Or you could use the same approach and apply a svg mask, that will work in all modern browsers.

    0 讨论(0)
提交回复
热议问题