Forum Moderators: open

Message Too Old, No Replies

Tables and the height attrib

XHTML Valid?

         

madcat

4:48 pm on Apr 19, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi-

I ran a site search but couldn't find this particular problem...

I have a table that runs about 70% of the length of a page. I want to center that table so that there would be 15% of background above and 15% below. That way on any resolution screen it would appear centered. Is there a way that I could do this without using the height attribute? Or do I have to wrap it in a table or two using height? Another goal is to make it XHTML valid and height won't cut it.

[personal.atl.bellsouth.net ]

Thanks

pcguru333

4:56 pm on Apr 19, 2002 (gmt 0)

10+ Year Member



Only thing that comes to mind is using CSS relative positioning.

There have been threads on this in the recent past. Maybe I could do a search in a minute...

jatar_k

5:00 pm on Apr 19, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



maybe one of these?

[webmasterworld.com...]
[webmasterworld.com...]

toadhall

5:06 pm on Apr 19, 2002 (gmt 0)

10+ Year Member



Try this:

<center>
<script language="JavaScript">
document.writeln('<table border="2" height="',
screen.height -190,'"><tr><td>')
</script>
By entering + or - a number, it becomes more or less than 100% in any screen resolution.
</td></tr></table>
</center>

toadhall

6:11 pm on Apr 19, 2002 (gmt 0)

10+ Year Member



What I meant, but didn't say (bad habit), was "try hacking this". So, I did and here's the result. Think it might do the trick?

<center>
<script language="JavaScript">
document.writeln('<table border="1" height="100%" width="', screen.width -170,'">');
document.writeln('<tr><td height="', screen.height / 10 * 1.5,'"> </td></tr>');
document.writeln('<tr><td height="70%">');
</script>

Content goes here.<br>

<script language="JavaScript">
document.writeln('</td></tr>');
document.writeln('<tr><td height="', screen.height / 10 * 1.5,'"> </td></tr></table>');
</script>
</center>

Just turn off the borders attribute.

papabaer

6:23 pm on Apr 19, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try adjusting <div> & CSS I included (I added a border for visual testing - and just because Brett hates "dotted borders"... ;))

Works even in NN4.x and will validate XHTML (I also added a TABLE Summary - Accessibility!).

<div style="padding: 10px 20px; margin: 15% 5%; border: 1px dotted #333;">
<table border="0" width="100%" cellpadding="0" cellspacing="0" summary="Quentin Tarantino">
<tr>
<td class="color" width="145"><img src="images/whois.gif" width="145" height="33"
alt=" " /><br />
<img src="images/bio.gif" width="145" height="33" alt=" " /><br />
<img src="images/filmo.gif" width="145" height="33" alt=" " /><br />
<img src="images/stories.gif" width="145" height="33" alt=" " /> <img
src="images/move.gif" width="145" height="33" alt=" " /><br />
<img src="images/what.gif" width="145" height="33" alt=" " /></td>

<td class="color" width="1"><img src="images/line2.gif" width="1" height="300"
alt=" " /></td>

<td class="color"> </td>

<td class="color" width="20"><img src="images/line.gif" width="20" height="300"
alt=" " /></td>

<td class="color" width="196"><img src="images/quentintarintino.jpg" width="196"
height="300" align="right" alt=" " /></td>
</tr>
</table>
</div>

madcat

9:53 pm on Apr 20, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Man, you all rock.

toadhall-->That code is very cool, is there anyway to make that code follow a 'liquid-type' format. When I change screen.width (-170) to screen.width (-2) a horizontal scrollbar appears and all hell breaks loose. I suppose after seeing this script; it would be possible to write some code that could place my table in the center of each screen resolution? Can you recommend a nice JavaScript book to learn from?

papabaer-->Works just fine, and so simple too. The problem though is that the tables position is relative to the browser chrome. Is there anyway to keep it in the center, where I don't have to worry about it moving around on me?

Just wondering...and thanks again for all you guys help.

papabaer

11:11 pm on Apr 20, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No problem madcat!

>>>>> Is there anyway to keep it in the center, where I don't have to worry about it moving around on me?

