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

  • SEARCH
  • Home
  • 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 7527243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:03:59+00:00 2026-05-30T04:03:59+00:00

I have the following html: <div class=canvas red> <div> <div class=canvas blue> <div> has

  • 0

I have the following html:

<div class="canvas red">
    <div>
        <div class="canvas blue">
           <div>
               has blue border
               <div class="canvas red">
                   ...
                   <div>
                   MUST HAVE RED BORDER
                   </div>
               </div>           
           </div>
        </div>
    </div>
</div>

and here is the css code:

div.canvas div {
    border-style: solid;
    border-width: 1px;
}

div.canvas.red div {
    border-width: 4px;
    border-color: red;
}

div.canvas.blue div {

    border-color: blue;
}

The problems are 3:

  • The innermost div.canvas.red div receives blue border because it is inside div.canvas.blue in the hierarchy. I need to stop this css inheritance so that the innermost div.canvas.red div will not get twisted by div.canvas.blue.

  • I cannot control the nesting of the divs above, because of dynamically inserting components in the web page. There can be various nesting scenarios that I must handle.

  • I must not change the css structure and the way it is applied – like canvas and red/blue etc being separate class names, instead of having canvas_red and canvas_blue as different classes.


I do not plan to support IE6, therefore I can use the > token in my css. However, I was unable to properly take advantage of it. I’d apreciate if you change my code using it more appropriately.

  • 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-30T04:04:00+00:00Added an answer on May 30, 2026 at 4:04 am

    I do not plan to support IE6, therefore I can use the > token in my css. However, I was unable to properly take advantage of it. I’d apreciate if you change my code using it more appropriately.

    This should be what you’re looking for:

    div.canvas > div {
        border-style: solid;
        border-width: 1px;
    }
    
    div.canvas.red > div {
        border-width: 4px;
        border-color: red;
    }
    
    div.canvas.blue > div {
        border-color: blue;
    }
    

    Keep in mind that border styles are not inherited by child elements from their parents by default. The behavior you’re seeing with descendant selectors is a simple effect of cascading (due to the equal specificity of your selectors), as well as the nature of the descendant selector itself to look at any level of nesting.

    The child selector > doesn’t increase specificity, but it does limit the nesting depth to only one level (i.e. div.canvas.blue > div cannot match the innermost element in <div class="canvas blue"><div><div>), which is why the resulting styles will be different.

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

Sidebar

Related Questions

I have the following HTML. <div class=red>Div One</div> <div class=green>Div Two</div> <div class=blue>Div Three</div>
I have the following html page: <body> <div class=hide1 style=width:1000px; height:1000px;> <table width=100% border=0
I have the following HTML code: <div class=container> <span class=red></span> <span class=hot></span> </div> On
I have the following HTML: <DIV class=foo bar></DIV> I'm trying to create a CSS
I have the following html and css <div id=header> <div id=headerTopLeft> <div id=areaSelect style=display:
I have the following HTML code: <div id=summary_form> <textarea class=summary>Please fill in</textarea><br/> <textarea class=summary>Please
I have the following html code: <div class=result hide id=userNameTooShort><span class=error>Your username needs to
I have the following css and html... .hide { display:none; } <div> <span class='kardashian
I have the following HTML code: <fieldset> <legend><span>Contact Details</span> <span class=edit1>Edit</span><span class=hide1>Hide</span></legend> <div> <!--content-->
I have the following code: HTML: <div id=login class=transparent-div login_leaf_class> <input class=pointer login_fields_button id=submit_button

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.