Change body width using javascript

心不动则不痛 提交于 2019-12-22 08:33:55

问题


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


回答1:


You can set the body with JavaScript...

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

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

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



回答2:


You can use jquery and do it through .css

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

css() documentation.



来源:https://stackoverflow.com/questions/6620029/change-body-width-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!