Succinct way of specifying two or more values for an attribute in css selector

后端 未结 2 1363
囚心锁ツ
囚心锁ツ 2021-01-23 14:31

I have a CSS selector as follows:

#foo input[type=number].form-control, #foo input[type=text].form-control
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-23 15:00

    No not in plain ol' CSS, but with a pre-processor like LESS or SASS you can nest attributes.

    #foo {
        input.form-control {
            &[type=number],
            &[type=text] {
                /* your css styles here */
            }
        }
    }
    

    It's prehaps not 'succinct', in that the end result is longer than your desired outcome, but it is somewhat easier to read, and may cut down some repetition in your stylesheet.

提交回复
热议问题