You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: files/en-us/web/css/sibling-count/index.md
+13-8Lines changed: 13 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,15 +10,15 @@ sidebar: cssref
10
10
11
11
{{SeeCompatTable}}
12
12
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 parentelement 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.
14
14
15
15
> [!NOTE]
16
16
> 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.
17
17
18
18
## Syntax
19
19
20
-
```css
21
-
--total-sibling-elements: sibling-count();
20
+
```css-nolint
21
+
sibling-count()
22
22
```
23
23
24
24
### Parameters
@@ -27,13 +27,13 @@ The `sibling-count()` function doesn't accept parameters.
27
27
28
28
### Return value
29
29
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.
31
31
32
32
## Examples
33
33
34
34
### Dynamic column count
35
35
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.
37
37
38
38
#### HTML
39
39
@@ -45,20 +45,25 @@ We include a {{htmlelement("ul")}} container and several {{htmlelement("li")}} e
45
45
<li>Two</li>
46
46
<li>Three</li>
47
47
<li>Four</li>
48
+
<li>Five</li>
48
49
</ul>
49
50
```
50
51
51
52
#### CSS
52
53
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.
0 commit comments