Category: 

How Can I Create CSS Hover Effects?

Article Details
  • Written By: G. Wiesen
  • Edited By: Heather Bailey
  • Last Modified Date: 19 April 2014
  • Copyright Protected:
    2003-2014
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
A 2003 blackout affected 50 million people in North America and had an economic impact of about $10 billion USD.  more...

April 23 ,  :  William Shakespeare was born and died. (1564, 1616)  more...

CSS hover effects are fairly simple to create, and basic hover effects can be quickly and easily implemented and modified with a number of other options. Cascading style sheets (CSS) is a language used in creating the style and layout of a document created in a markup language, and it can be used to easily create hover effects. Hover effects are changes that occur with text, images, or other objects in a document when the pointer controlled by a mouse is hovered over the object. CSS hover effects are typically created within the CSS code and can be implemented quickly and effectively.

One of the easiest types of CSS hover effects to create is an effect that causes a change to a link on a website when it is hovered over. For example, someone may want to create a textual link that looks like standard text, or is a different color than the rest of the page, but when “moused over” or “hovered over” it is underlined or emboldened. How this is done, precisely, will typically depend on the exact coding used on the page, but in a simple case the CSS hover effect can be added within the CSS rules within the “style” section.

Ad

A new rule is created for the CSS hover effect using the appropriate tag for the object to which the effect is being added. For example, text that is being chosen might be part of a list or selected within the body of a webpage. This text should have a specific tag associated with it in the body coding. With this tag noted, the rule can be created to establish a CSS hover effect for any objects with that given tag.

Using text, for example, if you want to make a link become underlined when a user hovers over it, then you can begin by tagging that link within the body code and creating a special rule for that tag. Within this rule you can indicate what color that text should be, easily making it stand out from the surrounding text, and visually indicating that the user may want to hover over it, which would then trigger the CSS hover effect. This effect is added by creating a “hover pseudo-class” to the tag for the line of text.

If the tag for the text, for example, was “a” then you would use the pseudo-class that looked like “a:hover {…}” with the desired CSS hover effect indicated within the bracket. Using the previous example, if the desired effect was to underline the text when it is hovered over, then it would read “text-decoration: underline;” within the bracket. There are a number of different hover effects that can be created for different objects, and each has a specific command to create the effect, but the process is similar in most cases.

Ad

Discuss this Article

Post your comments

Post Anonymously

Login

username
password
forgot password?

Register

username
password
confirm
email