Click to See Complete Forum and Search --> : Table to CSS


blank
03-14-2007, 10:43 PM
Hey guys, I've read about how it's bad to use tables for the layout of a page, and have been suggested to use CSS instead. However, I'm no web developer, and I was wondering if you guys could help me transfer this snippet to XHTML/CSS. I've done some of it, very little actually. Here is the original snippet:


<table class="maintable">
<tr>
<td>
<table align="center" cellpadding="0" cellspacing="1" class="table-border">
<tr>
<td class="box">
<center><br />
<img src="media/images/banner.png" alt="The Company" /><br />
<h2>We are currently under construction.</h2>
<hr class="sep" />
Sorry for the inconvenience.<br />
If you wish to contact me, you can email me at <strong>admin@site.com</strong><br />
</center>
</td>
</tr>
</table>
</td>
</tr>
</table>


The stylesheet is here:


/* main site style sheet */

.table-border {
background-color: #D1D8DD;
width: 80%;
}

.box {
font-size: 12px;
color: #000;
background-color: #F1F1F1;
padding: 4px;
}

.construct {
font-size: 12px;
color: #000;
background-color: #F6F6F6;
padding: 4px;
}

.maintable {
height: 100%;
width: 100%;
}

.sep {
width: 25%
}


I know this might seem like I'm asking you guys to 'do my homework', but I honestly have tried, and here is something to prove it (I know it isn't much, but...):


<body class="construct">
<div class="box">
<center>
<img src="media/images/banner.png" alt="The Company" /><br />
<h2>We are currently under construction.</h2>
<hr class="sep" />Sorry for the inconvenience.<br />If you wish to contact me, you can email me at <strong>admin@site.com</strong>
</center>
</div>
</body>


I'm sorry for being very 'sudden' and making it all seem rushed, fact of the matter is that I'm in a hurry. If you guys don't have time to help me out completely, I'd still appreciate any type of response, even if they are general responses which could get me out out of this, as I'm kind of stuck.

If you are wondering what this actually looks like, here is an example (http://www.newconceptsonline.net/).

Thanks again guys, I appreciate your time.

Siddan
03-14-2007, 11:00 PM
ok, but what is it really you want help with?

All look ok and all I can recommend you is to lose the center tag and the class for the Body tag

For the class box, use a new attribute:
text-align:center

For the body....
In the CSS, use body instead of .construct
and you do not have to repeat the attributes for the box again

also for the hr. Lose the class and style the hr directly from the CSS as you should do with the body tag

blank
03-14-2007, 11:33 PM
Thanks I appreciate the reply, but the page doesn't quite look like I'd like. You could find the one I'm working on here (http://www.newconceptsonline.net/proto.php). As you can probably see, the original (http://www.newconceptsonline.ne) has a border around it. That's actually what I was having trouble with, sorry for not clarifying in the first post.

I appreciate your help!

Siddan
03-15-2007, 07:12 AM
Aha alright :)

Add these three attributes under the .box in the css

width:80%;
margin:0 auto;
border:1px solid #D1D8DD;

This should then look like the tabled one


I could give you a tip btw the beauty of css, so that you do not have to assign a class to every element you want to affect.

Take the HR for an example. It is inside the div.box element.
So unless you are not intending to have every HR the same you could do like this...

.box hr {width:25%}


cheers

WebJoel
03-24-2007, 11:16 AM
I was playing around with your design and came up with this (looks the same in Fx and IE, no errors or warnings).

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title></title>
<style type="text/css">
* {border:0; padding:0; margin:0;}/* Set everything to "zero" */

body {min-height:100%; height:101%; padding-bottom:40px;
font:x-small Arial, Verdana, sans-serif;
voice-family: "\"}\"";voice-family:inherit;
font-size:small;/*for IE 5.5 */
} html>body {font-size:small;}
/*font-size: small; voice-family: "\"}\"";
voice-family: inherit; font-size: medium;*/} /* Assist IE rendering height, keyword-font sizes, etc. */

