HTML localStorage CSS Issues?

HTML localStorage CSS Issues?

本文关键字:Issues CSS localStorage HTML      更新时间:2023-09-26

好的,所以我在几个小时后成功地管理了使用 HTML localStorage 系统调用图像,但现在我对调用的图像有一个问题......我无法决定它的去向.....它只是位于页面底部,因为代码是纯粹的javascript.....我试过把它放在一个div中并改变它的位置,但它不会让步任何建议......下面是调用图像的代码:

    window.onload = function() {
 var picture = localStorage.getItem('img');
 var image = document.createElement('img');
 image.src = picture;
 document.body.appendChild(image);
};

如何编辑页面上的位置以及高度等......................?任何帮助表示赞赏!

您将图像附加到文档正文,因此同样,它将被添加到页面底部。

您可以设置 image.style 的属性以更改图像的 CSS 属性,例如高度 ( image.style.height ) 和宽度 ( image.style.width )。

要将其放置在页面上的其他位置,您可以更改其显示属性

image.style.position = "absolute"; //(for example)
image.style.top = "50px"; //drops the image down 50px from the top of the page

或者,您可以将其完全添加到 DOM 的不同部分:

document.getElementById('ID_OF_YOUR_DIV').appendChild(image);

希望这有帮助。