csscss-mask

How can I make a single run-of-text outlined in some areas and a solid-fill in other areas?


I recently came across this dribbble/landing page concept with hollow/filled text.

enter image description here

First off I'm not entirely sure if this concept could be recreated in CSS. A bit of Google did lead me to CSS text masks, but I wasn't able to find any post that can really recreate this effect.

How would I be able to reconstruct the hollow/filled text, depending if the background behind the text has an image or not?


Solution


  •  body {
    background-color: #dbdac2;
    --solid-white: linear-gradient(white,white);
     }
    #container,
    #container > #div1 {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
    
        background-size:
            153px 302px,
            148px 302px,
            154px 302px;
    
        background-position:
            131px 94px,
            309px 28px,
            480px 94px;
    
        background-repeat:
            no-repeat,
            no-repeat,
            no-repeat;
    
        animation: moveImages 2s infinite;
        animation-direction: alternate;
    }
    
    #container {
        border: 1px solid white;
        position: relative;
        width: 711px;
        height: 440px;
    
        /* These are the 3 photo images, rendered as separate background-image layers: */
        background-image:
            url( "https://i.sstatic.net/hmwyh.png" ),
            url( "https://i.sstatic.net/JeHEg.png" ),
            url( "https://i.sstatic.net/pVgz6.png" );
        }
        #container p {
            margin: 0;
            position: static;
            padding-top: 192px;
            padding-left: 62px;
            overflow: hidden;
    
            font-family: Helvetica;
            font-size: 99px;
            letter-spacing: -2px;
            font-weight: 600;
        }
            #container > #pStroke {
                text-stroke: 1px white;
                -webkit-text-stroke: 1px white;
                color: transparent;
            }
    
            #container > #div1 {
                /* #div1's background-image layers must match #container's: */
                background-image:
                    var(--solid-white),
                    var(--solid-white),
                    var(--solid-white);
    
                -webkit-background-clip: text;
                background-clip: text;
                color: transparent;
            }
    
    @keyframes moveImages {
        /* The `@keyframes from {}` rule is optional, btw. */
        to {
            background-size:
                53px 302px,
                58px 302px,
                154px 302px;
    
            background-position:
                431px 94px,
                209px 28px,
                280px 194px;
        }
    }
    <div id="container">
    
      <div id="div1">
        <p id="pWhite">Fashion Give<br />Impression.</p>
      </div>
      
      <p id="pStroke">Fashion Give<br />Impression.</p>
    
    </div>

    Explanation:

    Possible alternative approaches: