Home » CSS

The pointer-events Property in CSS

CSS | pointer-events Property: Here, we are going to learn about the pointer-events property with examples in CSS.
Submitted by Anjali Singh, on December 17, 2019

CSS | pointer-events Property

Pointers are the mouse cursors on the web page that are used to navigate and click an option.

Yes, pointers can also be formatted specifically. If you plan on carving every detail of your web page then you must not forget about pointers. To deal with pointers we use Pointer-events property in CSS.

The pointer-events property in CSS allows controlling how elements are supposed to react to mouse/touch events. It also specifies whether or not the cursor is visible.

Those are quite a load of features. Let us understand them with the following example,

Syntax:

Element {
    pointer-event: none|auto;
}

pointer-events Property values

1) auto

If we add auto as a prefix to something, we assume that the functionality would be automatic, which is quite true most of the time. The case is the same here, the element reacts to pointer events such as when we hover over an element. Thereby making the auto a default property of pointers-event.

Well, why stop at the definition? Go ahead and try the below-mentioned example,

Syntax:

Element {
    pointer-event: auto;
}

Example:

<!DOCTYPE html>

<html>

<head>
    <style>
        div {
            pointer-events: auto;
        }
    </style>
</head>

<body>
    <h2>Pointer-events in CSS</h2>
    <div>Go to <a href="https://www.includehelp.com/">IncludeHelp</a></div>
</body>

</html>

Output

CSS | the pointer-event property | Example 1

In the above example, hover over and click the link "IncludeHelp" to see the effect in the above example,

2) none

"none" is used when we do not want any task to be performed by the cursor. Therefore, this property prevents all click, state and cursor options on the specified element.

Let us try to understand this property much better with the help of an example,

Syntax:

Element {
    pointer-events: none;
}

Example:

<!DOCTYPE html>

<html>

<head>
    <style>
        div {
            pointer-events: none;
        }
    </style>
</head>

<body>
    <h2>Pointer-events in CSS</h2>
    <div>Go to <a href="https://www.includehelp.com/">IncludeHelp</a></div>
</body>

</html>

Output

CSS | the pointer-event property | Example 2

In the above example, if you hover over the "IncludeHelp" link you won't be able to click and go to the next page.

Tip: none should be used very wisely. As most of the time, we do want our cursor to perform some tasks but if you apply this property nothing would happen.







Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.