DEV Community

Nikhil Chandra Roy
Nikhil Chandra Roy

Posted on

1

Easiest way to loop the css :nth-child pseudo class by scss

There are couple of way to loop the pseudo class by scss but the while loop make it more easy to understand and the process.

$count: 1;
@while $count < 10+1{
  .classname:nth-of-type(#{$count}){
    width: auto;
  }
    $count: $count+1
}

Enter fullscreen mode Exit fullscreen mode

this output is:


.classname:nth-of-type(1) {
  width: auto;
}

.classname:nth-of-type(2) {
  width: auto;
}

.classname:nth-of-type(3) {
  width: auto;
}

.classname:nth-of-type(4) {
  width: auto;
}

.classname:nth-of-type(5) {
  width: auto;
}

.classname:nth-of-type(6) {
  width: auto;
}

.classname:nth-of-type(7) {
  width: auto;
}

.classname:nth-of-type(8) {
  width: auto;
}

.classname:nth-of-type(9) {
  width: auto;
}

.classname:nth-of-type(10) {
  width: auto;
}
Enter fullscreen mode Exit fullscreen mode

Thanks.

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay