Can I write a CSS selector selecting elements NOT having a certain class or attribute?

前端 未结 10 620
不知归路
不知归路 2020-11-22 10:47

I would like to write a CSS selector rule that selects all elements that don\'t have a certain class. For example, given the following HTML:



        
10条回答
  •  不要未来只要你来
    2020-11-22 11:52

    Just like to contribute that the above answers of :not() can be very effective in angular forms, rather than creating effects or adjusting the view/DOM,

    input.ng-invalid:not(.ng-pristine) { ... your css here i.e. border-color: red; ...}
    

    Ensures that on loading your page, the input fields will only show the invalid (red borders or backgrounds, etc) if they have data added (i.e. no longer pristine) but are invalid.

提交回复
热议问题