html - 带实心阴影的透明文本

标签 html css

我正在尝试实现标题中提到的效果:

desired effect

我使用了以下代码:

.contact-txt h1 {
	color: transparent;
	font-size: 60px;
	line-height: 1em;
	text-shadow: 3px 3px #00d44a;
}

但我得到的是绿色文本:

see here

有没有办法像第一张图片那样有一个透明的文本和一个实心的阴影?

最佳答案

想法是把两个div叠在一起,如果只用一个透明的,阴影就不会被文字挡住。

用两个可以达到这个效果

-webkit-background-clip: text

(currently supported in Chrome, Safari, and Opera, and being implemented in Firefox) is the text value for background-clip. When used along with the proprietary -webkit-text-fill-color: transparent; feature, this allows you to clip background images to the shape of the element's text, making for some nice effects. This is not an official standard, but has been implemented across multiple browsers, as it is popular, and used fairly widely by developers. When used in this context, both of the properties would require a -webkit- vendor prefix, even for Non-Webkit/Chrome-based browsers:

.text-clip {
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

REF: https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_boxes/Advanced_box_effects#-webkit-background-clip_text

div {
  position: absolute;
  top: 0;
  left: 0;
  background-image: url(http://www.cameraegg.org/wp-content/uploads/2013/08/AF-S-DX-NIKKOR-18-140mm-f-3.5-5.6G-ED-VR-sample-images-1.jpg);
  font-size: 70pt;
  font-weight: bold;
  line-height: 2em;
  padding: .5em;
  font-family: Roboto;
}

div.shadow {
  color: transparent;
  text-shadow: 7px 7px red;
}

div.text {
  color: transparent;
  -webkit-text-fill-color: transparent;
  -webkit-background-clip: text;
}
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">

<div class="shadow">DIRECTOR</div>
<div class="text">DIRECTOR</div>

关于html - 带实心阴影的透明文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44249929/

相关文章:

css - 如何对齐按钮左侧?

HTML Inline Flex 不适应主类

jquery - 如何在 Bootstrap 日期分页器中只显示一个元素

html - float 属性在我的 CSS 中不起作用

javascript - 浏览器缩放时如何在打印时没有缩放内容?

css - 如何使用 CSS 调整图像以适应窗口宽度和高度

php - 使用 css 定位 div 标签

html - 如何使CSS搜索表单响应式

HTML - 有序列表,将列表编号设置为 (a)、(i)、(aa)

jquery - 更改背景位置 - 最好使用 jQuery 或 :hover with Selectivizr?