How to display image under text like as a background?

前端 未结 4 862
再見小時候
再見小時候 2021-01-06 12:51

I want to display Image under Text. I have done this with Photoshop but it\'s a Image. So every time text change I have to do changes in Photoshop. I want to achieve same us

4条回答
  •  温柔的废话
    2021-01-06 13:03

    Solution using webkit-background-clip - please note that for now this does not work in Firefox

    Rewrite from here HTML/CSS: "See Through Background" Text?

    Live Demo

    enter image description here

    h1, p { margin: 0; }
    
    #container {
        padding: 20px 20px 100px;
        margin: 50px;
        position: relative;
    }
    #container h1 {
        /* has same bg as #container */
        background: url(http://media.royalcaribbean.com/content/shared_assets/images/destinations/regions/hero/hawaii_01.jpg);
    
        font-size: 12em;
        font-family: impact;
        left: 0;
        line-height: 100%;
        padding-top: 25px; /* padding + border of div */
        position: absolute; /* position at top left of #containter to sync bg */
        text-align: center;
        top: 0;
        width: 100%;
        text-fill-color: transparent;
        background-clip: text;
        text-fill-color: transparent;
        background-clip: text;
        -webkit-text-fill-color: transparent;
        -webkit-background-clip: text;
        -moz-text-fill-color: transparent;
        -moz-background-clip: text;
    }
    

提交回复
热议问题