Using SASS Variables within nth-child?

后端 未结 1 960
春和景丽
春和景丽 2020-12-10 10:49

I have a grid set up of thumbnail images, currently 4 thumbs per row. To make sure they line up i have this snippet of code:

li:nth-child(5) { margin-left: 0         


        
相关标签:
1条回答
  • 2020-12-10 11:03

    You need to use variable interpolation to allow nth-child to be a variable.

    $galleryGrid: 5;
    li:nth-child(#{$galleryGrid}) { margin-left: 0;}
    

    Generates

    li:nth-child(5){margin-left:0}
    

    This markup is fine if you have absolute control over the images and layout to ensure that your elements always wrap in such a way that every 5th one begins a new row. If you cannot make such guarantees, setting negative margins on the parent element is a better way to go.

    0 讨论(0)
提交回复
热议问题