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

Editorial review: CSS Anchor Positioning landing page and guide #33058

Merged
merged 70 commits into from
Jun 20, 2024
Merged
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
9e31158
CSS Anchor Positioning landing page and tutorial
chrisdavidmills Apr 12, 2024
20bf5f6
Merge branch 'main' into css-anchor-positioning-1
chrisdavidmills Apr 15, 2024
8ec419d
first part of guide
chrisdavidmills Apr 15, 2024
b197523
Add anchor() example
chrisdavidmills Apr 17, 2024
4d0836d
Add description and example of inst-area
chrisdavidmills Apr 17, 2024
b6012eb
Another couple fo sections done
chrisdavidmills Apr 30, 2024
50dabaa
Merge branch 'main' into css-anchor-positioning-1
chrisdavidmills May 1, 2024
93204bc
Final content updates
chrisdavidmills May 3, 2024
3df35bc
Merge branch 'main' into css-anchor-positioning-1
chrisdavidmills May 3, 2024
3072147
Add inset-area() function to landing page
chrisdavidmills May 3, 2024
759020f
Merge branch 'css-anchor-positioning-1' of github.com:chrisdavidmills…
chrisdavidmills May 3, 2024
8b44357
Fixes for mfreed7 review comments
chrisdavidmills May 7, 2024
3a1eab2
Merge branch 'main' into css-anchor-positioning-1
chrisdavidmills May 7, 2024
0a64f95
Few more fixes for mfreed7 review comments
chrisdavidmills May 12, 2024
ee4f0c2
Update the position-try-order demo to use inset properties rather tha…
chrisdavidmills May 14, 2024
30de3ec
Merge branch 'main' into css-anchor-positioning-1
chrisdavidmills May 14, 2024
25b4efd
Remove position-try-order
chrisdavidmills May 15, 2024
998bcf1
Merge branch 'main' into css-anchor-positioning-1
chrisdavidmills May 15, 2024
a7f7f15
typo fix
chrisdavidmills May 15, 2024
0b17054
add back position-try-order
chrisdavidmills May 16, 2024
7a2a558
Merge branch 'main' into css-anchor-positioning-1
chrisdavidmills May 16, 2024
02b65b6
Update files/en-us/web/css/css_anchor_positioning/index.md
chrisdavidmills May 24, 2024
4ab329c
Update files/en-us/web/css/css_anchor_positioning/index.md
chrisdavidmills May 24, 2024
c704730
Update files/en-us/web/css/css_anchor_positioning/index.md
chrisdavidmills May 24, 2024
95abeca
Update files/en-us/web/css/css_anchor_positioning/index.md
chrisdavidmills May 24, 2024
f553a16
Update files/en-us/web/css/css_anchor_positioning/index.md
chrisdavidmills May 24, 2024
e6aaf4d
Update files/en-us/web/css/css_anchor_positioning/index.md
chrisdavidmills May 24, 2024
5b9fea7
Partial fixes; more to come
chrisdavidmills May 25, 2024
efc36f2
Fixes for estelle review comments
chrisdavidmills May 27, 2024
1237adf
Merge branch 'main' into css-anchor-positioning-1
chrisdavidmills May 27, 2024
b1a6a23
Update files/en-us/web/css/css_anchor_positioning/index.md
chrisdavidmills May 30, 2024
1d95627
Next round of fixes for estelle review comments
chrisdavidmills May 31, 2024
5affd38
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills May 31, 2024
319b01e
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills May 31, 2024
d90b1fb
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills May 31, 2024
febeb77
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills May 31, 2024
7df5a41
Update files/en-us/web/css/css_anchor_positioning/index.md
chrisdavidmills May 31, 2024
3c86b63
Merge branch 'main' into css-anchor-positioning-1
chrisdavidmills May 31, 2024
be3fa5c
change anchor name to be more distinct and less confusion
chrisdavidmills May 31, 2024
d9b0703
Split guide into two
chrisdavidmills Jun 4, 2024
e59c317
Merge branch 'main' into css-anchor-positioning-1
chrisdavidmills Jun 4, 2024
c6dd389
Added link to inset-area type
chrisdavidmills Jun 5, 2024
a8b9dee
fixes for estelle review comments
chrisdavidmills Jun 6, 2024
2e5fb62
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills Jun 6, 2024
27650a9
Update files/en-us/web/css/css_anchor_positioning/try_options_hiding/…
chrisdavidmills Jun 6, 2024
4a35de4
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills Jun 6, 2024
2f19e93
Update files/en-us/web/css/css_anchor_positioning/try_options_hiding/…
chrisdavidmills Jun 6, 2024
2dd3330
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills Jun 6, 2024
2d542f5
small terminology fix
chrisdavidmills Jun 6, 2024
3080bfe
module page suggestions
estelle Jun 7, 2024
8c9557b
Edits to the first guide
estelle Jun 8, 2024
1ba2c5a
update inset-area row and column values info
chrisdavidmills Jun 11, 2024
da5217c
Merge pull request #2 from mdn/ap1
chrisdavidmills Jun 11, 2024
1938693
Merge pull request #3 from mdn/ap1-guide1
chrisdavidmills Jun 11, 2024
f8dad40
a few fixes to make
chrisdavidmills Jun 11, 2024
32d6904
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills Jun 11, 2024
e716b52
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills Jun 15, 2024
c3d139f
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills Jun 15, 2024
856795c
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills Jun 15, 2024
51012ab
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills Jun 15, 2024
0897b72
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills Jun 15, 2024
ae88d9a
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills Jun 15, 2024
fd7befd
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills Jun 15, 2024
3b5e5b7
Update files/en-us/web/css/css_anchor_positioning/using/index.md
chrisdavidmills Jun 15, 2024
c580a57
Update files/en-us/web/css/css_anchor_positioning/using/inset-area.dr…
chrisdavidmills Jun 15, 2024
4072d32
Final fixes to using guide
chrisdavidmills Jun 15, 2024
60390c7
Merge branch 'main' into css-anchor-positioning-1
chrisdavidmills Jun 15, 2024
1898599
Add anchor() info to make association vs position clear, and clarify …
chrisdavidmills Jun 18, 2024
b9f13a5
Fixes for estelle review comments
chrisdavidmills Jun 19, 2024
b3a3905
Merge branch 'main' into css-anchor-positioning-1
chrisdavidmills Jun 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add anchor() example
  • Loading branch information
