Home > Web Front-end > CSS Tutorial > How to disable clicking on elements in css

How to disable clicking on elements in css

WBOY
Release: 2021-11-25 18:43:05
Original
4043 people have browsed it

In CSS, you can use the pointer-events attribute to achieve the click ban effect. This attribute is used to define whether the element responds to pointer events. You only need to add the "pointer-events:none" style to the element. Can.

How to disable clicking on elements in css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

How to prohibit clicks on elements in css

In css, you can set the pointer-events attribute of the element to none to prevent the element from being clickable. Click. This method makes the element unclickable by setting the mouse event of the element to invalid.

The pointer-events attribute defines whether the element reacts to pointer events.

The syntax of this attribute is:

pointer-events: auto|none;
Copy after login

How to disable clicking on elements in css

Let’s take a look at how to prohibit clicking on an element based on an example. The example is as follows:

<!DOCTYPE html>
<html>
<head>
<style> 
div.ex1 {
  pointer-events: none;
}
div.ex2 {
  pointer-events: auto;
}
</style>
</head>
<body>
<h2>pointer-events: none:</h2>
<div class="ex1">访问 <a href="https://www.w3school.com.cn/html/">HTML 教程</a></div>
<h2>pointer-events: auto(默认)</h2>
<div class="ex2">访问 <a href="https://www.w3school.com.cn/css/">CSS 教程</a></div>
</body>
</html>
Copy after login

Output result:

How to disable clicking on elements in css

When adding the "pointer-events: none;" style, the originally clickable link elements are no longer clickable.

(Learning video sharing: css video tutorial)

The above is the detailed content of How to disable clicking on elements in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template