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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:55:30+00:00 2026-06-13T07:55:30+00:00

I have 2 css classes that hold the background-color property. One class is for

  • 0

I have 2 css classes that hold the background-color property. One class is for general elements and the other is for selected elements. I put the selected_element class on the element according to data i have in my model.
This is the css:

.selected_obj {
    background-color: #00EE76
}

.general_obj{
    /* Othe CSS Properties */
    background-color: #d9d9d9;
}

This is my JSP:

<c:forEach items="${myModel.myCollection}" var="obj">
        <c:choose>
            <c:when test="${obj.id == myModel.selectedObj.id}">
                <div class="selected_obj general_obj">
                    <span>${obj.name}</span>
                </div>
            </c:when>
            <c:otherwise>
                <div class="general_obj">
                    <span>${obj.name}</span>
                </div>
            </c:otherwise>
        </c:choose>
    </c:forEach>

When i view the generated HTML, i can see the selected_obj class on the correct elements but the value is overriden by the backgroung-color property value of the general_obj class. How is the correct value selected by the brouwser and how can i overcome this?

  • 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-06-13T07:55:31+00:00Added an answer on June 13, 2026 at 7:55 am

    When two conflicting rules with the same specificity are to be applied, the latter one wins. ) In your case .general_obj background-color rule wins (= is actually applied), because it goes after the .specific_obj rule in CSS file.

    This – class="general_obj selected_obj" – change in HTML will do nothing to fix the problem, as both classes will still have the same specificity.

    One obvious approach to fix this problem is using !important:

    .selected_obj {
        background-color: #00EE76 !important;
    }
    

    … as styles specified with !important will override the styles that otherwise should be applied (by following the general CSS cascading rules).

    That goes well as a quick fix, but I’d actually strongly suggest against it (the reasons are described in this article quite well; CSS-Tricks also have a mighty word on that topic).

    Instead you may either…

    • make a specific multi-class rule for such cases, like this:

      .selected_obj, .selected_obj.generic_obj {
      background-color: #00EE76;
      }

    • (strongly suggested) fix the CSS file so that rules for generic classes are described first and rules for specific classes follow them.

    Actually, it’s a great rule of thumb: deal with all the generic things first, then work with specialties. )

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

Sidebar

Related Questions

Possible Duplicate: CSS Selector that applies to elements with two classes So I have
i have this css code, and i want to shorten it. #one{ background: #6cab26;
I have a css rule defining the background color as the window system color
I have a table that has rows with different classes depending on what color
i have a css in my GWTApplication which contains several classes in that,I want
I have a page with many elements that have the same class attached to
In my project I have put all my css classes in the style sheets.
Lets say I have a couple of CSS classes: .tickup { color: green; }
I have css classes that will automatic get names from a jquery script: so
Say I have a div that uses two css classes that both use text-align,

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.