html隐藏标签属性(二)

简介: html隐藏标签属性

区别:

display: none visibility: hidden opacity: 0
页面中 不存在 存在 存在
重排 不会 不会
重绘 不一定
自身绑定事件 不触发 不触发 可触发
transition 不支持 支持 支持
子元素可复原 不能 不能
被遮挡的元素可触发事件 不能
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS几种隐藏元素的方法大全</title>
  </head>
  <style>
    .w_vis-hid-outer {
      background-color: steelblue;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      margin-bottom: 42px;
    }
    .w_vis-hid-outer p {
      line-height: 62px;
      padding: 0 24px;
    }
    .w_l-con {
      background-color: tomato;
    }
    .w_r-con {
      background-color: yellowgreen;
    }
    /* visibility: hidden 设置隐藏 */
    .w_now-vis {
      background-color: brown;
      margin: 0 12px;
      /* visibility: hidden; */
    }
    .w_opac-hid-outer {
      background-color: slategray;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      padding: 0 12px;
      margin-bottom: 42px;
    }
    .w_opac-hid-outer p {
      line-height: 62px;
      padding: 0 24px;
    }
    .w_l-opa-con {
      background-color: snow;
    }
    .w_r-opa-con {
      background-color: tan;
    }
    /* opacity: 0  设置隐藏 */
    .w_now-opac {
      background-color: skyblue;
      margin: 0 12px;
      /* opacity: 0; */
    }
    .w_posi-hid-outer {
      background-color: slategray;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      padding: 0 12px;
      margin-bottom: 42px;
    }
    .w_posi-hid-outer p {
      line-height: 62px;
      padding: 0 24px;
    }
    .w_l-pos-con {
      background-color: snow;
      margin-right: 12px;
    }
    .w_r-pos-con {
      background-color: tan;
      margin-left: 12px;
    }
    /* opacity: 0  设置隐藏 */
    .w_now-posi {
      background-color: skyblue;
      /* position: absolute; */
      /* left: -6666px; */
    }
    .w_disp-hid-outer {
      background-color: red;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      padding: 0 12px;
      margin-bottom: 42px;
    }
    .w_disp-hid-outer p {
      line-height: 62px;
      padding: 0 24px;
    }
    .w_l-dis-con {
      background-color: #ccc;
      margin-right: 12px;
    }
    .w_r-dis-con {
      background-color: #212121;
      margin-left: 12px;
      color: #FFF;
    }
    /* display: none  设置隐藏 */
    .w_now-disp {
      background-color: blueviolet;
      /* display: none; */
    }
    .w_trans-hid-outer {
      background-color: darkorange;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      padding: 0 12px;
      margin-bottom: 42px;
    }
    .w_trans-hid-outer p {
      line-height: 62px;
      padding: 0 24px;
    }
    .w_l-tran-con {
      background-color: #ccc;
      margin-right: 12px;
    }
    .w_r-tran-con {
      background-color: #212121;
      margin-left: 12px;
      color: #FFF;
    }
    /* transform: scale(0)  设置隐藏 */
    .w_now-trans {
      background-color: blueviolet;
      /* transform: scale(0); */
    }
    .w_hidd-hid-outer {
      background-color: darksalmon;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      padding: 0 12px;
      margin-bottom: 42px;
    }
    .w_hidd-hid-outer p {
      line-height: 62px;
      padding: 0 24px;
    }
    .w_l-hid-con {
      background-color: steelblue;
      margin-right: 12px;
    }
    .w_r-hid-con {
      background-color: #212121;
      margin-left: 12px;
      color: #FFF;
    }
    /* hidden attribute  设置隐藏 (在 html 元素标签上设置) */
    .w_now-hidd {
      background-color: red;
    }
  </style>
  <body>
    <div>
      <!-- visibility: hidden  方法 -->
      <div>
        <p>左侧元素 -- 方法 1: visibility: hidden</p>
        <p>中间 隐藏 元素</p>
        <p>右侧元素 -- 方法 1: visibility: hidden</p>
      </div> <!-- opacity: 0  方法-->
      <div>
        <p>左侧元素 -- 方法 2: opacity: 0</p>
        <p>中间 隐藏 元素</p>
        <p>右侧元素 -- 方法 2: opacity: 0</p>
      </div> <!-- position: absolute 方法 -->
      <div>
        <p>左侧元素 -- 方法 3: position: absolute</p>
        <p>中间 隐藏 元素</p>
        <p>右侧元素 -- 方法 3: position: absolute</p>
      </div> <!-- display: none -->
      <div>
        <p>左侧元素 -- 方法 4: display: none</p>
        <p>中间 隐藏 元素</p>
        <p>右侧元素 -- 方法 4: display: none</p>
      </div> <!-- transform: scale(0) -->
      <div>
        <p>左侧元素 -- 方法 5: display: none</p>
        <p>中间 隐藏 元素</p>
        <p>右侧元素 -- 方法 5: display: none</p>
      </div> <!-- hidden attribute -->
      <div>
        <p>左侧元素 -- 方法 6: hidden attribute</p>
        <p>中间 隐藏 元素</p> <!-- <p hidden="true">中间  隐藏  元素</p> -->
        <p>右侧元素 -- 方法 6: hidden attribute</p>
      </div>
    </div>
  </body>
</html>
相关文章
|
人工智能 前端开发 UED
1分钟解锁属性:HTML中的列表标签属性
1分钟解锁属性:HTML中的列表标签属性
|
前端开发 JavaScript
|
移动开发 HTML5
HTML5 标签释义 CSS3属性释义
HTML5 标签释义 CSS3属性释义
265 0
HTML5 标签释义 CSS3属性释义
html中a标签属性parent和self的举例说明
html中a标签属性parent和self的举例说明
541 0
html中a标签属性parent和self的举例说明
|
移动开发 HTML5
html5基本标签属性
图片标签、路径、超链接标签
|
移动开发 HTML5
HTML5 a标签的download属性
介绍一个HTML5的新特性 a标签的download属性; 目前市场上面支持的浏览器有限; html: DOCTYPE html> 点击 W3School 的 logo 来下载该图片:     参考链接: http://www.
2707 0
|
JavaScript
在VSCode中编辑HTML文档时,在Dom标签上写style属性时智能提示的问题
首先在VSCode中打开一个HTML文件 然后点右下角的“选择语言模式” 然后点击配置HTML语言的基础设置 然后在打开的界面中(右侧) 输入如下代码 { "editor.quickSuggestions": { "other": true, "comments": tr...
2202 0
|
Web App开发 移动开发 JavaScript
HTML5中&lt;script&gt;标签中的defer与async属性详解
   在HTML中执行脚本最重要的方法就是使用&lt;script&gt;元素,但是执行&lt;script&gt;元素时会阻塞后面文档的加载。 那么首先为什么会阻塞呢,是由于哪些原因呢? 其实是&lt;script&gt;标签中的src属性在作怪,因为一个src就相当于一次http请求,他的作用就是把src所对应的地址上的文档下载到本地,因此当浏览器碰到&lt;scrip
1564 0