如何在JavaScript中设置div的宽度百分比? [英] How to set width of a div in percent in JavaScript?

查看:2320
本文介绍了如何在JavaScript中设置div的宽度百分比?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用JavaScript或jQuery以百分比设置元素的高度/宽度?​​

Is it possible to set the height/width of an element in percent using JavaScript or jQuery?

推荐答案

document.getElementById('header').style.width = '50%';

如果您使用的是Firebug或Chrome / Safari开发人员工具,请在控制台中执行以上操作,你会看到Stack Overflow标题缩小了50%。

If you are using Firebug or the Chrome/Safari Developer tools, execute the above in the console, and you'll see the Stack Overflow header shrink by 50%.

这篇关于如何在JavaScript中设置div的宽度百分比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