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 specificity example #1642

Closed
sarah11918 opened this issue Sep 29, 2022 · 8 comments · Fixed by #1648
Closed

CSS specificity example #1642

sarah11918 opened this issue Sep 29, 2022 · 8 comments · Fixed by #1648
Labels
help wanted Issues looking for someone to run with them! improve documentation Enhance existing documentation (e.g. add an example, improve description)

Comments

@sarah11918
Copy link
Member

sarah11918 commented Sep 29, 2022

Make sure the order of CSS styles applied is clearly documented, as per the description here: withastro/astro#3357 (comment)

I propose adding this right before CSS Integrations as an <h2> maybe ## CSS Specificity or ## Style Specificity (See attached screenshot for placement) since it builds off of both the Astro <style> tag and importing external spreadsheets described in the two sections above.

Further to Matthew's comment, I propose using ## Cascading Order to incorporate both specificity and order of appearance when we give an example of "what should happen."

This is now how it's intended to work, and should be documented as true. If people find it doesn't work that way, it's a bug and should be reported as an Issue in withastro/astro, not changed in documentation.
Screenshot 2022-09-29

@sarah11918 sarah11918 added improve documentation Enhance existing documentation (e.g. add an example, improve description) help wanted Issues looking for someone to run with them! labels Sep 29, 2022
@matthewp
Copy link
Contributor

Specificity is the weight of selectors, iirc, and order is something else if I'm reading this note correctly: https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity

From this: https://developer.mozilla.org/en-US/docs/Web/CSS/Cascade#cascading_order I think ordering is being called Order of appearance.

So probably the heading shouldn't be CSS Specificity but something else that both covers specificity of Astro styles (via our :where() usage and ordering which is what the linked issue comment was about.

@sarah11918
Copy link
Member Author

Great link. Sounds like "Order of appearance" is one of the 4 factors taken into consideration to determine the Cascading Order, with Specificity being another.

So, I think that "Cascading Order" should include both, and will be a heading that is meaningful to people searching. I'm going to update the original comment suggesting that heading!

@jasikpark
Copy link
Contributor

It could be good to link to example stackblitz projects for these too maybe?

@jasikpark
Copy link
Contributor

It'd be good to document how tailwind and other css libs interact, right? or does that fall into "global styles that you import into your astro files"

@matthewp
Copy link
Contributor

Tailwind uses injectScript integration API which puts an import statement at the top of your page files. So it's the same as you importing a CSS file first, before other imports. But since Tailwind is widely used it wouldn't be a bad thing to explain that too.

@jasikpark
Copy link
Contributor

Just thinking how it might be nice to have an explanation of how we expect all of it to resolve, so that we know what we expect the CSS to look like & so we know when it's resolved incorrectly in that case

@sarah11918
Copy link
Member Author

sarah11918 commented Sep 29, 2022

Quick note to check on and include in documentation: if importing multiple components (e.g. a layout and another component), the order of the import statments might affect the cascading order as mentioned here: https://discord.com/channels/830184174198718474/1012063538786873464/1025174614940336128

@jasikpark
Copy link
Contributor

Quick note to check on and include in documentation: if importing multiple components (e.g. a layout and another component), the order of the import statments might affect the cascading order as mentioned here: https://discord.com/channels/830184174198718474/1012063538786873464/1025174614940336128

that's what i'm experiencing with 1.4.0 at least - i need to make sure that my layout that contains my global styles is the first import for my page so that those styles are added to the head first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issues looking for someone to run with them! improve documentation Enhance existing documentation (e.g. add an example, improve description)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants