Css strikethrough different color from text?
Quickly achieve a strikethrough with a different color from the text using text-decoration-color
in CSS:
This snippet offers a red strikethrough over blue text. A stunning visual effect for your website.
Detailed application and use-cases
Let's delve deeper into advanced techniques and important considerations when implementing a strikethrough with a different color.
Custom strikethrough creation
By leveraging the CSS pseudo-element ::after
along with border-top
, you can custom design your strikethrough. Typically, this approach is advantageous for angling your strikethrough or adjusting its precise placement over the text:
Compatibility across browsers
The text-decoration-color
property enjoys support in most modern browsers. However, Edge and IE (Internet Explorer) might not render it correctly. Always check browser compatibility and provide fallbacks or alternatives for users on different browser versions.
Design considerations
To ensure readability, select contrasting colors for your strikethrough and text. Be sure to test your design on devices of various sizes to maintain visual consistency.
Extra tips
For performance considerations, use the ::after
method cautiously on large blocks of text. Also, be mindful that relying on !important
in CSS might introduce styling conflicts.
Special effects and cases
Applying hover effects
The :hover
pseudo-class allows you to apply a strikethrough on hover. However, in IE7, ensure an href
exists in the <a>
tag for the hover to take effect, a behavior not consistent with Firefox or WebKit-based browsers.
Implementing angled strikethroughs
Use CSS transform on the ::after
pseudo-element for angled strikethroughs to add visual appeal and dynamism.
Strikethrough animation
Using keyframes and animations in CSS, create exciting strikethroughs that animate.
Upcoming CSS3 features
Stay updated with emerging CSS3 features for potential new ways to style text decoration like text-decoration-thickness
for adjusting strikethrough width.
Was this article helpful?