Current location: Hot Scripts Forums » General Web Coding » CSS » Convert table to CSS


Convert table to CSS

Reply
  #1 (permalink)  
Old 07-26-09, 03:20 AM
Frogger Frogger is offline
Wannabe Coder
 
Join Date: Jul 2006
Posts: 149
Thanks: 5
Thanked 0 Times in 0 Posts
Convert table to CSS

Hi,
I am slowly teaching myself CSS but can not work out if it is possible to convert the below page layout I have created using tables into CSS layoit. Is it possible as its doing my head in trying to work it out.

Code:
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="50%" bgcolor="red">&nbsp;</td>
  </tr>
  <tr>
    <td height="600" bgcolor="black">&nbsp;</td>
  </tr>
  <tr>
    <td height="50%" bgcolor="blue">&nbsp;</td>
  </tr>
</table>
I basically want the middle to be 600px high and the top and bottom of the page will grow to the size of the browser. The width will be 100%.
Any ideas and is it possible?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-26-09, 09:27 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
HTML Code:
<html>
<head>
<title>div test</title>
<style type="text/css">
body
{
width:800px;
height:600px;
padding:0;
margin:0 auto;
color:#fff;
}
.outer
{
width:800px;
height:600px;
}
.left,.center,.right
{
float:left;
}
.left
{
height:50%;
width:25%;
background-color:red;
}
.center
{
height:100%;
width:50%;
background-color:black;
}
.right
{
height:50%;
width:25%;
background-color:blue;
}
</style>
</head>
<body>
<div class="outer">
	<div class="left">Left</div>
	<div class="center">Center</div>
	<div class="right">Right</div>
</div>
</body>
</html>
Tested with IE7, FF3
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-26-09, 04:35 PM
Frogger Frogger is offline
Wannabe Coder
 
Join Date: Jul 2006
Posts: 149
Thanks: 5
Thanked 0 Times in 0 Posts
Thanks wirehopper for getting back to me.
Your script ran vertically. I am trying to get the CSS to run horizontal so that the black part (middle) stays at 600px high and the top (red) and bottom (blue) grow in height depending on how big the browser is sized. I have attached image to display how tables get this to work.
Any ideas are much appreciated.
Attached Images
File Type: jpg boom.jpg (29.7 KB, 814 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-26-09, 08:18 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Sorry - I didn't see all the <tr> tags.

You might want to check min-height and max-height for the top and bottom, to give you some adjustment space. I'm not sure it is possible.

You may also be able to use javascript to adjust the div dimensions at page load. Check out the window.screenX property (spelling might be off, go to w3schools.com).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-27-09, 06:44 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
HTML Code:
<html>
<head>
<title>div test</title>
<style type="text/css">
body
{
padding:0;
margin:0 auto;
color:#fff;
}
.outer
{
width:100%;
}
.left
{
background-color:red;
}
.center
{
vertical-align:middle;
height:600px;
background-color:black;
}
.right
{
background-color:blue;
}
</style>
</head>
<body>
<div class="outer">
	<div class="left">Left<br />And a bit more ...</div>
	<div class="center">Center</div>
	<div class="right">Right<br />And a bit more ...</div>
</div>
</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 07-27-09, 04:46 PM
Frogger Frogger is offline
Wannabe Coder
 
Join Date: Jul 2006
Posts: 149
Thanks: 5
Thanked 0 Times in 0 Posts
Hi wirehopper,
Thanks for your reply.
I had the same problem with my CSS code as you did.
For some reason with CSS it is hard to get the height at 100% or 50%.
ie the red and the blue rows dont stretch out to the height of the web browser like the table code does unfortunatley.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 07-27-09, 06:42 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
You could also try a layered approach, with z-index.

Also - min-height is a good thing to try.

You could set the body background color to the same color as the bottom div - and have the bottom div background actually be transparent or none.

Hope these ideas help, good luck!

PS - Please post your solution.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 07-27-09, 09:46 PM
advanceddesigns advanceddesigns is offline
Newbie Coder
 
Join Date: May 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
you need to set your div tags behind your main div. you should have 3 div tags then your main div tag. that should solve you problem
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 07-27-09, 09:56 PM
Frogger Frogger is offline
Wannabe Coder
 
Join Date: Jul 2006
Posts: 149
Thanks: 5
Thanked 0 Times in 0 Posts
I tried this but I just cant get the top and bottom to size according to the browser size like I can with the tables.

Code:
<html>
<head>
<title>div test</title>
<style type="text/css">

body {
padding:0;
margin:auto;
}

.outer {
width:100%;
}

.top { 
background-color:red;
height: 50%;
}

.center {
vertical-align:middle;
height:600px;
background-color:black;
}

.bottom {
background-color:blue;
height: 50%;
}
</style>
</head>

<body>

	<div class="top">top</div>

<div class="outer">
	
	<div class="center">Center</div>
	
</div>

	<div class="bottom">bottom</div>
</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I center an ID'd table using CSS? likegluelikecrew CSS 4 04-30-09 05:57 AM
table layout vs css layout harish CSS 8 04-21-09 08:59 PM
MYSQL database countll Database 2 06-19-07 05:20 PM
IE and Firefox Table + CSS Help iidavidii HTML/XHTML/XML 5 12-04-06 12:29 PM
Table Through CSS xtreme231 CSS 1 08-11-05 02:26 PM


All times are GMT -5. The time now is 11:36 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.