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.

1
  • Use select:not(.someclass):not(.anotherclass) { } /* someclass and anotherclass should be assigned to select element */ Commented Jan 2, 2015 at 12:20

4 Answers 4

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>

Sign up to request clarification or add additional context in comments.

Comments

4

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

.element:not(.exclude) {
    background: green;
}
.exclude {
    background:red;
}

Comments

2

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

select:not(.someClass) {
    /* Styles */
}

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.