display和visibility的区别

style.visibility和style.display都可以实现对页的隐藏,但visibility要占用域的空间,而display则不占用
  • 将元素display属性设为 block,会在该元素后换行。
  • 将元素display属性设为 inline,会消除元素换行。
  • 将元素display属性设为 none,隐藏该元素内容,且不占用域的空间。
  • 将元素visibility属性设为 hidden,隐藏该元素内容,但占用域的空间。
  • 将元素visibility属性设为 visible,显示元素内容。
  • 占不占用域有什么影响呢?但好像推荐都用display;
  • <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8"/>
    <title>visibility and display different</title>
    <style>
           .test-display {
            display:none;
           }
           .test-visibility {
            visibility:hidden;
           }
    </style>
    </head>
    <body>
    <h1>Twilight</h1>
    <p>if you hard you will be more lucky!</p>
    <p>next will display;none!</p>
    <p class="test-display">so i will make this paragraph!</p>
    <p>next will visibility;hidden;</p>
    <p class="test-visibility">this paragraph use visibility;hidden</p>
    <p>let's begin!</p>
    </body>
    </html>
  • 运行结果是:
  • Twilight

    if you hard you will be more lucky!

    next will display;none!

    next will visibility;hidden;



  • let's begin!

  • 所以是visibility虽然隐藏了,但是还在占用位置,今天吴老师讲了,所以觉得应该试一下,以前都是看过而已


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值