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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:54:29+00:00 2026-06-13T14:54:29+00:00

I’m trying to figure out if there’s a way using only HTML and CSS

  • 0

I’m trying to figure out if there’s a way using only HTML and CSS to build elements within a page that are responsive to the other elements, rather than to the browser size as is with @media and traditional responsive design.

For example, I have an element that is 900px wide. It can sometimes contain 1, 2 or 3 child elements. I want the child elements to style and display additional elements depending on how many sibling elements there are.

Eg

<div id="parent">
    <div class="child"></div>
    <div class="child"></div>
    <div class="child"></div>
</div>

vs

<div id="parent">
    <div class="child"></div>
    <div class="child"></div>
</div>

The child elements would appear differently – different widths, different padding, borders… and they would also have child elements which would be hidden in the first sample, but display in the second.

I know this can be done with JS, PHP… but I’m trying to see if there’s a way to do it without it. Since I also want to hide/show specific elements depending on the existence of other child elements, using relative sizes (eg %) doesn’t cut it.

Thanks

  • 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-13T14:54:30+00:00Added an answer on June 13, 2026 at 2:54 pm

    It’s possible with CSS3, it took me a couple of minutes to figure it out.

    Check out http://jsfiddle.net/Vdz7s/.

    HTML:

    <h1>One:</h1>
    <div class="parent">
        <div class="child">1</div>
    </div>
    
    <h1>Two:</h1>
    <div class="parent">
        <div class="child">1</div>
        <div class="child">2</div>
    </div>
    
    <h1>Three:</h1>
    <div class="parent">
        <div class="child">1</div>
        <div class="child">2</div>
        <div class="child">3</div>
    </div>​
    

    CSS:

    .parent .child:nth-last-child(1)
    {
        border:1px solid yellow;
    }
    
    .parent .child:nth-last-child(2),
    .parent .child:nth-last-child(2) ~ .child
    {
        border:1px solid orange;
    }
    
    .parent .child:nth-last-child(3),
    .parent .child:nth-last-child(3) ~ .child
    {
        border:1px solid red;
    }
    ​
    

    I think that the code is pretty self-explanatory, then you just need to target the children childs and do whatever you want with them.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I know there's a lot of other questions out there that deal with this
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to

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.