I am trying to set my gridview (asp.net) position to absolute when the gridview stretches further than the standard 960 pixels.
However I have run across the issue where left: 0 has the effect I desire, however anything other than that does nothing.
Here is my code. The section where it’s less than the screen doesnt work because i am trying to center it to the screen. However as it’s greater than 0 the absolute position of Left: x doesn’t work. Any help would be appreciated!
var gridview = document.getElementsByTagName("table");
var fieldset = document.getElementsByTagName("fieldset");
fieldset[0].style.position = "relative";
for (var i = 0; i < gridview.length; i++) {
var width = gridview[i].offsetWidth;
var screenWidth = window.screen.width - 2;
if (width > 940) {
gridview[i].style.position = "absolute";
if (width > screenWidth) {
gridview[i].style.left = 0;
alert('> screen');
}
else {
gridview[i].style.left = 50;
alert('< screen');
}
}
}
EDIT: The fix was to concat ‘px’ after the value
Not really go enough to go on, but it might be the case that the container of gridview hasn’t had its position set your css.
To use the
postion:absolutethe above container should be set toposition:relativeor it just wont render the css.Also try adding px to the end of your size, setting the css to left:XXpx; rather than just a number.