944,107 Members | Top Members by Rank

Ad:
May 18th, 2005
0

Problem with <div> height - Controlling flow from center div

Expand Post »
Hi All

I am hoping someone can help me out since this is driving me nuts.

On my site I have 3 columns:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. |sidebar| content |sidebar|
What I want to do is have the height of the 2 sidebars controlled by the height of the content. So instead of:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1.  
  2.  
  3. |side| content |side|
  4. | | content |___ |
  5. |___ | content
  6. content

I have:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1.  
  2. |side | content |side |
  3. | | content | |
  4. | | content | |
  5. | | content | |

This hasn't been a problem so far I was working with fixed length heights of 700px but now I have content that is getting bigger than the 700px limit and the just looks bad with the side bars not matching the rest of the content.

The site is: www.geekserv.com

If anyone can give pointers I would appreciate it. Please note I don't want to end up using tables or frames this site has to remain 100% xhtml and css.

Thanks in advance for any help.

Ben
Similar Threads
Reputation Points: 66
Solved Threads: 3
Junior Poster
liliafan is offline Offline
117 posts
since Apr 2004
May 19th, 2005
0

Re: Problem with <div> height - Controlling flow from center div

The problem with xhmtl, css, and height, is that percentage heights refer to the percetange of the containing element. The parent element is "body". So, you have to give the body tag a height of 100%, as well as all child tags.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
May 19th, 2005
0

Re: Problem with <div> height - Controlling flow from center div

Quote originally posted by tgreer ...
The problem with xhmtl, css, and height, is that percentage heights refer to the percetange of the containing element. The parent element is "body". So, you have to give the body tag a height of 100%, as well as all child tags.
I was looking at this and experimented with setting:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. html,body {
  2. min-height: 100%;
  3. height: 100%;
  4. }

However, this seems to only take into account the screen height not the height of the elements contained within the screen.
Reputation Points: 66
Solved Threads: 3
Junior Poster
liliafan is offline Offline
117 posts
since Apr 2004
May 19th, 2005
0

Re: Problem with <div> height - Controlling flow from center div

Yes, you're right.

You'll have to use JavaScript. Add this in your document head:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. //<![CDATA[
  3. onload=function() {
  4. document.getElementById('leftbar').style.height=
  5. document.getElementById('rightbar').style.height=
  6. document.getElementById('maincontent').offsetHeight+"px";
  7. }
  8. //]]>
  9. </script>

This makes the style.height of your two side divs equal to the offsetHeight of your main div. It will run automatically "onload" (you don't have to modify your body tag), and will validate as xhtml (the CDATA comment sees to this).

Of course, you should remove the "height: 700px;" statements from your CSS.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
May 19th, 2005
0

Re: Problem with <div> height - Controlling flow from center div

Awesome I will experiment with that, do you know if it is cross browser capable? Or will I need to play with it a little?

Thanks so much for the pointers I will play with it this evening.

Ben
Reputation Points: 66
Solved Threads: 3
Junior Poster
liliafan is offline Offline
117 posts
since Apr 2004
May 19th, 2005
0

Re: Problem with <div> height - Controlling flow from center div

It should be cross-browser, though I admit I only tested with FireFox. I really don't use IE anymore.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
May 19th, 2005
0

Re: Problem with <div> height - Controlling flow from center div

Worked like a charm I just tested it on my development machine and the height works in both ie and firefox, I had to make a slight alteration to get it looking good on IE.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. document.getElementById('leftbar').style.height=
  2. document.getElementById('rightbar').style.height=
  3. (document.getElementById('maincontent').offsetHeight + 10)+"px";

Extra 10px added on and it looks great.

Thank you so much for the help.

Ben
Reputation Points: 66
Solved Threads: 3
Junior Poster
liliafan is offline Offline
117 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Dynamically modifying the CSS attributes through Javascript
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: hit counters





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC