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: flex-basis vs width #39

Open
AndreGeng opened this issue May 7, 2019 · 0 comments
Open

css: flex-basis vs width #39

AndreGeng opened this issue May 7, 2019 · 0 comments

Comments

@AndreGeng
Copy link
Owner

AndreGeng commented May 7, 2019

一直感觉这两个属性比较像,有点困惑,今天尝试列举下它们的不同。

  1. 首先flex-basis并不一定是拿来和width做对比的,这取决于flex-direction的值,值为column的话,它控制的就是height了,这里假设值为row
  2. flex-basis是一个初始值,例如container宽100px, display为flex, 子元素flex-basis设为10px, flex-grow为1. 那得到的结果为flex-basis: 10px; width会变为100px
  3. 再者考虑flex-basis的取值,它的合法值除了可以width/height可选的值外,还可以设为content. 既合法值包括数字值,auto, content.
    3.1 对于'auto'和'content'以外的属性值,它的效果和设置width一样
    3.2 对于'auto', 它会去读width的值,如果width也为‘auto’, 那flex-basis的效果与值为‘content’效果一致
    3.3 'content',基于item内容的大小
  4. flex-basis是会被min/max-width所限制的
    ps:
Authors are encouraged to control flexibility using the flex shorthand 
rather than with flex-basis directly, as the shorthand correctly resets 
any unspecified components to accommodate common uses.

Reference:
flex-basis-property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant