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

CSS盒模型 #3

Open
mbaxszy7 opened this issue Jun 16, 2020 · 0 comments
Open

CSS盒模型 #3

mbaxszy7 opened this issue Jun 16, 2020 · 0 comments
Labels

Comments

@mbaxszy7
Copy link
Owner

mbaxszy7 commented Jun 16, 2020

记录一下CSS盒模型

盒模型

content-box:W3C 标准盒模型

  • width,height只包含内容content区域,不包含border和padding

border-box: IE 盒模型

  • width 和 height 包含content+padding+border

从计算上看,border-box更符合人的直觉,比如实际生活中的纸盒子.

项目中设置盒模型

如果由第三方库不兼容box-sizing: border-box,则可以如下设置

  : root { box-sizing: border-box; }
  *,
  ::before,
  ::after {
    box-sizing: inherit;
  }
// 这样的话不会破坏第三方组件可能改变的box-sizing
// 可以在必要时选中第三方组件的顶级容器,将其恢复为 content-box
.third-party-component { box-sizing: content-box; }

CSS in Depth

@mbaxszy7 mbaxszy7 added the css label Jun 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant