Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change body width using javascript

I just came to know that we can find out the screen resolution of our users using screen.width and screen.height etc. But is there any way to have a variable body width. I mean can i set the body width property using jquery or javascript. This is gonna change with the resolution of every user so that my site seems perfect in all of them...

Can anyone help me in having code to set the width(CSS) of my page according to the value obtained through Jscript above.

Thanks

like image 495
Prashant Singh Avatar asked Jul 08 '11 04:07

Prashant Singh


2 Answers

You can set the body with JavaScript...

document.body.style.width = '700px';

...or if you are using jQuery...

$('body').css('width', '700px');
like image 153
alex Avatar answered Oct 20 '22 12:10

alex


You can use jquery and do it through .css

$('body').css('width', '1000px');

css() documentation.

like image 45
kobe Avatar answered Oct 20 '22 12:10

kobe