-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃摉 Document media query attributes #32789
Changes from all commits
a6a2be7
a087958
b5c145a
917d010
e8f55b1
48d084d
2a7ac9b
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<!--- | ||
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. This looks good. But to confirm: this doc file we'll end up on 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. If it is automatic, I would expect it to go to https://amp.dev/documentation/guides-and-tutorials/learn/amp-html-responsive-attributes based on where AMP's Layout system and AMP Action and events are located (also in this 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. I've opened a PR that should add it to the imported documents for amp.dev here: |
||
Copyright 2021 The AMP HTML Authors. All Rights Reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS-IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
# AMP HTML Responsive Attributes | ||
|
||
You can apply or remove certain attributes based on screen size. These are responsive attributes, or media attributes. On eligible components, these attributes are applied or removed based on media queries. You can also use a value without any media queries. Media queries evaluate from from left to right, applying the first matching media query. You must include a default value with no media query. | ||
|
||
[tip type="note"] | ||
|
||
Responsive attributes do not require media queries. You may apply media query eligible attributes the same as regular attributes: `attr-name="attr-value"`. | ||
|
||
[/tip] | ||
|
||
To apply this behavior to an attribute, use the following format: | ||
|
||
```html | ||
<amp-component | ||
attr-name="(min-width: 1000px) valueOne, (min-width: 600px) valueTwo, defaultValue" | ||
></amp-component> | ||
``` | ||
|
||
In the example above, if the page has a screen of `1000px` or more, it applies `valueOne`. If the width is between `999px` and `600px`, it applies `valueTwo`. When the screen is `599px` or smaller, it applies the `defaultValue`. | ||
|
||
The following `amp-base-carousel` will show `3` slides at a time when width is greater than or equal to `800px`, and `2` otherwise. | ||
|
||
[example preview="top-frame" playground="true" imports="amp-base-carousel:1.0"] | ||
|
||
```html | ||
<amp-base-carousel | ||
width="900" height="200" | ||
layout="responsive" | ||
visible-count="(min-width: 800px) 3, 2"> | ||
<amp-img src="./img/redgradient.png" layout="flex-item"></amp-img> | ||
<amp-img src="./img/greengradient.png" layout="flex-item"></amp-img> | ||
<amp-img src="./img/bluegradient.png" layout="flex-item"></amp-img> | ||
<amp-img src="./img/orangegradient.png" layout="flex-item"></amp-img> | ||
<amp-img src="./img/tealgradient.png" layout="flex-item"></amp-img> | ||
<amp-img src="./img/lemonyellowgradient.png" layout="flex-item"></amp-img> | ||
<amp-img src="./img/lilacgradient.png" layout="flex-item"></amp-img> | ||
</amp-base-carousel> | ||
``` | ||
|
||
[/example] | ||
|
||
## Eligible components | ||
|
||
You may apply responsive attribute values to the following components: | ||
|
||
- [amp-base-carousel](./../extensions/amp-base-carousel/amp-base-carousel.md) | ||
- [amp-inline-gallery-pagination](./../extensions/amp-inline-gallery/amp-inline-gallery.md#include-pagination-indicators) | ||
- [amp-inline-gallery-thumbnails](./../extensions/amp-inline-gallery/amp-inline-gallery.md#include-pagination-thumbnails) | ||
- [amp-stream-gallery](./../extensions/amp-stream-gallery/amp-stream-gallery.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do all attributes allow media queries in this component and all others? Or should we come up with some sort of flag per-attribute. E.g. "visible-count (media allowed)"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the ones that are eligible currently are that way for all of their attributes. Hence there is this one section which says so at the top of the
## Attributes
section. It may not be this way going forward for new components that adopt this, but that pattern you recommended is a good one in that case.