Forum Moderators: open
I've got two tables, one as a heading, with a title, etc., and a second with the content of the page in it. The top table must be 128 pixels in height. I want the bottom table to resize, so that its height is equal to 100%, (in the way that you might put "document.all.table1.style.height=100%"), minus 128 pixels. This will ensure that the bottom of the second table is always aligned with the bottom of the window.
I've attempted to make this happen using the following:
document.all.table1.style.height=parseFloat(100%)-128;
This has failed. What's wrong with that piece of code, and how can I get it to work?
Thanks in advance.
<html>
<head>
<title></title>
<style type="text/css">
html, body {height:100%;margin:0;padding:0;}
table {width:100%;height:100%;background-color:green;}
</style>
</head>
<body>
<table><tr><td>words</td></tr></table>
</body>
</html>
I've done javascript height sizing for another site, and it doesn't work reliably at all cross browser, especially on mac safari, this will always work, and will always display correctly whether or not the user has javascript enabled. That's because different browsers consider window height differently, opera for example sets it at I believe the entire height of the browser, not the display window part, which means you have to do browser sniffing to get the result you want, and it still won't work reliably.
But if you're a purist, you may be interested in this: you're not supposed to specify height for tables or table rows or table cells. Height is not a valid attribute for tables. Yes I know that isitreal didn't use an attribute, and used a CSS style for height instead (so the page will validate), but I think that this should be avoided in the same way that using an attribute should be avoided. This is because (for purists) tables are supposed to be for displaying tabular data, and they will automatically "grow" height to fit the data.
I'm being very pedantic, so feel free to ignore me and use the table. It's simple and it works! :-)
The real problem here is that browser coders have done such an amazingly good job with the table tag that it's really a waste not to use it in its full potential, who cares what the W3C says, their vision of the web is pretty drab as far as I'm concerned, it's not my vision, although CSS 1 and 2 are totally great, no doubt about that.
Not to say my code won't validate zero error and all that, but I'm going to go for functionality from now on I think, this discussion really cemented it for me, I wasn't sure before, although I was getting to that point. Why not just treat tags as what they are, ways to make the browser do something? Then follow the rules as closely as possible as long as it doesn't waste too much time in the process, and as long as it doesn't negatively impact your intention on page look and feel?
In other words, forget that a table is 'supposed' to be for x or y purpose. That definition is completely random, it's just something somebody said sometime, then they wrote a rule, that everybody ignored. A table is supposed to hold data, and a webpage is data, so what's the problem?
really the whole point is just to get something up on the web so people can see it
Not to say my code won't validate zero error and all thatYour code as posted above validates great with a doctype and a charset :-)
Why not just treat tags as what they are, ways to make the browser do something?
A table is supposed to hold data, and a webpage is data, so what's the problem?Actually, a table is supposed to hold tabular data, not just any information ;-)
I think one thing that is missed on some of these discussions is the importance of the page layout look and feel to the end user. I'm a bad designer, so when I get a page design from a designer, I try to duplicate it as exactly as possible, using clean HTML and CSS.
Usually the results the designer was looking for are almost impossible to reach using things like divs, or if I were to try to do it, the page template development and debugging time would be up to 20-50 times longer. I have a friend who is a designer and every time I show him a full div css site, he thinks it's very interesting and cool but sort of bland, missing something, which is what I see too in most cases.
Search engines don't care if stuff is in tables, obviously, or there wouldn't be very many results on them, they also don't care if stuff is in correctly coded frames or iframes, despite rumours to the contrary (I test this now and then with a new iframe content page and soon see my new section up on google in the top 10).
Using Opera's built in small handheld device emulator, you can see that all that happens with a table is that handheld screen just ignores the table tags and treats the data in the order it appears on the page, just like it would with divs.
So if the end user doesn't care, if the client doesn't care, and search engines don't care, and if the page loads in seconds, why should I spend that much time to satisfy a completely arbitrary definition of what a tag is 'supposed to be' for? I say this having tried this very thing many times over the last year.
Therefore, let me repeat the original question: is there a way in Javascript to set table heights dependent upon window height?
I tried to use window.innerHeight or window.dialogHeight, but for some reason IE6 does not return any of them.
Thanks for your help.