Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display: none和visibility: hidden的区别 #26

Open
JCHappytime opened this issue Mar 4, 2021 · 0 comments
Open

display: none和visibility: hidden的区别 #26

JCHappytime opened this issue Mar 4, 2021 · 0 comments
Labels
CSS 样式相关问题

Comments

@JCHappytime
Copy link
Owner

JCHappytime commented Mar 4, 2021

前言

在使用CSS隐藏一些元素的时候,我们经常用到display: none和visibility: hidden。那么2者之间有什么不一样呢。

占据空间与否

  • display: none 不占据任何空间,文档渲染时,这个元素就像不存在一样。
  • visibility: hidden 该元素空间仍然存在。

是否渲染

  • display: none 会触发reflow回流,进行渲染。
  • visibility: hidden 只会触发repaint重绘,因为没有发现位置改变,不进行渲染。

是否有继承属性

  • display: none,display不是继承属性,元素及其子元素都会消失。
  • visibility: hidden,visibility是继承属性,如果子元素使用了visibility: visible,则不继承,这个子元素又会显示出来。
@JCHappytime JCHappytime added the CSS 样式相关问题 label Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS 样式相关问题
Projects
None yet
Development

No branches or pull requests

1 participant