-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add note on disabling default styles #11787
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
Changes from 2 commits
4541591
4186cd2
adaccca
6df1589
e3f1aea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -148,7 +148,9 @@ | |||||
|
|
||||||
| ## Overriding image styles | ||||||
|
|
||||||
| The responsive image component applies a small number of styles to ensure they resize correctly. The applied styles depend on the layout type, and are designed to give the best behavior for the generated `srcset` and `sizes` attributes. These are the default styles: | ||||||
| The responsive image component applies a small number of styles to ensure they resize correctly. The applied styles depend on the layout type, and are designed to give the best behavior for the generated `srcset` and `sizes` attributes. You can override them with your own styles, or disable them entirely by setting [`image.experimentalDefaultStyles`](/en/reference/configuration-reference/#imageexperimentaldefaultstyles) to `false` if you prefer to handle styling them yourself. | ||||||
|
Check failure on line 151 in src/content/docs/en/reference/experimental-flags/responsive-images.mdx
|
||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The "override or disable" made it sound like you could access these directly to rewrite, but really, if you set this to false, they just ARE disabled, right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can override them with your own styles (like any CSS) without disabling them, so it should be the default choice if someone just wants to change a single thing. It's only really Tailwind 4 that can't do it like that
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, the sentence before could be taken ambiguously as in "by setting false, you can override or disable". ~~( Let me take a shot at it so it's clear that the config option refers only to disabling entirely. |
||||||
|
|
||||||
| These are the default styles: | ||||||
|
|
||||||
| ```css title="Responsive Image Styles" | ||||||
| :where([data-astro-image]) { | ||||||
|
|
@@ -167,6 +169,6 @@ | |||||
|
|
||||||
| The styles use the [`:where()` pseudo-class](https://developer.mozilla.org/en-US/docs/Web/CSS/:where), which has a [specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_cascade/Specificity) of 0, meaning that it is easy to override with your own styles. Any class or tag name will have a higher specificity than `:where()`, so you can easily override the styles by adding your own class or tag name to the image. | ||||||
|
|
||||||
| Tailwind 4 is a special case, because it uses [cascade layers](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer), meaning the Tailwind rules are always lower specificity than rules that don't use layers. Astro supports browsers that do not support cascade layers, so it cannot use them for images. This means that if you need to override the styles using Tailwind 4, you must use [the `!important` modifier](https://tailwindcss.com/docs/styling-with-utility-classes#using-the-important-modifier). | ||||||
| Tailwind 4 is a special case, because it uses [cascade layers](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer), meaning the Tailwind rules are always lower specificity than rules that don't use layers. Astro supports browsers that do not support cascade layers, so it cannot use them for images. This means that [you should disable the default styles](/en/reference/configuration-reference/#imageexperimentaldefaultstyles) if you need to override them with Tailwind 4. | ||||||
|
Check failure on line 172 in src/content/docs/en/reference/experimental-flags/responsive-images.mdx
|
||||||
|
|
||||||
| For a complete overview, and to give feedback on this experimental API, see the [Responsive Images RFC](https://github.com/withastro/roadmap/blob/responsive-images/proposals/0053-responsive-images.md). | ||||||
Uh oh!
There was an error while loading. Please reload this page.