2

I have an application where styles are defined as

select { 
    border: 1px solid #6FA7D1; 
    outline:0; 
    height:25px; 
    padding-left: 5px; 
    font-family:Arial; 
    font-size:12px; 
    transition: all 0.8s; 
    border-bottom-left-radius: 5px; 
    border-top-left-radius: 5px; 
    }

so, every <select></select> will get the same style, which is expected, but, I'm using some third party plugins like jqGrid and I don't want to apply same style on for instance <select> rendered in jqGrid pager. This <select> has some class. Is there some way to tell in CSS not to apply on DOM with certain class?

Please don't focus strictly on this <select> in jqGrid, I have more situations when I can use such exclusion.

dllhell
  • 1,987
  • 3
  • 34
  • 51
  • Use select:not(.someclass):not(.anotherclass) { } /* someclass and anotherclass should be assigned to select element */ – Shyam Jan 02 '15 at 12:20

4 Answers4

5

You can use the :not selector to prevent application under certain circumstances, e.g:

:not(selector) select

Where selector relates to either a jQGrid id or class

The negation CSS pseudo-class, :not(X), is a functional notation taking a simple selector X as an argument. It matches an element that is not represented by the argument. X must not contain another negation selector.

This basically says target select elements which arent a child of selector (in this case jQGrid)

You can use :not to exclude any subset of matched elements.

:not(div) > span {
  color: red;
}
<span>Make me red!</span>
<div><span>...but not me...</span>
</div>
SW4
  • 69,876
  • 20
  • 132
  • 137
4

http://jsfiddle.net/iaezzy/1s5g5mjn/

.element:not(.exclude) {
    background: green;
}
.exclude {
    background:red;
}
eozzy
  • 66,048
  • 104
  • 272
  • 428
2

What about Can I write a CSS selector selecting elements NOT having a certain class? in CSS3?

select:not(.someClass) {
    /* Styles */
}
Community
  • 1
  • 1
Yann Bertrand
  • 3,084
  • 1
  • 22
  • 38
0

You can't, the only option would be to:

  • Put the <select> styling into a class, e.g. .select, and add that <select class="select"> to all elements that you want to be styled.

  • Add a class, e.g. select-jqGrid, that overrides all default styling from the select and add that to all <select> elements inside the jqGrid.

ckuijjer
  • 13,293
  • 3
  • 40
  • 45