Text with background-color and transparent color

4

I need to apply a color: transparent to an element that has background-color: #fff . I've tried to apply a opacity: 0 but it applies to the element all of that, even in the background.

My current html: <strong>matar a fome</strong>

The goal is to achieve this result:

    
asked by anonymous 14.11.2017 / 19:45

1 answer

5

This effect is known as Knockout Text. I made this model to help you as an example. It works fine in Chrome and FF, but in IE it gets kind of buggy to vary ...

Follow CSS / HTML

div {
    width: 300px;
    height: 300px;
    position: relative;
    display: flex;
    background-image: url(http://placecage.com/300/300);
    background-position: center;
    background-repeat: no-repeat;
    margin: 10px auto;
}
div::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #000;
    width: 90%;
    height: 100px;
    margin: auto;
}
h1 {
    text-align: center;
    color: #fff;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-image: url(http://placecage.com/300/300);
    background-position: center;
    background-repeat: no-repeat;
    margin: auto;
    font-size: 42px;
    font-family: sans-serif;
    font-weight: bold;
    padding: 0;
    z-index: 1;
}
h1::after {
    content: attr(data-title);
    -webkit-background-clip: initial;
    -webkit-text-fill-color: initial;
    background-image: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, 80%);
}
<div>
    <h1 data-title="Knockout">Knockout</h1>
</div>

The articles I used as a reference are: link e link

    
23.11.2017 / 13:28