Page 1 of 1

table percents

Posted: Sun May 14, 2006 4:44 am
by s.dot

Code: Select all

<table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tr>
        <td width="49%">data</td>
        <td width="2%">&nbsp;</td>
        <td width="49%">data</td>
    </tr>
</table>
Now I know I shouldn't be using tables for layouts, and I shouldn't have just an &nbsp; in a table cell :P.

But, is it possible using this setup, to get the middle cell to be 1% and the other two cells to be equal in size? 2% seems to be a little too big. I think 1% would work nicely.

Posted: Sun May 14, 2006 5:08 am
by $phpNut
Why not do both 50% and use a CSS padding value?

Posted: Sun May 14, 2006 7:24 am
by Oren
I agree with $phpNut, but if for some reason it has to be like that, then 'auto' should do the trick :wink:

Posted: Sun May 14, 2006 3:58 pm
by s.dot
The padding goes on the inside of the table cell, but i have a border on the cells so I would need the padding to go on the outside. I'll try the auto.

Posted: Sun May 14, 2006 4:06 pm
by $phpNut
Now I know I shouldn't be using tables for layouts, and I shouldn't have just an &nbsp; in a table cell Razz.
So why are you using tables then? Just as a question.

Posted: Sun May 14, 2006 4:18 pm
by s.dot
Easier for me than trying to get div layers to be cross browser compatible. :P

Posted: Sun May 14, 2006 4:23 pm
by $phpNut
Ah shortcut then :?

Posted: Sun May 14, 2006 4:45 pm
by John Cartwright

Code: Select all

<table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tr>
        <td style="padding-right: 2px;">data</td>
        <td style="padding-left: 2px;">data</td>
    </tr>
</table>
wouldn't work as suggested?

Posted: Sun May 14, 2006 5:04 pm
by $phpNut
Why not mess with the cell spacing?

Code: Select all

<table width="100%" cellspacing="5px" cellpadding="0" border="0">
    <tr>
        <td style="border: 2px outset #666;">data</td>
        <td style="border: 2px outset #666;">data</td>
    </tr>
</table>
Admittedly if all the way around, but id does the job.

Posted: Mon May 15, 2006 12:08 am
by Benjamin
Why not a 2 column table with the left column padding set to Xpx?

Posted: Mon May 15, 2006 4:30 am
by matthijs
Maybe not using tables is easier. Of course don't know what the rest of the page/layout is supposed to do, but this works fine:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Untitled</title>
<style type="text/css">
<!-- 
#wrapper {}
#main { float:left;width:49.5%;border:1px solid #ddd;}
#sub { float:right;width:49.5%;border:1px solid #ddd;} 
#wrapper p {margin:0;padding:1em;}
-->
</style>
</head>
<body>
<div id="wrapper">
<div id="main">
<p>Data</p>
</div>
<div id="sub">
<p>Data</p>
</div>
</div>
</body>
</html>
Only issue is that below, say 500px window-width, the floated divs fall below eachother. So depending on thekind of layout you'll want to set a min-width or do something else.