css - Wavy red underline not visible near some characters like `g` and `y` - Stack Overflow

I want to style selected words with a wavy red underline. This answer explains how to do it using text-

I want to style selected words with a wavy red underline. This answer explains how to do it using text-decoration, and it works fairly well. However, it’s not perfect. The wavy line breaks near certain characters, such as the characters g, j and y. Is there a solution for this?

You can also try in this playground mentioned in the solution.

I want to style selected words with a wavy red underline. This answer explains how to do it using text-decoration, and it works fairly well. However, it’s not perfect. The wavy line breaks near certain characters, such as the characters g, j and y. Is there a solution for this?

You can also try in this playground mentioned in the solution.

Share Improve this question edited Mar 25 at 6:26 Brett Donald 14.9k5 gold badges35 silver badges61 bronze badges asked Mar 25 at 4:41 vibhaysinghvibhaysingh 465 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 2

Use text-underline-offset. Lowercase letters like qygpj that extend below the baseline are called descenders.

.line {
  text-decoration: underline wavy red;
}

.offset {
  text-underline-offset: 0.5rem;
}
<h1 class="line">qygpj</h1>

<h1 class="line offset">qygpj</h1>

What you need is the text-decoration-skip-ink property.

However, please be aware that this method may make it challenging to differentiate between similar letters, such as 'i' and 'j', if the text and underline share the same color. I recommend using an offset if employing different colors for the text and underline is not feasible.

You have two options for solving this. The first option is to tell the browser not to skip the underline in areas where it would overlap a character, by setting text-decoration-skip-ink: none.

.line {
  -webkit-text-decoration: underline wavy red; /* Safari */
  text-decoration: underline wavy red;
}

.skip {
  text-decoration-skip-ink: none;  /* has no effect in Safari, which doesn’t skip the ink in the first place */
}
<h1 class="line">jumps quickly</h1>

<h1 class="line skip">jumps quickly</h1>

The second option is to move the underline further away from the text by increasing the text-underline-offset.

.line {
  -webkit-text-decoration: underline wavy red; /* Safari */
  text-decoration: underline wavy red;
}

.offset {
  text-underline-offset: 0.3em;
}
<h1 class="line">jumps quickly</h1>

<h1 class="line offset">jumps quickly</h1>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744217598a4563628.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信