PDA

View Full Version : 100% width but limited to certain width?


gorilla1
10-06-2002, 03:09 AM
There was a couple of lines of code posted here once that was for a page that was set up to use a 100% table, but that wanted to limit that to the 1024 screensize, since the page went meaningless stretched too large. Does anyone have a link to that or know how it worked?

G

Graeme Hackston
10-06-2002, 06:36 AM
I don't know the thread you're refering to but something like this should work (not tested)

var TableWidth = document.getElementById('mytable').offsetWidth;
if (TableWidth > 1024) {
document.getElementById('mytable').style.width = 1024 + "px";
}

You could also use the window width, the function is cross browser but, like the above, it will only work with DOM browsers.

function iw() {
if (window.innerWidth) {
w = window.innerWidth
} else if (document.documentElement && document.documentElement.clientWidth) {
w = document.documentElement.clientWidth
} else if (document.body) {
w = document.body.clientWidth
}
return w
return null;
}


then:

if (iw() > 1024) {
document.getElementById('mytable').style.width = 1024 + "px";
}

I think you'd also have to reverse them so it doesn't stay at 1024 if the window is made smaller.


<edit>Actually, looking at it, the first one is irreversible without using another variable like the clientWidth. Maybe a combination of the 2 would do it.</edit>