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

box-sizing best practice #24357

Closed
Dunexus opened this issue Oct 13, 2017 · 7 comments
Closed

box-sizing best practice #24357

Dunexus opened this issue Oct 13, 2017 · 7 comments
Assignees
Labels

Comments

@Dunexus
Copy link

Dunexus commented Oct 13, 2017

Reading reboot.css, I saw you set box-sizing using

*,
*::before,
*::after {
    box-sizing: border-box;
}

instead of

html {
  box-sizing: border-box;
}
*, *:before, *:after {
  box-sizing: inherit;
}

Even if in most cases the first version would works fine, the second one allows devs to reset box-sizing for components designed to work in default box-sizing just by setting box-sizing : conten-box on the parent element.

Related article: Inheriting box-sizing Probably Slightly Better Best-Practice

@andresgalante
Copy link
Collaborator

Hi @Dunexus this is smart! (not surprisingly since it's coming from Chris Coyer)

@yuheiy
Copy link

yuheiy commented Oct 13, 2017

Is universal selector necessary for ::before and ::after?

@bkdotcom
Copy link
Contributor

bkdotcom commented Oct 13, 2017

@yuheiy, it's not required.
This will also work.

html {
  box-sizing: border-box;
}
*, ::before, ::after {
  box-sizing: inherit;
}

shouldn't we be using two-colons??
From MDN:

Note: As a rule, double colons (::) should be used instead of a single colon (:). This distinguishes pseudo-classes from pseudo-elements. However, since this distinction was not present in older versions of the W3C spec, most browsers support both syntaxes for the original pseudo-elements.

@mdo
Copy link
Member

mdo commented Oct 14, 2017

We reverted that approach in #23118 because of #22872.

@yuheiy
Copy link

yuheiy commented Oct 14, 2017

That approach is widely known. But it is not explicit why it is not being used. I think some comments are necessary in the code.

@andresgalante
Copy link
Collaborator

I'll close this issue for now, let's revisit the idea when chrome fixes the bog. Thanks @Dunexus

@Dunexus
Copy link
Author

Dunexus commented Nov 13, 2017

Related chromium bug tracker ticket : Box-Sizing does not inherit correctly inside <details>.

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

6 participants