HTML localStorage CSS问题?

时间:2016-01-16 22:02:21

标签: javascript jquery html css html5

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

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

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

1 个答案:

答案 0 :(得分:2)

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

您可以设置'ley' < 'lia' < 'vet'的属性来更改图片的CSS属性,例如高度(image.style)和宽度(image.style.height)。

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

image.style.width

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

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

希望这有帮助。