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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:49:26+00:00 2026-05-13T10:49:26+00:00

I have the following html <div class=section> <div>header</div> <div> contents <div>sub contents 1</div> <div>sub

  • 0

I have the following html

<div class="section">
   <div>header</div>
   <div>
          contents
          <div>sub contents 1</div>              
          <div>sub contents 2</div>
   </div>
</div>

And the following style:

DIV.section DIV:first-child 
{
  ...
}

For some reason that I don’t understand the style is getting applied to the “sub contents 1” <div> as well as the “header” <div>.

I thought that the selector on the style would only apply to the first direct child of a div with a class called “section”. How can I change the selector to get what I want?

  • 1 1 Answer
  • 1 View
  • 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-13T10:49:26+00:00Added an answer on May 13, 2026 at 10:49 am

    What you posted literally means “Find any divs that are inside of section divs and are the first child of their parent.” The sub contains one tag that matches that description.

    It is unclear to me whether you want both children of the main div or not. If so, use this:

    div.section > div
    

    If you only want the header, use this:

    div.section > div:first-child
    

    Using the > changes the description to: “Find any divs that are the direct descendents of section divs” which is what you want.

    Please note that all major browsers support this method, except IE6. If IE6 support is mission-critical, you will have to add classes to the child divs and use that, instead. Otherwise, it’s not worth caring about.

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

Sidebar

Related Questions

I have following HTML code: <section class=indent-1> <!-- Section 1 --> <section> <div>Some content</div>
I have the following construct in my HTML document: <div class=content> <section class=column></section> <aside
I have the following html <div id=menu> <ul class=horizMenu> <li id=active><a href=# id=current>About</a></li> <li><a
I have the following snippet in one of my html pages : <div class=inputboximage>
I have the following HTML: <DIV class=foo bar></DIV> I'm trying to create a CSS
I have the following HTML (excerpt from larger code-base) <div class=diary-event ui-corner-all title=[title]> <span
Hi guys lets say I have the following html: <div class=owner> <div> <a href=javascript:void(0)
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 HTML: <div id=footer> <div class=wrapper clear> <!-- stuff --> </div>

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.