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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:51:40+00:00 2026-05-17T02:51:40+00:00

In the markup below, I’m looking for a way (perhaps using css selector’s) to

  • 0

In the markup below, I’m looking for a way (perhaps using css selector’s) to style the content div differently depending on the presence of menu? Menu may or may not be present in that location in the markup and if it is there, I need to add some top margin to content.

I believe sibling and descendent selector rules might not go this far…

“When menu is present as a child of header set the top margin of content (whose parent is a sibling of header) to 100 pixels. Otherwise, set it to zero”

<div class="header">
  <div class="sitetitle">site title</div>
  <div class="tagline">tagline</div>
  <div class="menu">menu</div>
</div>

<div class="main">
  <div class="content">content goes here</div>
</div>

If css allowed groupings, I would do it this way…

(.header ~ .menu) + (.main > .content) {margin-top:100px;}
  • 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-17T02:51:41+00:00Added an answer on May 17, 2026 at 2:51 am

    Not possible in your markup.

    CSS selectors can only look at the ancestor and at the sibling axes. You cannot look inside (“what children do I have”) – only upwards (“what are my parents”) and sideways (“what’s next to me”).

    Examples. This:

    div.header div.menu
    

    refers to any <div class="menu"> one of whose ancestors is a <div class="header">.

    This:

    div.header > div.menu
    

    refers to any <div class="menu"> whose direct ancestor (i.e. “parent”) is a <div class="header">.

    This:

    div.header ~ div.menu
    

    refers to any <div class="menu"> that has a <div class="header"> among its preceding siblings, i.e. they have the same parent and occur one after another, but not necessarily adjacent to each other (that’s “looking sideways”).

    This:

    div.header + div.menu
    

    refers to any <div class="menu"> whose direct preceding sibling is a <div class="header">.

    There are no other traversing selectors in CSS (this statement refers to CSS2) and certainly there are no conditionals.

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

Sidebar

Related Questions

In the markup shown below, I'm trying to get the content div to stretch
The markup below is used for my jQuery carousel widget. The first div serves
I have the below markup that cannot be changed: <div>Some data</div> <span>More data</span> <a>Link
Sample html markup below <div class=container answer_comments> <p class=comment_text>Hey that's not cool.</p> <p class=comment_attribs>By
I'm wrapping text around an image using markup something like this: CSS: #imgAuthor {
I'm looking for a way to create a CSS layout where the left column
I got a markup like below and without any styling, the Twitetr Bootstrap css
I have my markup structure as below: <div> <div>value1</div> <div>value2</div> <div>value3</div> <div>value4</div> <div class=clear></div>
I'm getting an error when my content contains the table markup below. Here is
Using the markup below, the button text is underlined when hovered over. How can

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.