0

I need to stack two tables on top of each other with content before and after. I can't get the content that comes after to flow properly. The stacked tables are variable height.

HTML structure:

    ... other content ...  
    <div id="ChartPanel">  
      <table id="chart">  
      <table id="underlay">  
    </div>  
    <div id="ExtraInfoPanel">  
      <table id="extraInfo">  
    </div>  

CSS:

#ChartPanel { width: 100%; position: relative; }
#chart, #underlay { width: 1185px; position: absolute; top: 0; left: 0; }
#extraInfo { ??? }

The tables stack nicely, but I haven't figured out the CSS to get extraInfo to flow after the chart — it always ends up on top of the chart.

1
  • Welcome to Stack Overflow, @pat! In the future, you can make your code look like code by indenting each code line with four spaces. Otherwise the formatter gets confused and thinks you're trying to mark up your actual post. I fixed it for you this time. Commented Apr 4, 2011 at 21:08

4 Answers 4

1

I think the problem you are having is that both tables are position: absolute;. This is a problem because it takes them both out of the document flow, meaning that their height will not register as part of the containing parent's height.

However, you can't put them both back in the document flow, because then you won't get the underlay effect. I propose doing something like this:

#chart, #underlay { width: 1185px; }
#underlay { position: absolute; top: 0px; left: 0px; }

Assuming they have the same dimensions, leave one of the tables alone, and make the other positioned absolutely. This will preserve the dimensions of the parent container, and allow both tables to be positioned at the same location.

Have a look at the result here->

Sign up to request clarification or add additional context in comments.

Comments

0

Try adding floats to your divs, and for the extra info add clear: both;

Good luck.

Comments

0

Because the content of your #ChartPanel is empty (your tables are absolute, so picked out of the #ChartPanel. You don't have any height left in your #ChartPanel. Try adding height to #ChartPanel.

#ChartPanel { 
    width: 100%; 
    height:500px; /* <-- very new */
    position: relative; }
#chart, #underlay { 
    width: 1185px; 
    position: absolute; 
    top: 0; left: 0; }
#extraInfo { 
     /* maybe even just... nothing, or some relative positioning. */
}

Comments

0
#chart, #underlay { width: 1185px; position: absolute; top: 0; left: 0; }

Why are you positioning both of those tables in the exact same spot?

FYI, when you position: absolute, you take the object out of the document flow, so it gets tricky to then figure out how to visually place something below it, since CSS doesn't know where the bottom of the positioned elements are anymore.

If you need to put things side-by-side, better to use floats, which you can then contain with a parent wrapper.

2 Comments

Positioning on the same place, because it's an underlay. Seems quite logical to me.
If by 'on top of each other' the OP meant layered, then I guess that makes sense. I read that 'on top of each other' as one being higher on the page than the other one right below it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.