chrisdavidmills committed Apr 17, 2024
commit b197523a8b436b6bb4dc2e9caa193c7b17fbfbfc
89 changes: 87 additions & 2 deletions files/en-us/web/css/css_anchor_positioning/using/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The anchor and infobox are now associated together, but for the moment you'll ha

### Via HTML
chrisdavidmills marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Via HTML
### Using HTML attributes

it's only two attributes in the html. all else is CSS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used "HTML method" for this, to make it consistent with the earlier change to the CSS heading.


Associating an anchored element with an anchor is even simpler in HTML. You need to give the anchor element an ID, and then reference that ID in the anchored element's [`anchor`](/en-US/docs/Web/HTML/Global_attributes/anchor) attribute:
To associate an anchored element with an anchor in HTML, you need to give the anchor element an ID, and then reference that ID in the anchored element's [`anchor`](/en-US/docs/Web/HTML/Global_attributes/anchor) attribute:

```html
<div class="anchor" id="example-anchor">⚓︎</div>
Expand Down Expand Up @@ -171,7 +171,92 @@ The most common `anchor()` functions you'll use will just refer to a side of the
}
```

Let's look at an example of this in action ... GOT HERE
Let's look at an example of this in action. We'll start with the same HTML as in the previous examples, but with some filler text below and above to give the {{htmlelement("body")}} element some height:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Let's look at an example of this in action. We'll start with the same HTML as in the previous examples, but with some filler text below and above to give the {{htmlelement("body")}} element some height:
Let's look at an example of this in action. We are using the same HTML for the anchor and infobox as in the previous examples, placing them in the middle of filler text that overflows its container.

