{"id":11,"date":"2008-01-30T13:00:32","date_gmt":"2008-01-30T19:00:32","guid":{"rendered":"http:\/\/cssnewbie.com\/2008\/01\/style-your-links-with-css\/"},"modified":"2008-01-30T13:00:32","modified_gmt":"2008-01-30T19:00:32","slug":"style-your-links-with-css","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/style-your-links-with-css\/","title":{"rendered":"Style your links with CSS"},"content":{"rendered":"<p><img src='https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/01\/spider-web.jpg' alt='A Spider Web - Photo by MR+G' title='Photo by MR+G. Used under a creative commons license.' \/><\/p>\n<p>Anchor tags (a.k.a. links or hyperlinks) (these things: &lt;a&gt;) are one of the more ubiquitous elements of the web world. In fact, it\u2019s the anchor tags that put the \u2018Web\u2019 in the World Wide Web \u2013 they\u2019re the points of interconnectivity, like strands in a spider web, that hold this whole crazy Net of ours together.<\/p>\n<p>And we all know what links look like, too: they\u2019re dark blue, underlined, and stand out on a page like the varicose veins on the backs of great-Aunt Esther\u2019s legs. And just as we don\u2019t understand why Esther would choose to <em>wear<\/em> those shorts in public, we don\u2019t understand why something as common as an anchor tag should have to look so darn unattractive.<\/p>\n<p class=\"pullquote\">With CSS, links don\u2019t have to be ugly.<\/p>\n<p>But here\u2019s the kicker: with CSS, links don\u2019t have to be ugly. They can look pretty much however you want. Here are a few of the things you can do to make your links stand out without sticking out:<\/p>\n<p><strong>Change the Color.<\/strong> Some <a href=\"http:\/\/www.useit.com\/\">stick-in-the-mud Web proponents<\/a> would have you believe that blue is the only color a hyperlink should ever wear, in much the same way that white shoes after Labor Day are a social faux-pas. Their argument is that people are used to seeing blue, underlined links; to mess with this convention is to anger the gods and confuse your readers. I say bollocks! Any text that stands out from the rest will attract attention. And green can stand out just as well as blue:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">a { \n\tcolor: #6c6; \n}<\/pre>\n<p>This gives us a lovely link the exact shade of a seasick leprechaun. How\u2019s that for fancy?<\/p>\n<p><strong>Underline, Schmunderline.<\/strong> Personally, I\u2019m not a big fan of underlined text. Too much of it can be a distraction \u2013 everything on the page seems to be clamoring for attention. So why don\u2019t we remove the underline from that hyperlink:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">a { \n\ttext-decoration: none; \n}<\/pre>\n<p>And now, our <a href=\"http:\/\/www.google.com\" style=\"text-decoration: none;\">links don\u2019t overwhelm<\/a> the nearby text.<\/p>\n<p>Or, you could even make the underline only appear when someone puts their mouse over the link (my personal favorite):<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">a { \n\ttext-decoration: none; \n}\na:hover { \n\ttext-decoration: underline; \n}<\/pre>\n<p>The rules above state that \u201cnormal\u201d anchor tags should not have any sort of decoration: no underlines, in other words. However, when someone \u201chovers\u201d over an anchor, we should put the underline back.<\/p>\n<p><strong>Image is Everything.<\/strong> If you wanted to get really fancy, you could even make a small image (an icon, if you will) appear next to your links. All you have to do is create your image at the appropriate size, put it on your server where your CSS can get to it, and do something like this:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">a { \n\tpadding-left: 16px;\n\tbackground-image: url(icon.gif) no-repeat; \n}<\/pre>\n<p>This rule is a little more complicated, so I\u2019ll explain in greater detail. First, we applied some padding to the anchor tag&#8230; we need some room for the image to show up. Then, we applied the image to the background of the element (which, as we learned last time, is applied to the padding around an element). Under normal circumstances, the background would repeat itself in every direction, showing up underneath our link text. We don\u2019t want that, so we added the \u2018no-repeat\u2019 condition to stop it from showing up more than once. And the result: <a href=\"http:\/\/www.robglazebrook.com\" style=\"padding-left: 16px; background: transparent  url(\/img\/globe_icon.gif) no-repeat;\">links with images<\/a>.<\/p>\n<p><strong>Putting it All Together. <\/strong>When our powers combine, we become&#8230; Captain Hyperlink! Or, at the very least, we can have aesthetically pleasing links that somehow manage to attract attention without overwhelming the page. And without reminding us of great-Aunt Esther\u2019s visit last summer.<\/p>\n<p>If we take what we know about CSS classes and apply that to this example, we could even make certain types of links look different from others:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">a.pdf {\n\tcolor: #c00;\n\tfont-weight: bold;\n\ttext-decoration: none;\n\tpadding-left: 10px;\n\tbackground-image: url(pdf_icon.gif) no-repeat;\n}\na.pdf:hover {\n\ttext-decoration: underline;\n}<\/pre>\n<p>Now how\u2019s that for some fancy linkage? I encourage you to take these examples I\u2019ve provided and expand upon them. What can you make your links do?<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<\/p>\n<p>Anchor tags (a.k.a. links or hyperlinks) (these things: &lt;a&gt;) are one of the more ubiquitous elements of the web world. In fact, it\u2019s the anchor tags that put the \u2018Web\u2019 in the World Wide Web \u2013 they\u2019re the points of [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/style-your-links-with-css\/\" title=\"Click to read 'Style your links with CSS'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[173,182,188],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/11"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=11"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/11\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}