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 1091637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:33:37+00:00 2026-05-16T23:33:37+00:00

Is there a way to select an element with CSS based on the value

  • 0

Is there a way to select an element with CSS based on the value of the class attribute being set to two specific classes. For example, let’s say I have 3 divs:

<div class="foo">Hello Foo</div>
<div class="foo bar">Hello World</div>
<div class="bar">Hello Bar</div>

What CSS could I write to select ONLY the second element in the list, based on the fact that it is a member of both the foo AND bar classes?

  • 1 1 Answer
  • 2 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-16T23:33:37+00:00Added an answer on May 16, 2026 at 11:33 pm

    Chain both class selectors (without a space in between):

    .foo.bar {
      /* Styles for element(s) with foo AND bar classes */
    }
    

    If you still have to deal with ancient browsers like Internet Explorer 6, be aware that it doesn’t read chained class selectors correctly: it’ll only read the last class selector (.bar in this case) instead, regardless of what other classes you list.

    To illustrate how other browsers and IE6 interpret this, consider this snippet:

    * {
      color: black;
    }
    
    .foo.bar {
      color: red;
    }
    <div class="foo">1. Hello Foo</div>
    <div class="foo bar">2. Hello World</div>
    <div class="bar">3. Hello Bar</div>

    The page will look like this:

    • On supported browsers:

      1. Not selected as this element only has class foo.
      2. Selected as this element has both classes foo and bar.
      3. Not selected as this element only has class bar.
    • In Internet Explorer 6:

      1. Not selected as this element doesn’t have class bar.
      2. Selected as this element has class bar, regardless of any other classes listed.
      3. Selected as this element has class bar.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to select an element in css based on element text?
Is there a way to select a parent element based on the class of
Is there a way to select all CSS rules of an element with JavaScript?
Using CSS, is there any way to select an element's nearest descendent that matches
Is there a way in JavaScript to select a element of a multidimential array.
I there ANY way in javascript that we could trigger a select element (dropdown
Is there any way only using CSS (no script) to check if an element
is there a way to select with css, elements which have the index multiple
Is there a better way to select grandparent elements in jQuery in order to
Is there a way to select all id's with jQuery with a prefix my

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.