Let's hide all the HTML, and just discuss the CSS. Put all the HTML in a div or section with a height and width of 300px, forcing it to have scrollbars.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with hiding the HTML; I've done that.

I ended up modifying the text to:

Let's look at an example of this in action. We'll use the same HTML as in the previous examples, but with some filler text placed below and above it to cause the content to overflow its container and scroll.

I don't want to update the examples unless absolutely necessary, as there are a lot of them to keep consistent. I don't need an extra container — setting the embedding <iframe> to a fixed height already creates the required scrolling.


```html
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Dui nunc mattis enim ut tellus
elementum sagittis vitae et. Nisi quis eleifend quam adipiscing vitae proin
sagittis nisl rhoncus. In arcu cursus euismod quis viverra nibh cras pulvinar.
Vulputate ut pharetra sit amet aliquam.
</p>

<div class="anchor">⚓︎</div>

<div class="infobox">
<p>This is an information box.</p>
</div>

<p>
Malesuada nunc vel risus commodo viverra maecenas accumsan lacus. Vel elit
scelerisque mauris pellentesque pulvinar pellentesque habitant morbi
tristique. Porta lorem mollis aliquam ut porttitor. Turpis cursus in hac
habitasse platea dictumst quisque. Dolor sit amet consectetur adipiscing elit.
Ornare lectus sit amet est placerat. Nulla aliquet porttitor lacus luctus
accumsan.
</p>
```

We'll also give the anchor element the same CSS. The `<body>` element is given a narrow width to make the content taller:

```css hidden
.anchor {
font-size: 1.8rem;
color: white;
text-shadow: 1px 1px 1px black;
background-color: hsl(240 100% 75%);
width: fit-content;
border-radius: 10px;
border: 1px solid black;
padding: 3px;
}
```

```css
.anchor {
anchor-name: --infobox;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only show the anchor positinging related properties. Hide the body (now section) css.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've hidden the body rule, but I'm not adding a section. That's not needed.

}

body {
width: 50%;
margin: 0 auto;
}
```

The infobox is given fixed positioning and associated with the anchor in the same way as before. However, now we tether it to the anchor using the logical {{cssxref("inset-block-start")}} and {{cssxref("inset-inline-start")}} properties (which are equivalent to {{cssxref("top")}} and {{cssxref("left")}} in horizontal writing modes):

```css hidden
.infobox {
color: darkblue;
background-color: azure;
border: 1px solid #ddd;
padding: 10px;
border-radius: 10px;
font-size: 1rem;
}
```

```css
.infobox {
position: fixed;
position-anchor: --infobox;

inset-block-start: calc(anchor(end) + 5px);
inset-inline-start: calc(anchor(self-end) + 5px);
}
```

estelle marked this conversation as resolved.
Show resolved Hide resolved
Let's look at the positioning declarations in more detail:

- `inset-block-start: calc(anchor(end) + 5px)`: Here we are setting the anchored element's block start edge to be positioned in the same position along the block axis as the anchor's block end edge (calculated using the `anchor(end)` function), plus 5px, so a gap is left and the two edges are not flush against each other.
- `inset-inline-start: calc(anchor(self-end) + 5px)`: Here we are setting the anchored element's inline start edge to be positioned in the same position along the inline axis as the anchor's inline end edge (calculated using the `anchor(self-end)` function), plus 5px (again, to create a gap).

This gives us the following result:

{{ EmbedLiveSample("Using individual inset values, via `anchor()`", "100%", "250") }}

The anchored element is positioned 5px below and 5px to the right of the anchor element. As the document is scrolled up and down, the anchored element — despite being given fixed position — maintains its position relative to the anchor element.

### Using an `inset-area`

Expand Down