I'm not quite certain what you mean, could you explain a little more?

toadhall

4:08 am on Apr 21, 2002 (gmt 0)

10+ Year Member



It's been fun writing this. Better have been - I'm feeling a bit loopy.

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>table_max_set3</title>
<style type="text/css">
<!--
body {font-family:verdana,helvetica,sans-serif; font-size:11.4px;background:#c8e0d8;line-height: 1.3}
td {font-family:verdana,helvetica,sans-serif; font-size:11.4px}
-->
</style>
<script language="JavaScript">
<!--
// Set your margins as screen %. Don't leave them blank.

var top = 15;
var bottom = 15;
var left = 5;
var right = 5;

// Don't touch
var cellh = 100 - (top + bottom);// "Content" cell height
var cellw = 100 - (left + right);// "Content" cell width

function ver(mojo){
if (mojo == 0){
return(1);
} else {
vset = mojo / 10;
return(screen.height / 10 * vset);
}
}

function hor(mojo){
if (mojo == 0){
return(1);
} else {
hset = mojo / 10;
return(screen.width / 10 * hset);
}
}

//-->
</script>
</head>
<body style="margin:0px" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center>
<script language="JavaScript">
document.writeln('<table border="0" height="100%" width="100%"><tr>');
document.writeln('<td rowspan=3 width="'+hor(left)+'"> <br></td>');// left
document.writeln('<td height="'+ver(top)+'"> <br></td>');// top
document.writeln('<td rowspan=3 width="'+hor(right)+'"> <br></td></tr><tr>');// right
document.writeln('<td height="'+cellh+'%" width="'+cellw+'%" align="center"bgcolor="red">');
</script>

Content goes here.<br>

<script language="JavaScript">
document.writeln('</td></tr><tr>');
document.writeln('<td height="'+ver(bottom)+'"> <br></td>');// bottom
document.writeln('</tr></table>');
</script>
</center>
</body>
</html>

It really is goofy. Have a feeling I've just reinvented the wheel (CSS) and haven't done a very good job of it.

Oh well. Hope you're as amused as I am.

toadhall

4:25 am on Apr 21, 2002 (gmt 0)

10+ Year Member



Forgot these.

>code that could place my table in the center of each screen resolution

Not sure what you mean.
Not sure I want to know what you mean.

>recommend a nice JavaScript book

Anyone that has "a beginner's guide" as part of its title.

The O'Reilly Definitive Guide is , er... definitive, but a beginner's book is uncluttered and methodical. Test the index of the ones you run across. That is, try to find information in the book through it. If you can't, it's not you, it's the book - pick another one. You'll be using it as a reference guide for some time so it's got to have a good index. And glossary for that matter.

Check the remainders bins at stationery stores. You can pick up half price bargains or better. It may not cover the latest version but so what? 1.0 and 1.1 still work. And in more places!

And now, it's back to me pint.

Purple Martin

1:48 am on Apr 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>recommend a nice JavaScript book

I use the JavaScript Bible by Danny Goodman. It's superbly written, logically laid out, and covers absolutely everything (with sample code). It really is my bible, I keep it next to me at all times for quick and easy reference. You can buy it from the major online bookstores.

madcat

4:14 am on Apr 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks purple_martin::

>>>>> Is there anyway to keep it in the center, where I don't have to worry about it moving around on me?

I'm not quite certain what you mean, could you explain a little more?

All I mean is that when you expand and contract the menus up top (like the URL menu for example) The table moves with them. The table only looks centered say if my URL menu and my menu with FILE EDIT VIEW ETC... are expanded. I want it to stay centered at any screen configuration or resolution--JavaScript must provide a way...or maybe fixing the position of the div using percentages or something...? Hope that makes some sense, a bit late.

madcat

2:08 am on Apr 23, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One last problem is that my main scroll bar isn't being generated. If all of your menus are expanded and the table falls below the bottom margin...there is no way to scroll, why would this happen? I am looking on at 800*600.

[personal.atl.bellsouth.net ]

Thanks for any help...