tags:

views:

1399

answers:

5

I have an ASP.NET site that I'm developing. The layout is pretty basic. The master page has a header with a horizontal menu beneath the banner taking the entire width. On the left is a Navigation pane, 150 pixels wide with a picture and a few external links. The remainder of the width is the ContentPlaceholder. Beneath that is the footer.

In the default page, the master page's content has a few divs. One for "News", one for "FAQs", one for "deadlines" and another for a "Chart of the Day". Each of these is 450 pixels wide and I'd set them up with the appropriate "float: left;" and "float: right;" so that the left 'column' of content was the News, then FAQ under it and the right column was the deadlines and chart. If the user narrowed the browser too much, the deadlines and chart would get pushed under the News and FAQs.

Now I'm directed to change the behavior. Now, if the user narrows the browser, the deadlines and chart should "hold their ground" and remain as a second column with the user having to use the horizontal scroll bar to see them properly.

I thought that using "min-width: 950px;" on the overall content div would do that, but the "float: right" on the content div ends up pushing the whole content section under the navigation pane when I narrow the browser and when I narrow it further, the Deadlines and Chart divs are STILL getting pushed under the News and FAQs.

I know I'm missing something simple - like a property to "stay to the right regardless" - and anchor or something. Googling around for examples isn't helping much because I don't think I'm putting the right words into searching.

Thanks in advance for any advice.

A: 

As heretical as it sounds, by far the simplest way is to throw out the divs and use a table structure.

Below is a complete example. Just save it as an html file and preview in a browser. BTW, you might play with different doctypes to see how they affect the output.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
    <title>Untitled</title>
<style>
.box { width:250px;float:left;border: solid 1px green;}
.outer{width:600px;}
</style>    
</head>

<body>
<div class="outer">
<div class="box" style="height: 200px">Hello World!</div>
<div class="box" style="height: 300px">Hello World!</div>
<div class="box" style="height: 100px">Hello World! asd asdfasfd asdjasd hyasydufuasydf auysdfaysdfuaysdfu yasdufy ausdyf aiusdyf aiusydfuasdfasdf asf</div>
<div class="box" style="height: 50px">Hello World!</div>
</div>
</html>
Chris Lively
Heh. Yeah, I thought of that but each div of content is variable when it comes to height - the FAQ section even uses an Accordion. Was hoping there was a stylesheet tag I've overlooked as I'm relatively new at this.
David
A: 

Unless I'm misunderstanding, you want the page to simply be constant no matter what happens with the browser height/width. If this is the case, you can simply use absolute position and set an absolute top and left pixel setting in your css. So your News css would be something like

position: absolute;
top: 0px;
left: 0px;
...

Then your Deadlines would be:

position: absolute;
top: 0px;
left: 450px;
...

And so on. You may have to use relative as position or set up a top offset based on your header and a left offset based on your links div (which you already said is 150), but if you want your page to stay constant, that's your best bet. Let me know if you have any issues with this.

AdamB
A: 

This works for me, in FF3 and IE6.

 <html>
 <head>
     <title></title>
 <style>
 .content_section{width:450px;border: solid 1px green;}
 .nav{width:150px; border: solid 1px yellow; float: left;}
 .content_container{width: 950px; border: solid 1px blue; float: left;}

 </style>    
 </head>

 <body>
 <div style="width: 1104px;">
  <div class="nav">
    Navigation here<br />Navigation here<br />Navigation here<br />Navigation here<br />Navigation here<br />Navigation here<br />Navigation here<br />Navigation here<br />
  </div>
  <div class="content_container">
   <div style="float: left;">
    <div id="news" class="content_section">news<br />news<br />news<br />news<br />news<br />news<br />news<br />news<br /></div><br />
    <div id="faq" class="content_section">faq<br />faq<br />faq<br />faq<br />faq<br />faq<br />faq<br />faq<br />faq<br /></div>
   </div>
   <div style="float: right;">
    <div id="deadlines" class="content_section">deadlines<br /></div><br />
    <div id="chart" class="content_section">chart<br />chart<br />chart<br />chart<br />chart<br />chart<br />chart<br />chart<br />chart<br /></div>
   </div>
  </div>
 </div>
 </html>
Matt Dawdy
Having a wrapper DIV with a fixed length ended up working best for this particular situation. As usual, the requirements changed while I was testing solutions..
David
A: 

When you get tired of managing this all yourself, you should check out a decent CSS grid system.

Here are two:

These systems make it trivial to do the sort of thing you're talking about.

Triptych
A: 

The simplest answer is to wrap everything in a container and give the container a width so that it never shrinks. Example

<div id="container">
  <div id="header"></div>
  <div id="nav"></div>
  <div id="leftContent"></div>
  <div id="rightContent"></div>
  <div id="footer"></div>
</div>

This allows the left and right content to be any height at all.

Bruno43
That turned out to be the easiest solution. My boss asked that the site act like others and that we could 'optimize' for 1024x768. The 'wrapper' style was given a width of 1024 with margin-right:auto; and margin-left:auto; added to center all of the divs.
David
For IE 6 you might want to style your body with body{text-align:center;} then align your text left again in the wrapper #wrapper{text-align:left;} This will center the div for IE 6, otherwise it doesn't recognize the margin left and right auto.
Bruno43