Javascript 使用javascript更改身体宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6620029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change body width using javascript
提问by Prashant Singh
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...
我刚开始知道我们可以使用 screen.width 和 screen.height 等来找出用户的屏幕分辨率。但是有没有办法让主体宽度可变。我的意思是我可以使用 jquery 或 javascript 设置主体宽度属性。这将随着每个用户的分辨率而改变,以便我的网站在所有用户中看起来都很完美......
Can anyone help me in having code to set the width(CSS) of my page according to the value obtained through Jscript above.
任何人都可以帮助我根据上面通过 Jscript 获得的值设置页面宽度(CSS)的代码。
Thanks
谢谢
回答by alex
You can set the body with JavaScript...
您可以使用 JavaScript 设置正文...
document.body.style.width = '700px';
...or if you are using jQuery...
...或者如果您使用的是 jQuery ...
$('body').css('width', '700px');
回答by kobe
You can use jquery and do it through .css
您可以使用 jquery 并通过 .css 来完成
$('body').css('width', '1000px');