如何在背景剪辑中包含文本装饰:文本;影响?

发布于 2025-01-02 09:52:07 字数 838 浏览 0 评论 0原文

我在锚标记上使用 -webkit-background-clip: text,bordercolor:透明 ,下划线似乎永远不可见。

我想要的是将文本装饰包含在背景剪辑中。

这是我的 CSS:

.background-clip {
  background: url(images/index-background.jpg) repeat top center fixed;
  -webkit-background-clip: text,border;
  color: transparent;
}

.background-clip a {
  color: transparent;
}

.background-clip a:hover {
  text-decoration: underline;
  -webkit-text-decorations-in-effect: underline; /* doesn't seem to do anything, I am having trouble finding definitive documentation on this */
}

以及相关的 HTML:

<div class="background-clip"><a href="#">Imagine a lot of text here</a></div>

我在查找 WebKit CSS 属性的完整文档时遇到了很多麻烦。有谁知道我可以做些什么来使文本下划线出现在我的锚标记的悬停上?

I am using -webkit-background-clip: text,border and color: transparent on an anchor tag and it seems the underline never becomes visible.

What I want is to include the text decoration in the background clipping.

Here is my CSS:

.background-clip {
  background: url(images/index-background.jpg) repeat top center fixed;
  -webkit-background-clip: text,border;
  color: transparent;
}

.background-clip a {
  color: transparent;
}

.background-clip a:hover {
  text-decoration: underline;
  -webkit-text-decorations-in-effect: underline; /* doesn't seem to do anything, I am having trouble finding definitive documentation on this */
}

And the related HTML:

<div class="background-clip"><a href="#">Imagine a lot of text here</a></div>

I am having a lot of trouble finding thorough documentation of the WebKit CSS properties. Does anyone know what I can do to make the text underline appear on hover of my anchor tag?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

2025-01-09 09:52:07

您可以将 -webkit-text-fill-color 更改为 RGBA 值,如下所示; -webkit-text-fill-color: rgba(0,0,0,0.3); 这允许显示下划线。只需调整不透明度和 RGB 值以匹配背景颜色等即可。

You can change your -webkit-text-fill-color to a RGBA value, like so; -webkit-text-fill-color: rgba(0,0,0,0.3); This allows the underline to display. Just play around with the opacity and rgb values to match the colour of your background etc.

哽咽笑 2025-01-09 09:52:07

我已经在 Chrome 50.0 和 Firefox Nightly 49.0a1 上对此进行了测试(它还支持 -webkit-background-clip: text 自版本 48.0)

据我所知,根据 WebKit 文档,无法在其中包含文本装饰或文本阴影剪报。

根据 Chromium bug -webkit-text- Decorations-in-effect 的目标是纠正与标准 text-decoration 属性相关的继承问题,尽管它显然不会影响 -webkit-background-clip: text以任何方式。

I've tested this on Chrome 50.0 and Firefox Nightly 49.0a1 (which also supports -webkit-background-clip: text since version 48.0)

And as far as I can see, against the WebKit documentation there is no way to include the text decoration or the text shadows in the clipping.

According to a Chromium bug -webkit-text-decorations-in-effect targets to correct inheritance issues related to the standard text-decoration property, though it obviously doesn't affect -webkit-background-clip: text in any way.

如若梦似彩虹 2025-01-09 09:52:07

你实际上得到了下划线,但它也有透明的颜色:)

You actually get the underline, but it has a transparent color, too :)

自此以后,行同陌路 2025-01-09 09:52:07

我认为您不能使用 background-clip: text; 显示 text-decoration,但您可以使用一些 css 创建下划线>。

/* UNNECESSARY CSS */

body {
  font-size: 1.2rem;
  font-family: sans-serif;
  font-weight: bold;
}

.wrapper {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* NECESSARY CSS */
.link {
  position: relative;
  color: black;
  cursor: pointer;
  display: inline;
  pointer-events: all;
  background: linear-gradient(to right, green, green 50%, #43b843ff 50%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-size: 200% 100%;
  background-position: 100%;
  transition: background-position 150ms ease;
}
.link:after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  outline: 0px solid transparent;
  transition: width 150ms ease;
}
.link:hover {
  background-position: 0 100%;
  color: green;
}
.link:hover:after {
  outline: 1px solid green;
  width: 100%;
}
<div class="wrapper">
  <a class="link">Link</a>
</div>

I don't think you can show the text-decoration with background-clip: text;, but you can create your underline playing with some css.

/* UNNECESSARY CSS */

body {
  font-size: 1.2rem;
  font-family: sans-serif;
  font-weight: bold;
}

.wrapper {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* NECESSARY CSS */
.link {
  position: relative;
  color: black;
  cursor: pointer;
  display: inline;
  pointer-events: all;
  background: linear-gradient(to right, green, green 50%, #43b843ff 50%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-size: 200% 100%;
  background-position: 100%;
  transition: background-position 150ms ease;
}
.link:after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  outline: 0px solid transparent;
  transition: width 150ms ease;
}
.link:hover {
  background-position: 0 100%;
  color: green;
}
.link:hover:after {
  outline: 1px solid green;
  width: 100%;
}
<div class="wrapper">
  <a class="link">Link</a>
</div>

北恋 2025-01-09 09:52:07

安德鲁,

如果使用颜色:透明,则看不到下划线。尝试下面的代码,您将在悬停时看到下划线。

    .background-clip {
     background:url(images/index-background.jpg) repeat top center fixed;
    -webkit-background-clip: text,border;
     color: transparent;}

    .background-clip a {
     color:red;
    text-decoration:none;}

    .background-clip a:hover {
    text-decoration:underline;
    -webkit-text-decorations-in-effect: underline;}`

Andrew,

You can't see underline if you use color:transparent. Try below code, you will see underline on hover.

    .background-clip {
     background:url(images/index-background.jpg) repeat top center fixed;
    -webkit-background-clip: text,border;
     color: transparent;}

    .background-clip a {
     color:red;
    text-decoration:none;}

    .background-clip a:hover {
    text-decoration:underline;
    -webkit-text-decorations-in-effect: underline;}`
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文