- How to exclude particular class name in CSS selector?
- How to exclude particular class name in CSS selector?
- Method 1
- Method 2
- Method 3
- How to exclude a particular class in css?
- Using :not to exclude classes in css
- CSS Rule exclude parent class
- Css selector exclude class
- Try it
- Syntax
- Description
- Examples
- Using :not() with valid selectors
- HTML
- CSS
- Result
- Using :not() with invalid selectors
- HTML
- CSS
- Result
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- CSS exclude particular class name in CSS selector
- CSS Style
- HTML Body
- Related
How to exclude particular class name in CSS selector?
Secondly, you may need to add after so final code will be Solution 3: As far as I know you can’t use :not() on nested classes: nesting inside css :not() selectors You could try using on single posts? You can target the selector, which would be similar to using in CSS, but with much better browser support Fiddle Question: Here’s my css: What I am trying to achieve is: I want the container width to be 60% on single post pages and 92% on every other page.
How to exclude particular class name in CSS selector?
I’m trying to apply background-color when a user mouse hover the element whose class name is «reMode_hover» .
But I do not want to change color if the element also has «reMode_selected»
Note: I can only use CSS not javascript because I’m working within some sort of limited environment.
To clarify, my goal is to color the first element on hover but not the second element.
I tried below hoping the first definition would work but it is not. What am I doing wrong?
/* do not apply background-color so leave this empty */ .reMode_selected .reMode_hover:hover < >.reMode_hover:hover
One way is to use the multiple class selector (no space as that is the descendant selector):
.reMode_hover:not(.reMode_selected):hover
In modern browsers you can do:
.reMode_hover:not(.reMode_selected):hover<>
Consult http://caniuse.com/css-sel3 for compatibility information.
Method 1
The problem with your code is that you are selecting the .remode_hover that is a descendant of .remode_selected . So the first part of getting your code to work correctly is by removing that space
.reMode_selected.reMode_hover:hover
Then, in order to get the style to not work, you have to override the style set by the :hover . In other words, you need to counter the background-color property. So the final code will be
.reMode_selected.reMode_hover:hover < background-color:inherit; >.reMode_hover:hover
Method 2
An alternative method would be to use :not() , as stated by others. This will return any element that doesn’t have the class or property stated inside the parenthesis. In this case, you would put .remode_selected in there. This will target all elements that don’t have a class of .remode_selected
However, I would not recommend this method, because of the fact that it was introduced in CSS3, so browser support is not ideal.
Method 3
A third method would be to use jQuery. You can target the .not() selector, which would be similar to using :not() in CSS, but with much better browser support
How do I set a style but exclude classes and their, Your ex-members div is inside your people div, and your second style is looking for elements with a people class and no ex-members class on them. The simple solution is to just remove the &:not..ex-members < color:green; >
How to exclude a particular class in css?
.single-post .container < width: 60%; >not(.single-post) .container
What I am trying to achieve is: I want the container width to be 60% on single post pages and 92% on every other page. So, I am trying to exclude .single-post class from 2nd line of code by using not(.single-post) but it’s not working.
However, First line of code is working fine.
You can declare the general case first and the more specific later. The order of declarations matters (cascading). Run the following sample to check it out.
.container < width:92%; background-color: blue; >.single-post .container
Secondly, you may need to add !important after 92%
As far as I know you can’t use :not() on nested classes: nesting inside css :not() selectors
You could try using !important on single posts?
.container < background-color: lightblue; margin: 1em 0; padding: 1em; width: 92%; >.single-post .container
Working fiddle: https://jsfiddle.net/rmgawnu8/1/
Note that you’ll have to use the same CSS reference.
Assuming that the .single-post class is on the body element or another parent element, you could just write the following:
.container < width: 92%; >.single-post .container
This will set the width of the .container element to 92% on all pages—except when it’s on the .single-post page, where it will be set to 60% because that ruleset is defined later in the cascade and is more specific than the previous ruleset.
Css — How to exclude a class with all children in style, The major drawback here is that some styles in the child divs may get removed unintendedly. Depends on how they’re styled in the first place. Use :first-child with the ID or Class of its parent Element. If you are unable to catch the element using CSS, it is suggested to use Javascript or jQuery.
Using :not to exclude classes in css
I’m trying to apply css for all spans in a specific class but exclude some of them, but the following code doesn’t work:
.basket-items li span:not(.name,.count)
I have always used the :not just like :not(:empty) . doesn’t it accept css classes?
P.S.: note that in here excluding classes are meant which produce different result than the similar question like: Can I have multiple :not() selectors?
.basket-items li span:not(.name):not(.count)
.basket-items li span:not(.name):not(.count)
Css selectors — CSS Rule exclude parent class, CSS Rule exclude parent class. Ask Question Asked 5 years, 3 months ago. Modified 5 years, 3 months ago. Viewed 5k times 5 How can I write a CSS Rule that selects all div.box that are not inside .container? The following snippet is
CSS Rule exclude parent class
How can I write a CSS Rule that selects all div.box that are not inside .container ?
The following snippet is not working because there is a div without .container inside the div.container .
If you do not want to override every attribute, the only way I see is to give an additional class to the boxes inside of the specific container.
In a way, the CSS rule you are asking for is sort of backwards. You should start with the most generic rules, and then add more specific ones. In your case, you should do something like the following:
/* Generic Box styles */ .box < border: 1px solid black; >/* Boxes in a container */ .container .box
Select all div.box or all div not inside .container ? What you ask for and what you say you want selected in the html code sample are not the same thing. That said, your css selectors are just out of order. Try:
txtIf you want all the divs, just remove the .boxExclude single browser from using a CSS class, I have a css class that looks like — input[type=»radio»]:checked, input[type=»radio»]:hover < box-shadow: 0px 0px 10px #90BBD4; >Since Firefox’s latest browser update removed the -moz-box-shadow property and I believe it now uses the default box-shadow instead, my Firefox is still working great, but …
Css selector exclude class
The :not() CSS pseudo-class represents elements that do not match a list of selectors. Since it prevents specific items from being selected, it is known as the negation pseudo-class.
Try it
The :not() pseudo-class has a number of quirks, tricks, and unexpected results that you should be aware of before using it.
Syntax
The :not() pseudo-class requires a comma-separated list of one or more selectors as its argument. The list must not contain another negation selector or a pseudo-element.
Description
There are several unusual effects and outcomes when using :not() that you should keep in mind when using it:
- Useless selectors can be written using this pseudo-class. For example, :not(*) matches any element which is not an element, which is obviously nonsense, so the accompanying rule will never be applied.
- This pseudo-class can increase the specificity of a rule. For example, #foo:not(#bar) will match the same element as the simpler #foo , but has the higher specificity of two id selectors.
- The specificity of the :not() pseudo-class is replaced by the specificity of the most specific selector in its comma-separated argument of selectors; providing the same specificity as if it had been written :not(:is(argument)) .
- :not(.foo) will match anything that isn’t .foo , including and .
- This selector will match everything that is «not an X». This may be surprising when used with descendant combinators, since there are multiple paths to select a target element. For instance, body :not(table) a will still apply to links inside a , since , , , , , etc. can all match the :not(table) part of the selector.
- You can negate several selectors at the same time. Example: :not(.foo, .bar) is equivalent to :not(.foo):not(.bar) .
- If any selector passed to the :not() pseudo-class is invalid or not supported by the browser, the whole rule will be invalidated. The effective way to overcome this behavior is to use :is() pseudo-class, which accepts a forgiving selector list. For example :not(.foo, :invalid-pseudo-class) will invalidate a whole rule, but :not(:is(.foo, :invalid-pseudo-class)) will match any (including and ) element that isn’t .foo .
Examples
Using :not() with valid selectors
This example shows some simple cases of using :not() .
HTML
p>I am a paragraph.p> p class="fancy">I am so very fancy!p> div>I am NOT a paragraph.div> h2> span class="foo">foo inside h2span> span class="bar">bar inside h2span> h2>CSS
.fancy text-shadow: 2px 2px 3px gold; > /*
elements that don't have a class `.fancy` */
p:not(.fancy) color: green; > /* Elements that are notelements */
body :not(p) text-decoration: underline; > /* Elements that are not s or `.fancy` */ body :not(div):not(.fancy) font-weight: bold; > /* Elements that are not s or `.fancy` */ body :not(div, .fancy) text-decoration: overline underline; > /* Elements inside an that aren't a with a class of `.foo` */ h2 :not(span.foo) color: red; >Result
Using :not() with invalid selectors
This example shows the use of :not() with invalid selectors and how to prevent invalidation.
HTML
p class="foo">I am a paragraph with .foop> p class="bar">I am a paragraph with .barp> div>I am a div without a classdiv> div class="foo">I am a div with .foodiv> div class="bar">I am a div with .bardiv> div class="foo bar">I am a div with .foo and .bardiv>CSS
/* Invalid rule, does nothing */ p:not(.foo, :invalid-pseudo-class) color: red; font-style: italic; > /* Select allelements without the `foo` class */
p:not(:is(.foo, :invalid-pseudo-class)) color: green; border-top: dotted thin currentcolor; > /* Select all elements without the `foo` or the `bar` class */ div:not(.foo, .bar) color: red; font-style: italic; > /* Select all elements without the `foo` or the `bar` class */ div:not(:is(.foo, .bar)) border-bottom: dotted thin currentcolor; >Result
The p:not(.foo, :invalid-pseudo-class) rule is invalid because it contains an invalid selector. The :is() pseudo-class accepts a forgiving selector list, so the :is(.foo, :invalid-pseudo-class) rule is valid and equivalent to :is(.foo) . Thus, the p:not(:is(.foo, :invalid-pseudo-class)) rule is valid and equivalent to p:not(.foo) .
If :invalid-pseudo-class was a valid selector, the first two rules above would still be equivalent (the last two rules showcase that). The use of :is() makes the rule more robust.
Specifications
Browser compatibility
BCD tables only load in the browser
See also
Found a content problem with this page?
This page was last modified on Jul 18, 2023 by MDN contributors.
Your blueprint for a better internet.
CSS exclude particular class name in CSS selector
The following tutorial shows you how to use CSS to do «CSS exclude particular class name in CSS selector».
CSS Style
The CSS style to do «CSS exclude particular class name in CSS selector» is
.reMode_hover:not(.reMode_selected):hover < background-color:#f0ac00; >HTML Body
body> a href="" title="Design" >"reMode_design reMode_hover"> span>Design a href="" title="Design" >"reMode_design reMode_hover reMode_selected"> span>DesignThe following iframe shows the result. You can view the full source code and open it in another tab.
html> head> meta name="viewport" content="width=device-width, initial-scale=1"> style id="compiled-css" type="text/css"> .reMode_hover:not(.reMode_selected):hover < background-color: #f0ac00; > body> a href="" title="Design" >"reMode_design reMode_hover"> span>Design a href="" title="Design" >"reMode_design reMode_hover reMode_selected"> span>Design
Related
- CSS edit the CSS of a selector in Polymer 1.0
- CSS exclude last child in css pseudo class selector
- CSS exclude last child in css pseudo class selector (Demo 2)
- CSS exclude particular class name in CSS selector
- CSS exclude particular class name in CSS selector (Demo 2)
- CSS find elements when child element exists or not with JQuery selector
- CSS find first non-empty by css selector
demo2s.com | Email: | Demo Source and Support. All rights reserved.