473,382 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

CSS for 2 row and 2 col layout

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
Jul 20 '05 #1
2 12832
"Peter Foti" <pe****@systolicnetworks.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?
.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 <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #2
"Steve Pugh" <st***@pugh.net> wrote in message
news:8k********************************@4ax.com...
"Peter Foti" <pe****@systolicnetworks.com> wrote:
I want to create a 2 row and 2 column layout (without using tables... eventhough 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! :)
.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 doesnot.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 thisworking.


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!!!
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
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

82
by: Peter Diedrich | last post by:
The site design is pretty simple: ============================================ | Head | ============================================ | | ...
39
by: Zak McGregor | last post by:
Hi all Are there any good solutions to aligning form field names and input boxes without resorting to tables? I am struggling to do this nicely at the moment. Thanks Ciao Zak
47
by: Neal | last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A quite good article.
20
by: Tammy | last post by:
What would be a good alternative to using frames? I need something that will section my webpage into two halves and can change both frames on a single click. Thanks in Advance, Tammy
10
by: Volker Lenhardt | last post by:
For a QApplication (PyQt) on the small screen of my Zaurus 5500 PDA I try to layout my data output in a QScrollView as the central widget. I'd prefer to use QGridLayout, but cannot add it to the...
10
by: Luke | last post by:
Hi. I am trying to make correct layout, here is an example of (dynamically generated content via jsp): http://localhost/www/layout.htm Most outer div is positioned absolute (if not then it...
3
by: Samuel Shulman | last post by:
I am looking for good guidance for positioning controls on the form.document, it is absolute nightmare and I don't know where to begin Thank you, Samuel Shulman
5
by: Jeff User | last post by:
Hi all I am writing program/framework to server a web site dynamically based on stored web page data with C#, .net1.1 What is the preferred means of controlling page layout, frames or...
5
by: Ed Sproull [MSFT] | last post by:
First I'm pretty new to ASP.NET and I'm having a simple problem. I have small website with a header, sidebar and the the content. I want my content to appear beside my sidebar which seems to be a...
53
by: brave1979 | last post by:
Please check out my javascript library that allows you to create any layout for your web page, nested as deep as you like, adjusting to width and height of a browser window. You just describe it in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.