我试图将Figma设计转换为代码,但它有一些使用内部阴影效果的文本

enter image description here

我try 使用纯文本和剪切文本阴影CSS属性来设置样式,但结果与阴影类剪切/插入文本的设计不太匹配.

h1 {
  font-family: 'Poppins';
    font-style: normal;
    font-size: 80px;
 
    text-align: center;
    
    color: #6225E6;
    text-shadow: -6px 0px 0px #D63737;
    background-color: #151717;
}
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<h1>This is some text<h1/>

推荐答案

你可以使用mask(在Firefox中不起作用)

h1 {
  font-family: 'Poppins';
  font-size: 80px;
  letter-spacing: 5px;
  text-align: center;
  color: #0000;
  text-shadow: 
    5px 0  #6225E6,
    0 0  red;
  -webkit-mask: linear-gradient(#000 0 0);
  -webkit-mask-clip: text;
          mask-clip: text;
}

body {
  background:#000;
}
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<h1>This is some text<h1/>

为了获得更好的支持,您可以复制文本并try 以下操作:

h1 {
  font-family: 'Poppins';
  font-size: 80px;
  letter-spacing: 5px;
  text-align: center;
  color: #0000;
  text-shadow: 
    5px 0 #6225E6, 
    0 0 red;
  position: relative;
}

h1:before {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  background: #000;
  color: #fff;
  mix-blend-mode: darken;
  text-shadow: none;
}

body {
  background: #000;
}
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<h1 data-text="This is some text">This is some text</h1>

Html相关问答推荐

CSS属性不适用于IOS设备

srcset和大小总是下载最大的

在元素之间添加空格

Angular 15 p-对话框不使用组件 Select 器呈现HTML

悬停效果在新西兰表上不起作用

需要帮助创建一个简单的html css网格布局

如何使用Reaction Js读取html文件中的代码

在css中,如何在英雄版块的标题后面做一个粘性的导航栏?

Style=背景图像URL引用变成&;Quot;

为什么根捕获上的`min-height`溢出,而`height`没有?

是否可以只使用css而不使用像&;nbsp;这样的HTML符号来实现断字而不换行空格?

div 中的垂直中心表格

调整 Rmarkdown 输出的 html_document 的标题和副标题之间的间距

jQuery 索引返回不正确的结果

Tailwind 网格行高度可防止拉伸到最高行的所有相同高度

Bootstrap 轮播内容在箭头之间不显示

如何让一个 div 始终贴在容器的边缘?

CSS 中的 fingerprint scanner 动画

在身体外部创建 tanget 45° div

尽管设置了 width:100% left:0,但居中对齐的 CSS 动画并不对称