Home  >  Article  >  Web Front-end  >  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
angryTomOriginal
2019-10-22 14:03:026254browse

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;
}

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;
}

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;
}

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!

Statement:
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