HTML5 的 hidden 属性和 css 的 display: none 有何区别?
阿神
阿神 2017-04-17 11:12:59
[HTML讨论组]

都可以隐藏 html 的内容,那么正确的使用场景应该是怎样的呢?

<!DOCTYPE html>
<html>
<body>



<p hidden="hidden">这是一段隐藏的段落。</p>





<p>这是一段可见的段落。</p>



</body>
</html>
阿神
阿神

闭关修行中......

全部回复(3)
迷茫

把以下几句读完就明白了:

This Boolean attribute indicates that the element is not yet, or is no longer, relevant. For example, it can be used to hide elements of the page that can't be used until the login process has been completed. The browser won't render such elements.

Usage notes:

  1. This attribute must not be used to hide content that could legitimately be shown. For example, it shouldn't be used to hide tabs panels of a tabbed interface, as this is a styling decision and another style showing them would lead to a perfectly correct page.
  2. Hidden elements shouldn't be linked from non-hidden elements.
  3. Elements that are descendants of a hidden element are still active, which means that script elements can still execute and form elements can still submit.
  4. Changing the display CSS value of an element with the hidden attribute overrides the behavior. For instance, an element styled display: flex will be displayed on screen regardless of the hidden attribute being present.
巴扎黑

效果其实都是一样的,隐藏后不占位

巴扎黑

none不占位,hidden占位,应该是这样。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号