Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to style individual text-decoration when using multiple properties?

I would like to style to overline to be dashed and the underline to be dotted for a personal project of mine is there any way to achieve that using pure css?

p {
  color: green;
  text-decoration: underline overline;
  text-decoration-style: dashed;
  text-decoration-color: red;
}
<p>Decorated text</p><p>Decorated text</p><p>Decorated text</p>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you know it’s on just one line then you could style the first-line to have one of the lines and the actual element to have the other.

This will work as well as setting a border, and is easier as the placement is already done for you (with border you have to worry about how to get the underline going through the descenders to make it look like a proper underline – which can vary depending on font used).

p {
  color: green;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: red;
}

p::first-line {
  text-decoration: overline;
  text-decoration-style: dashed;
  text-decoration-color: red;
}
<p>Decorated text</p>
<p>Decorated text</p>
<p>Decorated text</p>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading