Talking from hidden elements

Source: Internet
Author: User

Personal blog: Damonare's personal blog

Speaking of hidden elements I think every front of the ER can say a few, but can say the whole I think is not a lot. Bloggers summed up several methods of hiding elements, summarizing the following table:

Overflow opacity visibility display position Clip ( Clip-path) z-index
Property value Hidden 0 Hidden None Absolute Rect ()/inset ()/polygon () -1000

Why do we need so many ways to hide elements, and they all seem to achieve the same effect. In fact, each method is actually slightly different, and these differences determine which method to use in certain situations. Let's explore the nuances below. 1. Overflow

. hide{
     Overflow:hidden/* Occupy space, can not click * * 

the overflow hidden is used to hide the element overflow part, occupy the space, cannot respond to the Click event. 2.opacity

. hide{
    opacity:0;/* occupies space and can be clicked
/}. hide_2{
    -webkit-filter:opacity (0);
    Filter:opacity (0);/* occupy space, you can click */

Filter element filter can also use the opacity value to set transparency, but filter is now not compatible, only support the WebKit kernel, here incidentally.

opacity is used to set element transparency, but when set to 0 it is the equivalent of hiding elements. Therefore, the element still exists in its original position and occupies space and can respond to events. If you're going to use the opacity attribute to hide elements in the screen-reading software, unfortunately, you can't do it. The element and all its contents are read by the read-screen software, just like the other elements on the Web page. In other words, the behavior of elements is the same as when they are opaque. 3.visibility

. hide{
    Visibility:hidden/* Occupy space, can not click * *

as with the opacity attribute, the hidden elements will still work on our page layout. The only difference with opacity is that it does not respond to any user interaction. In addition, elements can be hidden in the read-screen software 4.display

. hide{
    display:none;/* does not occupy space, can not click * * 

The Classic display hidden elements, this is completely hidden elements, do not occupy space, also does not affect the layout, of course, can not respond to events. 5.position

. hide{
    top:-90999px;/* does not occupy space, can not click * *
    top:-90999px;/* occupy space, can not click * * 

Suppose there is an element that you want to interact with, but you don't want it to affect your page layout, there is no suitable attribute to handle this situation (opacity and visibility affect the layout, display does not affect the layout but cannot directly interact with the translator). In this case, you can only consider moving the element out of the viewable area. This approach will not affect the layout, there is the ability to keep the elements can be manipulated. It's not 6.clip/clip-path to adopt this approach

. hide{
    clip:rect (top,right,bottom,left);/* Occupy space, cannot click/ 
. hide_ 2 {
  Clip-path:polygon (0px 0px,0px 0px,0px 0px,0px 0px);

another way to hide elements is by trimming them. In the past, this can be done by clip properties, but this attribute is discarded (now browsers still support), and a better attribute is called Clip-path. Clip-path properties are really useful drop, you can easily achieve a number of complex graphics in the desert teachers to share a link, the link in most of the graphics are used Clip-path polygon value to achieve. Unfortunately, it is still only used in chrome40+ browsers. 7.z-index

. hide{
    z-index:-1000;/* does not occupy space, can not click * * 

The element is hidden by setting the Z-index value so that other elements are obscured. PostScript

In this tutorial, we looked at 7 different ways to hide elements through CSS. Each method is a little different from the others. Knowing what you want to achieve will help you decide which attribute to use, and over time you can instinctively choose the best way to meet your actual needs. If you have any questions about these methods of hiding elements, please leave a comment in the comments.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.