【问题标题】:How do I get deteted image using text effect using css? [duplicate]如何使用 css 使用文本效果删除图像? [复制]
【发布时间】:2021-10-23 10:46:06
【问题描述】:

有人可以帮我实现这样的效果吗?背景图像需要使用如下图所示的文本删除。用css

【问题讨论】:

  • 黑色svg图片,字母被剪掉,图片设置为深层。
  • 手动设置svg??使用插画师??是否可以使用 css tho?
  • 可以使用css。我不知道怎么。我所知道的是使用 svg。您可以在 Illustrator 中创建 svg,但我推荐 Inkscape,因为它是您需要的网络友好 svg,并且 Inkscape 提供本机 svg。

标签: css


【解决方案1】:

您可以将background-clip-webkit-text-fill-color: transparent 与伪元素一起使用。

放置一个带有背景图片和相对位置的元素。然后在该元素内放置一个元素并覆盖其父元素的宽度 100% 的高度的 50vw,然后将其绝对定位并放置左侧或右侧和顶部@0。然后您可以根据需要设置样式文本。将 background-clip 设置为文本,background-clip: text; 并设置 -webkit-text-fill-color: transparent,设置 background-size 以覆盖父元素和剪辑元素。

现在设置一个伪元素来放置黑色背景。 .clip-area::before 将背景设置为黑色,宽度设置为 50%,高度设置为 100%,左侧或右侧和顶部设置为 0,z-index 设置为 -1。

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

#bg {
  width: 100vw;
  height: 100vw;
  background: url(https://d2jx2rerrg6sh3.cloudfront.net/image-handler/ts/20200123101248/ri/673/picture/2020/1/shutterstock_603198743.jpg) no-repeat;
  position: relative;
  z-index: 1;
  background-size: cover;
}

.clip-area {
  display: flex;
  align-items: center;
  position: absolute;
  left: 0;
  top: 0;
  width: 50vw;
  height: 100%;
  line-height: 3.5rem;
  font-size:  clamp(2rem, 3.5vw, 5rem);
  text-align: center;
  text-transform: uppercase;
  font-family: 'Open Sans Pro', sans-serif;
  font-weight: bold;
  background: url(https://d2jx2rerrg6sh3.cloudfront.net/image-handler/ts/20200123101248/ri/673/picture/2020/1/shutterstock_603198743.jpg);
  background-size: cover;
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.clip-area::before {
  content: '';
  background: black;
  width: 50vw;
  height: calc(100% - 6px);
  position: absolute;
  left: 0;
  top: 0;
  z-index: -1;
  margin: 3px;
  border-top-left-radius: 1rem;
  border-bottom-left-radius: 1rem;
}
<div id="bg">
  <div class="clip-area">
    You can use text clipping to show the background below
  </div>
</div>

【讨论】:

  • 我很想看到这是堆栈溢出时工作的交互式代码(我在手机上)。
  • @Nick 答案中有一个片段,当你进入桌面时检查一下。
  • IE 不支持 -webkit-text-fill-color 但这并不奇怪。这太棒了!
  • 你不需要-webkit-text-fill-colorcolor就够了
  • @SalilRajkarnikar 它正在删除文本层上的背景,然后在背景上使用图像覆盖该文本层,在两个层上使用相同的图像。
猜你喜欢
  • 2013-01-17
  • 2013-08-21
  • 2023-03-07
  • 1970-01-01
  • 2016-05-02
  • 2018-02-05
  • 2022-01-24
  • 2016-06-25
  • 2018-02-19
相关资源
最近更新 更多