Can I make this CSS simpler to avoid repeating the parent selector?

前端 未结 2 2060
无人及你
无人及你 2020-12-22 06:58

A common pattern I come across is the following:

form.request input {
    /* ... */
}

form.request input[type=\"text\"] {
    /* ... */
}

form.request sele         


        
相关标签:
2条回答
  • 2020-12-22 07:46

    No, you cannot. But if you want to do less typing and make the stylesheets more readable, consider using SCSS.

    0 讨论(0)
  • 2020-12-22 07:48

    Use LESS, which would let you write

    form.request {
      input { /* ... */ }
      input[type="text"] { /* ... */ }
      select { /* ... */ }
      br { /* ... */ }
    }
    

    or even

    form.request {
      input {
        /* ... */
        &[type="text"] { /* ... */ }
      }
      select { /* ... */ }
      br { /* ... */ }
    }
    
    0 讨论(0)
提交回复
热议问题