Skip to content

Commit c71bdfc

Browse files
Add note about issues with popover default styles (mdn#40723)
* Add note about issues with popover default styles * Tweaks * Update popover positioning notes to include links to default styles
1 parent cda46c8 commit c71bdfc

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

files/en-us/web/api/popover_api/using/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ For example, you could use a combination of {{cssxref("anchor()")}} function val
434434

435435
```css
436436
.my-popover {
437+
margin: 0;
438+
inset: auto;
437439
bottom: calc(anchor(top) + 20px);
438440
justify-self: anchor-center;
439441
}
@@ -443,10 +445,14 @@ Or you could use a {{cssxref("position-area")}} property:
443445

444446
```css
445447
.my-popover {
448+
margin: 0;
449+
inset: auto;
446450
position-area: top;
447451
}
448452
```
449453

454+
When using {{cssxref("position-area")}} or {{cssxref("anchor()")}} to position popovers, be aware that [the default styles for popovers](https://html.spec.whatwg.org/multipage/rendering.html#flow-content-3:~:text=%5Bpopover%5D%20%7B) may conflict with the position you're trying to achieve. The usual culprits are the default styles for `margin` and `inset`, so it's advisable to reset those, as in the examples above. The CSS working group is [looking at ways to avoid requiring this workaround](https://github.com/w3c/csswg-drafts/issues/10258).
455+
450456
See [Using CSS anchor positioning](/en-US/docs/Web/CSS/CSS_anchor_positioning/Using#positioning_elements_relative_to_their_anchor) for more details on associating anchor and positioned elements, and positioning elements relative to their anchor.
451457

452458
> [!NOTE]

files/en-us/web/css/anchor/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ The below table lists the inset properties, and the `<anchor-side>` parameter va
131131
| `inset-block-start` and `inset-block-end` | `start`, `end`, `self-start`, and `self-end`<br>`top` and `bottom` in horizontal writing modes<br>`left` and `right` in vertical writing modes |
132132
| `inset-inline-start` and `inset-inline-end` | `start`, `end`, `self-start`, and `self-end`<br>`left` and `right` in horizontal writing modes<br>`top` and `bottom` in vertical writing modes |
133133

134+
### Using `anchor()` to position popovers
135+
136+
When using `anchor()` to position [popovers](/en-US/docs/Web/HTML/Reference/Global_attributes/popover), be aware that [the default styles for popovers](https://html.spec.whatwg.org/multipage/rendering.html#flow-content-3:~:text=%5Bpopover%5D%20%7B) may conflict with the position you're trying to achieve. The usual culprits are the default styles for `margin` and `inset`, so it's advisable to reset those:
137+
138+
```css
139+
.positionedPopover {
140+
margin: 0;
141+
inset: auto;
142+
}
143+
```
144+
145+
The CSS working group is [looking at ways to avoid requiring this workaround](https://github.com/w3c/csswg-drafts/issues/10258).
146+
134147
### Using `anchor()` inside `calc()`
135148

136149
When the `anchor()` function refers to a side of the default anchor, you can include a {{cssxref("margin")}} to create spacing between the edges of the anchor and positioned element as needed. Alternatively, you can include the `anchor()` function within a {{cssxref("calc")}} function to add spacing.

files/en-us/web/css/position-area/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ If the positioned element is placed in a single top-center, bottom-center, or ce
115115

116116
If the positioned element is placed in any other single grid square (say with `position-area: top left`) or is set to span two or more grid squares (for example using `position-area: bottom span-all`), it will align with the specified grid area but behave as if it has a {{cssxref("width")}} of `max-content` set on it. It is being sized according to its containing block size, which is the size imposed on it when it was set to `position: fixed`. It will stretch as wide as the text content, although it may also be constrained by the edge of the `<body>`.
117117

118+
### Using `position-area` to position popovers
119+
120+
When using `position-area` to position [popovers](/en-US/docs/Web/HTML/Reference/Global_attributes/popover), be aware that [the default styles for popovers](https://html.spec.whatwg.org/multipage/rendering.html#flow-content-3:~:text=%5Bpopover%5D%20%7B) may conflict with the position you're trying to achieve. The usual culprits are the default styles for `margin` and `inset`, so it's advisable to reset those:
121+
122+
```css
123+
.my-popover {
124+
margin: 0;
125+
inset: auto;
126+
}
127+
```
128+
129+
The CSS working group is [looking at ways to avoid requiring this workaround](https://github.com/w3c/csswg-drafts/issues/10258).
130+
118131
## Formal definition
119132

120133
{{cssinfo}}

0 commit comments

Comments
 (0)