html - 如何用 HTML 中的图像填充文本?
问题描述
假设我有这样的图像:
我想<h1>
用该图像填充一个标签,看起来像这样:
我想我可以做这样的事情开始......
div {
width: 100%;
height: 100%;
background: url(https://i.stack.imgur.com/n8gtc.jpg) 50% 0 no-repeat;
background-size: cover;
}
h1 {
color: white;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
<div>
<h1>404</h1>
</div>
我应该有另一个覆盖图像的“绝对”div 白色和透明字体吗?有谁知道如何做到这一点?
解决方案
background-clip
可能是一个选择
https://developer.mozilla.org/en-US/docs/Web/CSS/background-clip
background-clip CSS 属性设置元素的背景是否延伸到其边框框、填充框或内容框下方。
div {
width: 100%;
height: 100%;
}
h1 {
color: transparent;
font-size: 28vmax;
background-size: cover;
background: url(https://i.stack.imgur.com/n8gtc.jpg) 50% 0 no-repeat;
background-clip: text;
}
<div>
<h1>404</h1>
</div>
或mix-blend-mode
:
https://css-tricks.com/almanac/properties/m/mix-blend-mode/
mix-blend-mode 属性定义元素的内容应如何与其背景混合。这意味着任何图像或文本、边框或标题都将受到此属性的影响。
还
https://developer.mozilla.org/en-US/docs/Web/CSS/mix-blend-mode
mix-blend-mode CSS 属性设置元素的内容应该如何与元素的父元素的内容和元素的背景混合。
* {
margin: 0;
}
div {
width: 100%;
height: 100vh;
background: url(https://i.stack.imgur.com/n8gtc.jpg) 50% 0 no-repeat;
background-size: cover;
}
h1 {
font-size: 15vmax;
display: flex;
align-items: center;
justify-content: center;
height: 100%;
width: 100%;
color: black;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
background: white;
mix-blend-mode: screen;
}
<div>
<h1>404</h1>
</div>
推荐阅读
- sql-server - Azure 数据工厂管道 - 从本地 SQL Server 和 Dynamics CRM 复制数据
- powershell - Powershell 使用 Get-ADPrincipleGroup 引发错误
- css - 生成css的SASS函数
- c# - 在 C# Parallel.ForEach 中的线程上保持变量
- linux - 如何删除 Linux 中所有目录文件的内容?
- reactjs - 使用 Material UI 自定义上一个/下一个分页图标背景颜色
- python-2.7 - 警告 warn(warning_msg) rpm
- wpf - GridSplitter 移动后使用 Expander 调整网格大小不起作用
- php - 配对相同数组中的键值 - PHP
- salesforce - 是否可以在另一个外部网站中嵌入 Salesforce Lightning 应用程序