We often need to control the hidden, transparent and other properties of some elements on the web page <style> .d1{ display: none; } .d2{ visibility: visible; } .d3{ opacity: 0; } </style> <div class="d1" onclick="clickEvent('display: none;')"></div> <div class="d2" onclick="clickEvent('visibility: hidden;')"></div> <div class="d3" onclick="clickEvent('opacity: 0;')"></div> <script type="text/javascript"> function clickEvent(type){ alert(type) } </script> display: none;
visibility: hidden;
opacity: 0;
rgb
z-index: -1
A little experiment You can try it yourself and play it. //html <div class="container"> <div class="target"> <p>I am target, and you?</p> </div> </div> // css <style> .container{ margin: 0 auto; width: 500px; min-height: 30px; background-color: skyblue; } .target{ width: 200px; height: 50px; line-height: 50px; text-align: center; margin: 0 auto; background-color: plum; color: #fff; transition: all linear 1s; cursor: pointer; } .clickBlock{ display: none; } .clickVisibility{ visibility: hidden; } .clickOpacity{ opacity: 0; } .clickRgba{ background-color: rgba(221, 160, 221, 0); } .clickZindex{ z-index: -1; position: absolute; } </style> // js const _target = document.getElementsByClassName("target")[0]; _target.onclick = (() => { let i = 1; // click times return () => { // _target.attributes.class.value += " clickBlock"; // _target.attributes.class.value += " clickVisibility"; // _target.attributes.class.value += " clickOpacity"; // _target.attributes.class.value += " clickRgba"; _target.attributes.class.value += " clickZindex"; console.log(`${i}th click`); i++; }})(); This is the end of this article about the differences between Display, Visibility and Opacity in CSS. For more information about CSS controlling hidden content, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! |
<<: Detailed steps to expand LVM disk in Linux
>>: How to implement mobile web page size adaptation
Log in to MySQL first shell> mysql --user=root...
Vue recommends using templates to create your HTM...
IE gave us a headache in the early stages of deve...
This article uses examples to illustrate the func...
What are :is and :where? :is() and :where() are p...
Overlay network analysis Built-in cross-host netw...
In daily operation and maintenance work, nginx se...
Because the Raspberry Pi is based on ARM architec...
This article mainly introduces the example analys...
This article discusses several major zero-copy te...
This article example shares the specific code of ...
WeChat applet: Simple calculator, for your refere...
Table of contents Solution 1 Solution 2 When crea...
Preface As you all know, we have encountered many...
1. Add the plug-in and add the following configur...