S
S
symnoob2021-05-04 19:25:45
Sass
symnoob, 2021-05-04 19:25:45

What selector should be used to determine the number of child classes available?

Hello everyone,

I have several divs described below with the class "parent", these divs are nested with other divs with the class "child" and "menu":

<div class="parent">
    <div class="menu"></div>
    <div class="child"></div>
    <div class="child"></div>
    <div class="child"></div>
</div>

<div class="parent">
    <div class="menu"></div>
    <div class="child"></div>
</div>


how can scss track where there are at least two divs with class "child"?

well, for example, in order to give a height, if there are 2 divs or more, then give a div with the class "child":

.child{
height: 200px;
}

and if the parent div has only one div with the class "child" then a different height:

.child{
height: 400px;
}

and it would also be cooler if something like this is possible if the parent div has more than one div with the class "child":

.child{
height: calc(400px / #количество дивов с классом "child");
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
IIIu6ko, 2021-05-04
@symnoob

This cannot be done with sass. he does not see the markup.
You can use regular css and tags

Here you can read more https://habr.com/en/post/252181/

A
Arseny, 2021-05-04
Matytsyn @ArsenyMatytsyn

I guess the :has selector in combination with :nth-child() will be able to do this. Unfortunately, CSS logical operations are still on an alluring horizon.
Therefore, since in the end the output will be carried out by one or another templating engine, it is easier to count the elements on it and set the parent modifier class, through which to carry out styling.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question