Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 673883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:38:41+00:00 2026-05-14T00:38:41+00:00

I have some divs: <div class=A>Target</div> <div class=A B>NotMyTarget</div> <div class=A C>NotMyTarget</div> <div class=A

  • 0

I have some divs:

<div class="A">"Target"</div>
<div class="A B">"NotMyTarget"</div>
<div class="A C">"NotMyTarget"</div>
<div class="A D">"NotMyTarget"</div>
<div class="A E">"NotMyTarget"</div>

Is there a CSS selector that will get me the div containing Target but not the divs containing NotMyTarget?

Solution must work on IE7, IE8, Safari, Chrome, and Firefox

Edit: So far Nick is the closest. It’s clumsy and I don’t like the solution, but at least it works:

.A
{
   /* style that all divs will take */
}
div.B 
{
  /* style that will override style .A */
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:38:42+00:00Added an answer on May 14, 2026 at 12:38 am

    You can use the attribute selector to match the div that has only one class:

    div[class=A] {
      background: 1px solid #0f0;
    }
    

    If you want to select another div that has multiple classes, use quotes:

    div[class="A C"] {
      background: 1px solid #00f;
    }
    

    Some browsers do not support the attribute selector syntax. As usual, “some browsers” is a euphemism for IE 6 and older.

    See also: http://www.quirksmode.org/css/selector_attribute.html

    Full example:

    <!DOCTYPE html>
    <html>
    <head>
      <style>
        .A { font-size:22px; }
        .B { font-weight: bold; border: 1px solid blue; }
        .C { color: green; }
    
        div[class="A"] {
          border: 1px solid red;
        }
        div[class="A B"] {
          border: 3px solid green;
        }
      </style>
    </head>
    <body>
      <div class="A">"Target"</div> 
      <div class="A B">"NotMyTarget"</div> 
      <div class="A C">"NotMyTarget"</div> 
      <div class="A D">"NotMyTarget"</div> 
      <div class="A E">"NotMyTarget"</div> 
    </body>
    </html>
    

    EDIT 2014-02-21: Four years later, :not is now widely available, though verbose in this specific case:

    .A:not(.B):not(.C):not(.D):not(.E) {
      border: 1px solid red;
    }
    

    Unfortunately, this doesn’t work in IE 7–8 as specified in the question: http://caniuse.com/#search=:not

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a div called 'menu' and inside that menu there are some divs
I have some UI in VB 2005 that looks great in XP Style, but
I have some DIVs that I am using JQuery to hide and show using
I have a whole bunch of divs that have a class called ofint .
I have a couple of nested divs and have set a CSS class for
If I have a HTML form with some embedded div s, and after the
I have some ASP.NET web services which all share a common helper class they
We have some input data that sometimes appears with &nbsp characters on the end.
I have some classes layed out like this class A { public virtual void
We have some files on our website that users of our software can download.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.