透明文本允许背景显示

时间:2016-12-01 04:51:42

标签: css frontend

我想知道是否可以在具有纯色背景的容器内实现透明文本。透明文本允许您查看容器后面的图像。

像这样的东西

Transparent text

通过谷歌搜索找到了这个。图像是在photoshop中创建的。使用CSS可以实现这种效果吗?如果是这样,怎么样?

好奇。

2 个答案:

答案 0 :(得分:1)

我希望这将是你要找的东西

<!DOCTYPE html>
<html>

<head>
    <style>
        body {
            background: url(https://lh3.googleusercontent.com/-iFUzJopkFgY/VfZYTJZtC4I/AAAAAAAAArw/mmFz7fGW0VQ/w1920-h1080/never_alone___-wallpaper-1920x1080.jpg) repeat;
            margin: 10px;
        }
        
        h1 {
            background-color: #fff;
            overflow: hidden;
            display: inline-block;
            padding: 10px;
            font-weight: bold;
            font-family: arial;
            font-size: 200px;
        }
        
        span {
            background: url(https://lh3.googleusercontent.com/-iFUzJopkFgY/VfZYTJZtC4I/AAAAAAAAArw/mmFz7fGW0VQ/w1920-h1080/never_alone___-wallpaper-1920x1080.jpg) -20px -20px repeat;
            -webkit-text-fill-color: transparent;
            -webkit-background-clip: text;
            display: block;
        }
        .Container {
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="Container">
        <h1><span>LOS ANGELES</span></h1>
    </div>
</body>

</html>

您只想将-webkit-text-fill-colorcolor设为transparent,将-webkit-background-clip设为text。简单:)

答案 1 :(得分:0)

另一种方法是使用Vendor GenuineIntel Brand Intel(R) Core(TM) i7-4960HQ CPU @ 2.60GHz ==================================================================================================== Deterministic Cache Parameters (EAX = 0x04, ECX = 0x00) ---------------------------------------------------------------------------------------------------- Cache level 1 1 2 3 4 Cache type Data Instruction Unified Unified Unified Cache size (byte) 32K 32K 256K 6M 128M Maximum Proc sharing 2 2 2 16 16 Maximum Proc physical 8 8 8 8 8 Coherency line size (byte) 64 64 64 64 64 Physical line partitions 1 1 1 1 16 Ways of associative 8 8 8 12 16 Number of sets 64 64 512 8192 8192 Self initializing Yes Yes Yes Yes Yes Fully associative No No No No No Write-back invalidate No No No No No Cache inclusiveness No No No Yes No Complex cache indexing No No No Yes Yes ---------------------------------------------------------------------------------------------------- 并使用SVG图像作为掩码 - SVG图像本身可以包含文本。这支持WebKit和Gecko,但不支持IE(http://caniuse.com/#feat=css-masks

https://css-tricks.com/clipping-masking-css/