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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:56:06+00:00 2026-06-18T06:56:06+00:00

part of my css layout sets div heights relative to widths so that the

  • 0

part of my css layout sets div heights relative to widths so that the aspect ratio is the same for all screen sizes. this way i never specifically set the height of a div to a px value – the height is simply an aspect ratio of the width. if you have not come across this technique before, here is a good explanation.

onto my specific problem…

with this in mind i have created the following simple div which is twice as wide as it is high: (to see it in action please see this fiddle)

<html>
    <head>
       <style type="text/css">
.container
{
    position:relative;
    width:50%;/*half the width of the whole page*/
    margin:auto;/*center the whole thing*/
}
.relative_container
{
    background-color:blue;
    position:absolute;
    width:100%;
    top:0;
    left:0;
}
.set_height
{
    width:100%;
    height:100%;
    margin-top:50%;/*aspect ratio 2:1*/
}
       </style>
    </head>
    <body>
        <div class='container'>
            <div class='relative_container'>
                <div class='set_height'></div>
            </div>
        </div>
    </body>
</html>

all good so far. however i then want to add another identical div under the first. as you can see in this fiddle, i cannot get them to display any way other than on top of each other. no doubt the answer lies with clearing the divs as demonstrated here but i can’t figure it out.

  • 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-18T06:56:07+00:00Added an answer on June 18, 2026 at 6:56 am

    Your relative_container class is absolutely positioned, so it’s placing both of the divs at top:0, left:0 with the same width and height (so they’re on top of each other). This doesn’t make sense for what you’re doing.

    If you change the positioning to relative, and add float: left to your strangely named relative_container, you will get your desired behavior, as they will “float” to the leftmost possible place in their parent div.

    Also, your “clear” divs aren’t doing anything. The clear property tells other divs not to float to the right/left of the given div. If the width of your div is 100% (ie. it fills up the parent), then nothing can float next to it anyway.

    Example 1: http://jsfiddle.net/NKRPe/13/

    EDIT: This second example accomplishes the same task without using the dummy div. Note that either padding-top or padding-bottom can be used.

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

Sidebar

Related Questions

I want to verify that the images, css, and javascript files that are part
The titles says it. I want a 2-column CSS layout that: is centered -
I made this simple 3 part css layout, but it's not behaving like it
Sorry for the silly question but for some reason this part of HTML/CSS layout
I am trying to build this very simple (visually speaking) layout using HTML/CSS that
We all know that we're supposed to combine our CSS into one file, but
Question Can I style just a part of a single character? Meaning CSS attributes
Part of the GUI I'm building using tkinter has a pop-up window that says
Part of my web application is a background script that polls from a beanstalkd
Part of my app caches web pages for offline viewing. To do that, I

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.