【发布时间】:2013-04-11 22:12:08
【问题描述】:
如何使用 jquery 将元素的宽度增加 10rem。问题是 Jquery 总是返回以像素为单位的宽度/高度,我们希望以其他一些单位更新高度/宽度。
示例:JS Bin
var $c = $('#container');
console.log($c.width());
var c = document.getElementById('container');
// Q1. Why is it different from above one. This is 324 while earlier it was 320. See the output.
console.log(c.clientWidth);
// Q2. How to update the code to increase the width by 10rem.
$c.css({width: $c.width() + 10}); //It adds 10 pixels here.
console.log($c.width());
我的问题是代码中的cmets。
【问题讨论】:
-
同意你的问题,但我认为
rem单位仅适用于 Fonts 根据 W3C 标准参见:w3.org/TR/css3-values -
是的,但是这些天 em/rem 单位在应用程序中被广泛使用,因为这允许页面内容根据设备大小进行调整。随着字体大小的变化,其他所有内容都会相应地变化。