It is possible to change the distance between text and underline?
Yes as colleagues have already demonstrated you can increase the distance between what would be a underline and the text. I’ll just add a few things to complete what you asked at the beginning.
But in the future I believe we will have news about this, because the W3C has in its Drafts a property dedicated to it.
text-underline-offset
: official documentation W3C https://www.w3.org/TR/css-text-decor-4/#underline-offset
"Specifies the offset of underlines as a length. This Replaces any information in the font or derived from Glyph shapes / Character ranges. Authors are strongly encouraged to use em Units so that the offset Scales with the font."
If yes, it has some direct property in CSS that we can use to put spacing?
To ward off the underline original, created by text-decoration: underline
at present there is no such property.
Since to text-Decoration we have only these 3 property:
text-decoration-line
Sets the type of decoration used, such as underline or line.
text-decoration-color
Sets the line color
text-decoration-style
Sets the line style, solid
, wavy
, dashed
etc....
Here’s the Mozilla documentation if you want to check it out: https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration#Syntax
There is still the property text-underline-position
but it is used to underline texts vertically etc., it is not for this kind of thing, although it has a correction for when the "descendants" go over the line.
Source W3C: https://www.w3.org/TR/css-text-decor-3/#text-underline-position-Property
In addition, it is possible to use an image like underline for a text?
Yes it is also possible, but take into account what other colleagues have said. The example I did was with a pseudo element ::after
, it will always have 100% of the width of the tag, and how I used measures in rem
and em
it will always follow a proportion relative to the size of the font-size
p {
line-height: 2em;
font-size: 1rem;
}
span {
display: inline-block;
position: relative;
font-size: 1em;
}
span::after {
content: "";
position: absolute;
top: 2em;
left: 0;
width: 100%;
height: 0.2em;
background-image: url(https://placecage.com/50/50);
}
span:nth-child(2) {
font-size: 1.25em;
}
<p>
Lorem ipsum dolor sit, amet consectetur <span>adipisicing 123 abc</span> elit. Quod dolore natus voluptates at a soluta ad nulla aspernatur <span>consequatur</span> ducimus! Adipisci reprehenderit itaque delectus, molestias magni recusandae blanditiis eos libero quisquam voluptatibus deleniti eveniet numquam corporis porro nulla laudantium quibusdam quam sunt ea temporibus ratione incidunt! Incidunt possimus rem illo quam cum minima ad aut sunt sapiente consequuntur eum inventore ipsum, dignissimos quaerat neque deserunt nisi, odit, suscipit quo molestias ut illum officia. Voluptatem magni ipsa nobis facere voluptate deserunt minima adipisci voluptas sapiente dolore placeat facilis perspiciatis repudiandae tenetur aut at, nam id voluptatum atque libero! Veritatis, qui maxime.
</p>
Doubt: define
border-bottom
would be a solution?– Woss
@Andersoncarloswoss I believe it may be!
– João Pedro Schmitz