Skip to content

Commit 9ccdb2d

Browse files
ramiyJosh-Cena
andauthored
Update example in CSS sibling-count() function (mdn#40830)
* Update example in CSS `sibling-count()` function * Update description * Fix * Fix syntax --------- Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
1 parent 0145276 commit 9ccdb2d

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

files/en-us/web/css/sibling-count/index.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ sidebar: cssref
1010

1111
{{SeeCompatTable}}
1212

13-
The **`sibling-count()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Values_and_Units/CSS_Value_Functions) returns an integer representing the total number of direct child DOM elements of the parent element on which it is used.
13+
The **`sibling-count()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Values_and_Units/CSS_Value_Functions) returns an integer representing the total number of sibling DOM elements (direct children of the parent) of the element on which it is used, including itself.
1414

1515
> [!NOTE]
1616
> The {{CSSxRef("counter()")}} function provides a similar result but it returns a `<string>`, while `sibling-count()` returns an `<integer>` which can be used for calculations.
1717
1818
## Syntax
1919

20-
```css
21-
--total-sibling-elements: sibling-count();
20+
```css-nolint
21+
sibling-count()
2222
```
2323

2424
### Parameters
@@ -27,13 +27,13 @@ The `sibling-count()` function doesn't accept parameters.
2727

2828
### Return value
2929

30-
An integer; the total number of direct child DOM elements.
30+
An integer; the total number of sibling DOM elements including the element itself.
3131

3232
## Examples
3333

3434
### Dynamic column count
3535

36-
This example demonstrates setting the number of columns on a container to be equal to the number of its children, enabling placing each child in its own column.
36+
This example demonstrates setting the width of each item in a list based on the number of items, enabling placing each child in its own column.
3737

3838
#### HTML
3939

@@ -45,20 +45,25 @@ We include a {{htmlelement("ul")}} container and several {{htmlelement("li")}} e
4545
<li>Two</li>
4646
<li>Three</li>
4747
<li>Four</li>
48+
<li>Five</li>
4849
</ul>
4950
```
5051

5152
#### CSS
5253

53-
We set the {{CSSxRef("column-count")}} of the container to be equal to the quantity of direct children it contains. We also set every odd element to have a {{CSSxRef("background-color")}} to better demonstrate the resulting effect.
54+
We divide the {{CSSxRef("width")}} of each list item by the number of direct children the list contains. We also set every odd element to have a {{CSSxRef("background-color")}} to better demonstrate the resulting effect.
5455

5556
```css
5657
ul {
57-
column-count: sibling-count();
58-
text-align: center;
5958
list-style-type: none;
6059
padding: 0;
6160
margin: 0;
61+
text-align: center;
62+
display: flex;
63+
}
64+
65+
li {
66+
width: calc(100% / sibling-count());
6267
}
6368

6469
li:nth-of-type(odd) {

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,8 @@ The **`sibling-index()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/
7373
7474
## Syntax
7575

76-
```css
77-
li {
78-
width: calc(sibling-index() * 100px);
79-
}
76+
```css-nolint
77+
sibling-index()
8078
```
8179

8280
### Parameters
@@ -126,7 +124,7 @@ This example demonstrates how to create an ordered list using `sibling-index()`,
126124
We include a {{htmlelement("nav")}} container and several children {{htmlelement("div")}} elements.
127125

128126
```html
129-
<nav arial-label="Ordered list">
127+
<nav aria-label="Ordered list">
130128
<div>One</div>
131129
<div>Two</div>
132130
<div>Three</div>

0 commit comments

Comments
 (0)