W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body {font-family: Arial, Helvetica, sans-serif;} .image-container { background-image: url("/i/photo/shanghai.jpg"); background-size: cover; position: relative; height: 300px; } .text { background-color: white; color: black; font-size: 10vw; font-weight: bold; margin: 0 auto; padding: 10px; width: 55%; text-align: center; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); mix-blend-mode: screen; } </style> </head> <body> <h1>响应式文本抠图效果</h1> <div class="image-container"> <div class="text">SHANGHAI</div> </div> <p>本例创建了一种响应式的抠图文本,文本会剪切背景图像。</p> <p>请调整 浏览器窗口大小来查看响应式效果。</p> <p><b>注释:</b>此例在 Internet Explorer 或 Edge 中无效。</p> </body> </html>