Can CSS detect the number of children an element has?

后端 未结 7 2133
猫巷女王i
猫巷女王i 2020-11-22 00:52

I\'m probably answering my own question, but I\'m extremely curious.

I know that CSS can select individual children of a parent, but is there support to style the ch

相关标签:
7条回答
  • 2020-11-22 01:17

    If you are going to do it in pure CSS (using scss) but you have different elements/classes inside the same parent class you can use this version!!

      &:first-of-type:nth-last-of-type(1) {
        max-width: 100%;
      }
    
      @for $i from 2 through 10 {
        &:first-of-type:nth-last-of-type(#{$i}),
        &:first-of-type:nth-last-of-type(#{$i}) ~ & {
          max-width: (100% / #{$i});
        }
      }
    
    0 讨论(0)
提交回复
热议问题