HighDots Forums  

CSS for 2 row and 2 col layout

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss CSS for 2 row and 2 col layout in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Peter Foti
 
Posts: n/a

Default CSS for 2 row and 2 col layout - 12-08-2003 , 10:04 AM






I want to create a 2 row and 2 column layout (without using tables... even
though the resulting code looks very table-like). Here's the sample HTML
code I have so far:

<div class="row">
<div class="col1">Top Left</div>
<div class="col2">Top Right<br><br><br>Still here</div>
</div>
<div class="row">
<div class="col1">Bottom left</div>
<div class="col2">Bottom right</div>
</div>

And here's the styles applied:

..row { display: block; }
..col1 { border: 1px solid blue; background-color: #eee; float: left; width:
100px; margin: 0; padding: 0;}
..col2 { border: 1px solid red; background-color: #ddd; width: 100px; margin:
0; padding: 0; }

IE displays the results close to what I would expect (though there is a
space between the columns that I can't seem to get rid of)... Mozilla does
not.display what I would expect (the columns are stacked vertically... as if
"float: left" was not applied). I'd appreciate any ideas on how to get this
working.

Thanks,
Peter Foti



Reply With Quote
  #2  
Old   
Steve Pugh
 
Posts: n/a

Default Re: CSS for 2 row and 2 col layout - 12-08-2003 , 10:33 AM






"Peter Foti" <peterf (AT) systolicnetworks (DOT) com> wrote:

Quote:
I want to create a 2 row and 2 column layout (without using tables... even
though the resulting code looks very table-like). Here's the sample HTML
code I have so far:

div class="row"
div class="col1">Top Left</div
div class="col2">Top Right<br><br><br>Still here</div
/div
div class="row"
div class="col1">Bottom left</div
div class="col2">Bottom right</div
/div

And here's the styles applied:

.row { display: block; }
As that's the default for div do you need to specify it? And in fact
do you actually need the row divs at all?

Quote:
.col1 { border: 1px solid blue; background-color: #eee; float: left; width:
100px; margin: 0; padding: 0;}
.col2 { border: 1px solid red; background-color: #ddd; width: 100px; margin:
0; padding: 0; }

IE displays the results close to what I would expect (though there is a
space between the columns that I can't seem to get rid of)... Mozilla does
not.display what I would expect (the columns are stacked vertically... as if
"float: left" was not applied). I'd appreciate any ideas on how to get this
working.
Guess what? IE is wrong and Netscape is right. The col2 divs still
start at the left hand edge of the parent, but any content in them
starts after the float. See the examples in the spec:
http://www.w3.org/TR/CSS2/visuren.html#floats
As you've set the width of col2 to 100px there is no room alongside
col1 for the text and so it must appear below col1.

One possible solution is:

..col1 { border: 1px solid blue; background-color: #eee; float: left;
width: 100px; margin: 0; padding: 0; clear: both;}
..col2 { border: 1px solid red; background-color: #ddd; width: 100px;
margin: 0 0 0 102px; padding: 0; }

<div class="col1">Top Left</div>
<div class="col2">Top Right<br><br><br>Still here</div>
<div class="col1">Bottom left</div>
<div class="col2">Bottom right</div>


cheers,
Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <steve (AT) pugh (DOT) net> <http://steve.pugh.net/>


Reply With Quote
  #3  
Old   
Peter Foti
 
Posts: n/a

Default Re: CSS for 2 row and 2 col layout - 12-08-2003 , 11:32 AM



"Steve Pugh" <steve (AT) pugh (DOT) net> wrote

Quote:
"Peter Foti" <peterf (AT) systolicnetworks (DOT) com> wrote:

I want to create a 2 row and 2 column layout (without using tables...
even
though the resulting code looks very table-like). Here's the sample HTML
code I have so far:

div class="row"
div class="col1">Top Left</div
div class="col2">Top Right<br><br><br>Still here</div
/div
div class="row"
div class="col1">Bottom left</div
div class="col2">Bottom right</div
/div

And here's the styles applied:

.row { display: block; }

As that's the default for div do you need to specify it? And in fact
do you actually need the row divs at all?
I wasn't sure if I needed to specify it. And it seems that I don't need to
include the div rows after all!

Quote:
.col1 { border: 1px solid blue; background-color: #eee; float: left;
width:
100px; margin: 0; padding: 0;}
.col2 { border: 1px solid red; background-color: #ddd; width: 100px;
margin:
0; padding: 0; }

IE displays the results close to what I would expect (though there is a
space between the columns that I can't seem to get rid of)... Mozilla
does
not.display what I would expect (the columns are stacked vertically... as
if
"float: left" was not applied). I'd appreciate any ideas on how to get
this
working.

Guess what? IE is wrong and Netscape is right. The col2 divs still
start at the left hand edge of the parent, but any content in them
starts after the float. See the examples in the spec:
http://www.w3.org/TR/CSS2/visuren.html#floats
As you've set the width of col2 to 100px there is no room alongside
col1 for the text and so it must appear below col1.
Ahh!!!

Quote:
One possible solution is:

.col1 { border: 1px solid blue; background-color: #eee; float: left;
width: 100px; margin: 0; padding: 0; clear: both;}
.col2 { border: 1px solid red; background-color: #ddd; width: 100px;
margin: 0 0 0 102px; padding: 0; }

div class="col1">Top Left</div
div class="col2">Top Right<br><br><br>Still here</div
div class="col1">Bottom left</div
div class="col2">Bottom right</div
Exactly what I was shooting for! Of course, IE still displays a space
between the columns, but I assume that's some sort of IE width bug.
Thanks!
Pete




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.