[英]Setting height and width of element in rems using javascript
如何使用 javascript 以 rems 为单位设置元素的宽度/高度?
这就是我想要做的:
function generateProgressItems(count)
{
console.log("doing it...");
let container = document.getElementById("progress-container");
for(var i=0; i<count; ++i)
{
console.log("creating image");
let img = document.createElement('img');
img.src = 'lock_closed.png';
img.width = "100rem";
img.height ="100rem";
container.appendChild(img);
}
}
这似乎不起作用,宽度/高度设置为 0
这应该有效。 我添加了背景颜色,因此即使由于某种原因 PNG 未加载,您也可以看到图像的空间。
function generateProgressItems(count) {
"use strict";
let container = document.getElementById("progress-container");
for (var index=0; index < count; ++index) {
let img = document.createElement("img");
img.src = "lock_closed.png";
img.style.background = "blue";
img.style.width = "2rem"; //100rem is fine too
img.style.height ="2rem"; //but it's huge.
container.appendChild(img);
}
}
generateProgressItems(5);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.