Last updated on December 15, 2009. Tags: block elements, cross browser compatibility, link hover, mouse pointer
This trick allows you to setup the mouse pointer (a.k.a. mouse cursor) to any part or block elements of a web page. All you need to do is to setup the CSS code that dictates the mouse type to whatever part, inline element or block element.
For example, you can setup the cursor for links using the following CSS codes:
a {cursor: crosshair;}
In the above code, you can change the mouse pointer that hovers on the link into a crosshair, something like this when you hover your mouse pointer on this text. You can place it in the CSS in the header section, in an external CSS file or in an inline style attribute (just like what we did in the italicized text in this paragraph).
You can also implement it in several different inline elements and block elements such as paragraph <p>, list <ul> or <ol>, item list <li>, as well as IDs and classes. The page in the iframe below implements different mouse pointers in paragraph, list items and block elements defined by a class and an ID.
The CSS for the page in the iframe above is shown below. The code that determines the mouse pointer type is in bold face:
/*elements*/
p {cursor: help; clear: both;}
li {cursor: move; clear: both; }
/*class*/
.leftblock {cursor: wait; width: 200px; margin: 5px; border: 1px solid #0000ff; float: left;}
/*ID*/
#rightblock {cursor: pointer; width: 200px; margin: 5px; border: 1px solid #ff0000; float: left;}
Below are the possible different values of cursor CSS attribute. Hover your mouse pointer on the list item to see how each of them looks like.
There is actually another value of cursor attribute not included in the list: it is cursor: url(); which is used if you intend to have a unique mouse pointer that you created or downloaded (the extension file is either .cur or .ani). It was covered in this article: Using customized mouse pointer on your webpage.
Posted by Greten on April 29, 2009 under Cascading Stylesheet (CSS)
Please double check your comment before clicking the "Post" button. Once you clicked it, there will be no way for you to edit your comment.
* Required. Your email will never be displayed in public.