Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip underlining counter [duplicate]

Tags:

html

css

I am trying to underline the headings (h2/h3 elements) for my page, but I also want them numbered. How can I skip underlining the numbers? So I want it to look like

1. <u>First heading</u>

rather than

<u>1. First heading</u>

How should I modify my code?

h2 {
    text-decoration: underline;
      text-decoration-color:#222;
      text-decoration-skip-ink:initial;
      color:#564;
}

h3 {
  text-decoration-color:#856;
  color:#333;
}
h1 {
        counter-reset: h2counter;
    }
    h2:before {
        content: counter(h2counter) ".\0000a0\0000a0";
        counter-increment: h2counter;
        counter-reset: h3counter;
        text-decoration:none;
    }
like image 697
user26316 Avatar asked Apr 01 '26 11:04

user26316


1 Answers

Just add display: inline-block to the ::before pseudo-element

h2 {
  text-decoration: underline;
  text-decoration-color: #222;
  text-decoration-skip-ink: initial;
  color: #564;
}

h3 {
  text-decoration-color: #856;
  color: #333;
}

h1 {
  counter-reset: h2counter;
}

h2::before {
  content: counter(h2counter) ".\0000a0\0000a0";
  counter-increment: h2counter;
  counter-reset: h3counter;
  text-decoration: none;
  display: inline-block;
}
<h2>Test</h2>
like image 173
julien.giband Avatar answered Apr 04 '26 05:04

julien.giband



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!