Home > Web Front-end > CSS Tutorial > Which of the several methods of hiding elements in css can trigger click events?

Which of the several methods of hiding elements in css can trigger click events?

angryTom
Release: 2019-10-24 17:31:34
Original
6481 people have browsed it

Which of the several methods of hiding elements in css can trigger click events?

Among the several ways to hide elements in css, the click event can be triggered by

with opacity set to 0 method.

How to hide elements in css:

1. display:none;

.box{
    display: none;
}
Copy after login

The simplest and most crude method is to set the display attribute of the element is none.

Elements set to display:none; will no longer occupy page space, and the space they occupy will be occupied by other elements, which will cause the browser to be rearranged and reassembled.

2. visibility: hidden

.box{
    visibility: hidden;
}
Copy after login

Although this method can hide the element, the element will still occupy the page space, so it will only cause the browser to reassemble but not reflow. .

If you want the element to be hidden without causing changes to the page layout, it is recommended to use the visibility:hidden; method.

3, opacity:0; (filter: alpha(opacity=0); both must be written to consider compatibility)

Set the element transparency opacity attribute to 0, you can also hide page elements .

.box{
    opacity:0;
}
Copy after login

is presented in the same way as visibility:hidden; and will also occupy page space.

Event binding differences:

display:none; The element will disappear directly from the page, so the event bound to the element will not Will take effect.

visibility: hidden; Elements will not trigger bound events .

opacity:0; The element will trigger the bound event, for example, clicking will trigger the click function.

For more HTML/css knowledge, you can follow the PHP Chinese website HTML video tutorial and CSS video tutorial

The above is the detailed content of Which of the several methods of hiding elements in css can trigger click events?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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