Forum Moderators: not2easy
I'm battling to make a table-like layout using CSS. I need a 'table' with 4(or more!) multiple-column rows. If that makes any sense..
This is what I'm aiming at... basically :
¦----------------¦
¦ header ¦
¦----------------¦
¦ 50% ¦ 50% ¦
¦----------------¦
¦25%¦ 75% ¦
¦----------------¦
¦33% ¦33%¦ 33%¦
¦----------------¦
¦ footer ¦
¦----------------¦
Crude...I know...sorry.
I seem to be able to get the header, first row and footer ... I am using float:left and :right to keep them both in position, and clear:both for the footer...
However...I can't seem to "insert" that 2nd or 3rd row. And as you can see from my expertly crafted example(again - apologies), I would like to be able to vary the column sizes accross all the rows (unique to each row).
Thanks to anyone who can provide any insight....and a HUGE thank you if anyone can provide the basic skeleton CSS and Style code so that I can learn how the logic works.
I would be immensely grateful..
like this.
<div id="main_container">
<div class="basic_row">
//header info or header div
</div>
<div class="basic_row">
<div 1></>
<div 2></>
</div>
<div class="basic_row">
<div 1></>
<div 2></>
<div 3></>
</div>
<div class="basic_row">
<div 1></>
<div 2></>
</div>
<div class="basic_row">
//footer info or footer div
</div>
</div>
I hope that clear.
CSS
* {
margin: 0px;
padding: 0px;
}
body {
font: 10px Arial, Helvetica, sans-serif;
background: #CCCCCC;
}
#main_container {
width: 600px;
margin-top: 20px;
margin-left: 20px;
border: 1px solid #000000;
}
.basic_row {
clear: both;
position: relative;
border: 1px solid #990000;
}
.two_col {
float: left;
width: 50%;
background: #999933;
}
.clear_float {
font-size: 0px;
line-height: 0px;
clear: both;
}
HTML
<body>
<div id="main_container">
<div class="basic_row">
<div class="two_col">Content for class "two_col" Goes Here</div>
<div class="two_col">Content for class "two_col" Goes Here</div>
<div class="clear_float"></div>
</div>
</div>
</body>
Ok... easiest might be to just give you the code I am working with. I've managed to add a 2nd row, and size the columns differently, but it's not working 100% in EI (only in FF).
CSS: (external)
----
body,html
{
margin:0;
padding:0;
background:#000000;
color:#000;
text-align:center; /* Table Center alignment for IE */
}
div.container
{
width:750px; /*<<<< SET 'TABLE' SIZE HERE */
margin:0 auto; /* Table Center Alignment for FF */
background: #2D3F80;
}
/* -------------------------------------------HEADER */
div.header1
{
height:100px;
color:white;
background-color:gray;
clear:left;
}
h1.header1
{
padding:0;
margin:0;
}
div.header2
{
height:50px;
color:white;
background-color:gray;
clear:left;
}
h1.header2
{
padding:0;
margin:0;
}
/* --------------------------------------------ROW1 */
div.row1left
{
float:left;
background-color:#4F41AE;
width:375px;
height:200px;
}
div.row1right
{
float:left;
background-color:green;
width:375px;
height:200px;
}
/* --------------------------------------------ROW2 */
div.row2left
{
float:left;
background-color:blue;
width:550px;
height:150px;
}
div.row2right
{
float:left;
background-color:brown;
width:200px;
height:150px;
}
/* -----------------------------------------FOOTER */
div.footer
{
color:white;
background-color:gray;
clear:left;
}
HTML:
-----
<html>
<head>
<link rel="stylesheet" type="text/css" href="Glob_Style.css" />
</head>
<body>
<!-- -----------------------------------CONTAINER-->
<div class="container">
<!-- -----------------------------------HEADERS---->
<div class="header1">
<h1 class="header1">Header1</h1>
</div>
<div class="header2">
<h1 class="header2">Header2</h1>
</div>
<!-- -----------------------------------ROW1--L---->
<div class="row1left">
<p>Left 375pix</p>
</div>
<!-- -----------------------------------ROW1--R---->
<div class="row1right">
<p>right 375pix</p>
</div>
<!-- -----------------------------------ROW2--L---->
<div class="row2left">
<p>Left 550pix</p>
</div>
<!-- -----------------------------------ROW2--R---->
<div class="row2right">
<p>Right 200pix</p>
</div>
<!-- -----------------------------------FOOTER---->
<div class="footer">Footer</div>
</div>
</body>
</html>
OK..this seems to work ok in FF...but in IE it's not right. I just get the feeling that I am going about this the wrong way, which is why I have posted this topic.
Thanks in advance to anyone who can enlighten me.
Basically your rows would more or less be set up as such...
<!--ROW 1 START-->
<div class="basic_row">
<!-- -----------------------------------ROW1--L---->
<div class="row1left">
<p>Left 375pix</p>
</div>
<!-- -----------------------------------ROW1--R---->
<div class="row1right">
<p>right 375pix</p>
</div>
</div>
<!--ROW 1 END-->
<!--ROW 2 START-->
<div class="basic_row">
<!-- -----------------------------------ROW2--L---->
<div class="row2left">
<p>Left 550pix</p>
</div>
<!-- -----------------------------------ROW2--R---->
<div class="row2right">
<p>Right 200pix</p>
</div>
</div>
<!--ROW 1 START-->
And repeat for each row. This way your floats are contained. All you need to do is to create a rule for .basic_row like I did. Also create a clear float class like I did as well and place it before the </div> for the .basic_row div. Keep your container and header the way they are. See how that works.
Now...however...I have noticed that the text is displayed at different heights from IE to FF... :( *sigh*
The code is the same as I pasted above... could anyone help me understand why IE puts the text right at the top of the div element...but in FF there is some padding at the top, and the text shows a bit lower!?
This doesn't happen in the header sections, only in the different rows! :(
Thanks..
Anywho… Here’s the code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
<!--
/*Fix to even out differently rendered spacing of elements for all browsers. You will have to set spacing for elements as needed… i.e. <p>. this also This also makes it possible to give divs left and right auto margins in order to center in all browsers.*/
* {
margin: 0px;
padding: 0px;
}
body {
font: 10px Arial, Helvetica, sans-serif;
background: #000000;
color:#000000;
/*No Text Align Needed to center container div for IE if you use the * rule listed above.*/
}
/* Gave both headers different names to easily differentiate the two. Also made them IDs instead of classes because they are only used once on each page. I took them out of the container and gave them auto margins for centering on the page and a clear both value.*/
#top_header {
height:100px;
width:750px;
margin-left:auto;
margin-right:auto;
color:white;
background-color:#808080;
clear:both;
}
#top_header h1 {
/*There are many ways to style h tags. I do it this way so I don’t have to remember witch one is the style I need. This way I know that the h1 tag in this div looks like this and the h1 tag in the other div looks like that. but others have the own preferences.*/
}
#sub_header {
height:50px;
width:750px;
margin-left:auto;
margin-right:auto;
color:white;
background-color:#808080;
clear:both;
}
#sub_header h1{
/*There are many ways to style h tags. I do it this way so I don’t have to remember witch one is the style I need ("was it the h1, h2 or h4?"). This way I know that the h1 tag in this div looks like this and the h1 tag in the other div looks like that. but others have the own preferences.*/
}
/*Used to hold all basic_row containers*/
#container {
width: 750px;
margin-left: auto;
margin-right: auto;
background:#2D3F80;
}
/*Used to hold the different column floats*/
.basic_row {
clear: both;
}
/*Depending on what you want to do you can style these anyway you want as long as their combined width stays with in that 750px range. Don’t forget to account for padding, margins and borders. Either create one class and use it twice (or thrice) or create a style for each individual column (cell really) as you did. I did an example of both for the two column rows.*/
.two_col {
float: left;
background:#4F41AE;
width:375px;
height:200px;
}
.two_col_left
{
float: left;
background:#4F41AE;
width:375px;
height:200px;
}
.two_col_right
{
float: left;
background:#008000;
width:375px;
height:200px;
}
/*Used to clear all floats on in a row. Noticed it is placed before the closing tag of the basic_row div.*/
.clear_float {
font-size: 0px;
line-height: 0px;
clear: both;
}
/*Footer is set up the same as the header. but will be placed under the container div*/
#footer {
color:white;
clear:both;
background:#808080;
height: 75px;
width: 750px;
margin-right: auto;
margin-left: auto;
}
-->
</style>
</head>
<body>
<div id="top_header">
<h1>TOP HEADER</h1>
</div>
<div id="sub_header">
<h1>SUB HEADER</h1>
</div>
<div id="container">
<div class="basic_row">
<!--example using the same class for both columns but giving the second one a different color by using inline style.-->
<div class="two_col">COLUMN LEFT USING SAME CLASS</div>
<div class="two_col" style="background:#008000;">COLUMN RIGHT USING SAME CLASS WITH INLINE STYLE FOR BACKGROUND COLOR</div>
<div class="clear_float"></div>
</div>
<div class="basic_row">
<!--example using differnt classes each column-->
<div class="two_col_left">LEFT COLUMN USING DIFFERENT CLASS</div>
<div class="two_col_right">RIGHT COLUMN USING DIFFERENT CLASS</div>
<div class="clear_float"></div>
</div>
</div>
<div id="footer">FOOTER</div>
</body>
</html>