In my react js project
There is a block which may have one element or two elements, depending on run time.
For example:
Scenario 1: (two groups are existed )
<div class='menu-list'>
<div class='group'>
<div class="option">....</div>
</div>
<div class='group'>
<div class="option">....</div>
</div>
</div>
Scenario 2: (only 1 group)
<div class="menu-list">
<div class='group'>
<div class="option">....</div>
</div>
</div>
Original I have my css styling ready. However, I noticed there exist scenario 2 sometimes in run time and I dont want to apply any styling in this situation.
I would like to style the element only when it is in scenario 1.
.menu-list .group:first-child .option:last-child { …..}
If it is possible to do so?
2
Answers
Based on the answers and adjustment,
this logic gets to the target.
Thank you all
If you only have these two scenarios: when it’s one element you apply one specific style, when it’s multiple elements you apply another style, this should be for you.
Or, if you only need to style for the first scenario (multiple elements)
As rightly suggested by @AmauryHanser, using
:only-child
is more correct