| You are here: | About>Computing & Technology>Web Design / HTML> CSS> Styling Links with CSS - Learn How to Use CSS to Create Button-like Links and Other Special Effects |
![]() | Web Design / HTML |
HTML References / Web Design ReferencesCSS 1 and CSS 2 PropertiesHTML 4.01 Tags / XHTML 1.0 ElementsHTML Codes Styling Links with CSSLearn How to Use CSS to Create Button-like Links and Other Special EffectsLinks are very common on Web pages, but many Web designers don't realize the power that they have with CSS to manipulate and manage their links effectively. You can define links with visited, hover, and active states. You can also work with borders and backgrounds to give your links more pizzaz or make them look like buttons or even images. Most Web designers start out by defining a style on the a tag: a { color: red; } This will style all aspects of the link (hover, visited, and active). To style each part separately, you must use link pseudo-classes. Link Pseudo-ClassesThere are four basic types of link pseudo-classes you can define:
To define a link pseudo-class, use it with the a tag in your CSS selector. So, to change the visited color of all your links to grey, write: a:visited { color: grey; } If you style one link pseudo-class, it's a good idea to style them all. That way you won't be surprised by extraneous results. So if you just want to change the visited color to grey, while all other pseudo-properties of your links remain black, you'd write: a:link, a:hover, a:active { color: black; } Change the Link ColorsThe most popular way to style links is to change the color when the mouse hovers over it: a { color: #00f; } But don't forget that you can affect how the link looks as they are clicking on it with the :active property: a { color: #00f; } Or how the link looks after you've visited it with the :visited property: a { color: #00f; } To put it all together: a { color: #00f; } Put Backgrounds on the Links to Add Icons or BulletsYou can put a background on a link as in the Stylish Backgrounds article, but by playing with the background a little, you can create a link that has an associated icon. Choose an icon that is small, around 15px by 15px, unless your text is larger. Place the background to one side of the link and set the repeat option to no-repeat. Then, padd the link so that the text within the link is moved over far enough to the left or right to see the icon. a { Once you've got your icon, you can set a different image as your hover, active, and visited icons to make the link change: a { Make Your Links Look Like ButtonsButtons are very popular, but until CSS came along, you had to create buttons using images, which makes your pages take longer to load. Luckily, there is a border style that can help you create a button-like effect easily with CSS. a { Note, when you put colors on the outset and inset styles, browsers are not as likely to render them as you might expect. So, here's a fancier button with colored borders: a { And you can affect the hover and active styles of a button link as well, just use those pseudo-classes: a:link {view Don't Let Your Links Be BoringWhen you use links, think about how they will impact your readers. Links can be fun or they can be just underlined text on your Web pages. Why not make your links part of the design? HTML References / Web Design ReferencesCSS 1 and CSS 2 PropertiesHTML 4.01 Tags / XHTML 1.0 ElementsHTML Codes |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


