Files
30-seconds-of-code/blog_posts/css-style-default-links.md
2022-12-04 22:26:44 +02:00

857 B

title, shortTitle, type, tags, author, cover, excerpt, firstSeen
title shortTitle type tags author cover excerpt firstSeen
Tip: Style links without a class Style default links tip css,visual,interactivity chalarangelo blog_images/citrus-drink.jpg A short summary of your story up to 180 characters long. 2022-11-23T05:00:00-04:00

When styling injected or generated HTML content, you might not have access to the classes or IDs of the elements you want to style. This can become especially annoying when dealing with link elements. Luckily, you can use the :not() selector with an appropriate attribute selector to check for the absence of a class and style links accordingly.

a[href]:not([class]) {
  color: #0077ff;
  text-decoration: underline;
}

As a bonus tip, you can use the previous tip about selecting any link to further enhance this solution.