tags:

views:

314

answers:

5

I want to achieve the following:

  1. "Main" div and sidebar "div" should have same height, with minimum height (maybe browser's screen height or 700px) maximum height is not limited - according to the contents.
  2. The "content" div should wrap them(same height and width of both of them)

Markup:

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>

    <link href="StyleSheet2.css" rel="stylesheet" type="text/css" />

</head>
<body>
    <div id="wrap">

      <div id="content">         
        <div id="main">
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>        
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>       
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>                 
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>  
        </div>     
        <div id="sidebar"></div>
      </div>
      <div id="footer">
          <p>Footer</p>
      </div>

    </div>
</body>
</html>

CSS:

body, html
{
    margin: 0;
    padding: 5px;
    color: #000;
    background: #ace187;
    height:100%; 
}
#wrap
{
    width: 752px;
    height:100%; 
    margin: 0 auto; 
}

#content
{
    border: 1px solid #000000;
    height: 100%;
    background-color: #dbeef8;
}
#main
{
    float: left;
    width: 506px;
    padding: 10px;   
    border: thin dashed green;
   height: 100%;
}

#sidebar
{
    border: thin dashed #FF0000;
    float: right;
    width: 200px;
    padding: 10px;
    height: 100%;
}
#footer
{
    clear: both;
    padding: 5px 10px;
    background: #cc9;
}

note: there is a "wrap" div and it's also needed because it wraps a header that i omitted.

A: 

I keep reading about sleazy CSS hacks to achieve this, or fake it.

At the risk of drawing the ire of the CSS purist crowd, whenever this comes up for me, I use tables. "Semantics and presentation" be damned, so long as CSS doesn't offer sensible solutions for commonplace problems like this, I'll stick with what works.

If you could guarantee that your page will always be shown in a JavaScript-enabled browser, you could do the sizing dynamically. But this would be far from my first choice.

Carl Smotricz
I don't want to use tables... tables are not for layous IMHO
samuel
Yep, I agree. Use the best tool for the job. Evaluate your requirements and implement what meets them all with the least amount of effort.
Rimian
Why tables for layout is stupid: http://www.hotdesign.com/seybold/everything.html
samuel
So did this admittedly very pretty site offer a solution to your problem?
Carl Smotricz
it offers an approach i need to find the solution
samuel
I disagree; it presents a glitzy and hyped-up argument why you shouldn't do the one thing that would easily solve your problem.
Carl Smotricz
anyway, i want a css solution.
samuel
And I want a date with Heidi Klum! Good luck.
Carl Smotricz
and good luck with your date :)
samuel
A: 

Though I am not fond of CSS expressions

height:expression("selector".Height< min-height? min-height : "auto" );
ram
http://msdn.microsoft.com/en-us/library/ms537634(VS.85).aspx: As of Windows Internet Explorer 8, dynamic properties have been deprecated and are only supported for Web pages displayed in IE5 mode or IE7 mode.
Carl Smotricz
Still, interesting information. I wasn't aware this existed!
Carl Smotricz
I wano to use simple CSS
samuel
and if dynamic properties indeed deprecated, it's useless.
samuel
+1  A: 

To answer your second question:

#content
{
    border: 1px solid #000000;
    height: 100%;
    background-color: #dbeef8;
    /* new part */
    overflow: hidden;
}

Your first question is a bit harder. In my order of preference (depending on circumstances):

  1. You can fake it using backgrounds for #main, #sitebar and #content.
  2. You can use javascript to get the tallest column and apply that height to the other one as well.
  3. You can use display:table and display:table-cell if IE6 and IE7 (older browsers in general actually...) are not a requirement.

Cross-browswer pure css is not possible I´m afraid.

jeroen
A: 

Equal height columns with pure CSS. I added a min-height since you asked for it. There is the one IE6 hack purely for the min-height since IE6 doesn't understand min-height, but treats height as min-height. This is a striped down version of this.. http://matthewjamestaylor.com/blog/equal-height-columns-2-column.htm

#container2 {
clear:left;
float:left;
width:100%;
overflow:hidden;
background:#ffa7a7;}
#container1 {
float:left;
width:100%;
position:relative;
right:50%;
background:#fff689; /* column 1 background colour */
}
#col1 {
float:left;
width:46%;
position:relative;
left:52%;
overflow:hidden;
_height:700px;
min-height:700px;
}
#col2 {
float:left;
width:46%;
position:relative;
left:56%;
overflow:hidden;
_height:700px;
min-height:700px;
}


<div id="container2">
<div id="container1">
 <div id="col1">
  <p>some text</p>
 </div>
 <div id="col2">
  <p>some text</p>
 </div>
</div>

chrismjones
Can it be modifed to use width and positions in pixels instead of percentage?
samuel
Sorry I was away and didn't see your question. It should work just fine with px instead of percentages. If nothing else, dropping a pixel width on one of the containers with the columns should have the desired affect.
chrismjones
A: 

The following is the answer I got from the author of the "stupid tables" page http://hotdesign.com/seybold/everything.html whom you cited in your comments. I figured that if he was going to go to the effort of giving this advice to people, I might as well ask him for a hint on how to solve this particular problem.

Hi Carl,

You could float all three, the wrap, the content, and the sidebar. That would contain everything. If you put a background image on the wrap, it would appear that the sidebar were the same height as the main content.

Or you could use overflow:auto on the wrap. That would also contain the floats.

However, I do not advocate uncompromising adherence to CSS layouts. 99% of the time, they are the way to go. But the other 1% of the time, tables are the only practical answer.

Table cells are the only elements in HTML that resize according to the content and dimensions of adjacent elements.

I'm glad you think the site was pretty. I hope you found other things of value there.

Cheers,

Bill

I'm happy to see he agrees with me that it's not practical to ALWAYS steer clear of tables.

Carl Smotricz
thanks for your time and effort.chrismjones answered my question.
samuel
I can't vote you up, because I am not registered :(
samuel
Cool, it's the thought that matters. I'm not hurting for reputation :)
Carl Smotricz