CSS bursting color underline

I would like to have a colored underline that looks like this when it breaks:
One and two line underline color header

text-decoration-color doesn't seem to be supported enough.

I tried this:

.underline {
  position: relative;
 }

.underline:after {
  position: absolute;
  content: '';
  height: 1px;
  background-color: #ffc04d;
  bottom: .1rem;
  right: 0;
  left: 0;
  z-index: -1;
}
 <h1><span class="underline">Sprouted Bread</span></h1>
Run codeHide result

, and this is how it looks when it breaks.

+5
source share
3 answers

Try this JSFiddle

Wrap items like yours in between. You can place the text decoration on the parent element and the text color in the gap.

HTML:

<h1><span class="underline">Some Text</span></h1>

CSS

h1 {
  text-decoration: underline;
  color: red;
}

.underline {
  color: blue;
}
+2
source

How about a linear gradient where it will be easy to control the color, size and distance within one element:

.underline {
  position: relative;
  font-size:28px;
  background:
    linear-gradient(yellow,yellow) /* Color */
    left 0 bottom 2px/ /* Position */
    100% 2px  /* Size (width height)*/
    no-repeat;
 }
<div style="width:150px;text-align:center"><span class="underline">Sprouted Bread</span></div>
Run codeHide result

, border-bottom , , , , :

.underline {
  position: relative;
  font-size:28px;
  border-bottom:2px solid yellow;
 }
<div style="width:150px;text-align:center"><span class="underline">Sprouted Bread</span></div>
Hide result
+3

Just add a border!

Using display: inline, add a lower border and a space with padding.

You can also use line-heightand then put negative fields to increase the space between the lines.

And ... you can also animate it!

.underline {
  position: relative;
  padding-bottom: 1px;
  border-bottom: 1px solid #ffc04d;
}
<h1 style="width: 5em">
  <span class="underline">Sprouted Bread</span>
</h1>
Run codeHide result

As @chriskirknielsen already mentioned, you can use box-decoration-break , although this is not supported by IE or Edge . Credits: @Temani Afif

+1
source

Source: https://habr.com/ru/post/1695133/


All Articles