p {font-size: 90%; line-height:1.2em; margin-top:6px;}
h1, h2, h3, h4, h5, h6 {font-family: 'times new roman', arial, verdana, serif; background-color:none;
font-style:normal; font-variant:normal; font-weight:normal; margin:11px 0 0 10px;}
h1{font-size: 1.93em; margin:15px 0 12px 0;}
h2{font-size: 1.72em; margin-top:12px;}
h3{font-size: 1.52em; margin-top:12px;}
h4{font-size: 1.42em; margin-top:12px;}
h5{font-size: 1.32em; margin-top:12px;}
h6{font-size: 1.21em; margin-top:12px;}

#wrapper {position:relative; width:760px; height:100%; background-color:#f7f3f7; margin:10px auto; border:2px solid #d6dbd3;}
#content {width:92%; height:auto; padding-bottom:45px; margin:0 auto;}
.imgLeft {width:150px; height:85px; border:1px solid gray; margin:12px; float:left;}
.imgRight {width:150px; height:85px; border:1px solid gray; margin:12px; float:right;}
#footer p {position:absolute; bottom:-25px; width:760px; text-align:center;}

</style>

<script type="text/javascript"><!--
// -->
</script>
<link rel="shortcut icon" href="favicon.ico"><!-- path to your favicon -->
</head>
<body>

<div id="wrapper">

<img alt="New Concepts Wood Works" src="images/banner.png" style="position:relative; top:10px; left:140px;" />

<div id="content">
<h1 title="Under Construction: First 'first-level header" style="width:100%; text-align:center;">This site is under construction</h1>

<h1 title="First-level header">First-level header</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Suspendisse egestas ultricies pede. Phasellus suscipit blandit risus.
Praesent nonummy. In erat. Duis nibh pede, accumsan eu, pulvinar et,
volutpat vel, elit.

<img alt="First image, floated left" src="#" class="imgLeft" />
<img alt="Second image, floated right" src="#" class="imgRight" />

Curabitur nec dui sed nunc congue tempus. Nulla ac
dui ac libero fringilla nonummy. Maecenas ullamcorper sodales risus.
Vivamus pretium dolor. Proin eu turpis. Phasellus ut mauris non nulla
mattis luctus. Nunc porttitor dapibus sapien. In malesuada fermentum
metus. Nulla egestas, tellus a vestibulum pharetra, nunc purus auctor
lacus, ut semper purus ipsum eu velit. Praesent dui. Nulla accumsan
turpis at erat.</p>

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Morbi lacus felis, euismod at, pulvinar sit amet, dapibus eu, eros.
Etiam tellus. Nam vestibulum porttitor urna. Phasellus aliquet pretium
quam. Proin pharetra, wisi nec tristique accumsan, magna sapien pulvinar
purus, vel hendrerit ipsum tellus at ante.</p>

<h2 title="Second-level header">Second-level header</h2>

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Morbi lacus felis, euismod at, pulvinar sit amet, dapibus eu, eros.
Etiam tellus. Nam vestibulum porttitor urna. Phasellus aliquet pretium
quam. Proin pharetra, wisi nec tristique accumsan, magna sapien pulvinar
purus, vel hendrerit ipsum tellus at ante.</p>
</div>

<div id="footer">
<p>If you wish to <a title="Sends e-mails to jorge@newconceptsonline.net" href="mailto:jorge@newconceptsonline.net">contact me</a>, you can email me at <a title="Sends e-mails to jorge@newconceptsonline.net" href="mailto:jorge@newconceptsonline.net">jorge@newconceptsonline.net</a></p>
</div>

</div>

</body>
</html> This assumes that the image "banner.jpg" resides in a folder called "images".
The BOLD text in "<style></style>" is what replaces the TABLE layout. The non-bold text in "<style></style>" just gets the fonts, margins and padding and other stuff to work right across different browsers.

blank
03-24-2007, 11:27 AM
Cool thanks I appreciate it.