HTML localStorage CSS问题? [英] HTML localStorage CSS Issues?

查看:176
本文介绍了HTML localStorage CSS问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我已经成功地管理了几个小时后使用HTML localStorage系统调用一个图像,但我现在有一个问题,调用over image ....我不能指定它去哪里... ..它只是坐在页面的底部,因为代码是纯粹的javascript .....我试图把它放在一个div,并改变它的位置,但它不会预料任何建议.... heres代码

Okay so I've successfully managed after a couple of hours to call over an image using HTML localStorage system but I now have one problem with the called over image.... I can't dictate where it goes..... It just sits at the bottom of the page as the code is purely javascript..... I've tried putting it in a div and changing its position but it won't budge any suggestions.... heres the code thats calling the image across:

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

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

How can I edit the position on the page as well as the hight etc......................? Any help appreciated!

推荐答案

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

You're appending the image to the document body, so likewise, it's going to be added to the bottom of the page.

您可以设置 image.style 的属性来更改图像的CSS属性,例如height $ c> image.style.height )和width( image.style.width )。

You can set the properties of image.style to change the image's CSS properties such as height (image.style.height) and width (image.style.width).

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

To position it elsewhere on the page, you can change it's display properties

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

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

Or, you can add it to a different part of the DOM altogether:

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

希望这有帮助。

这篇关于HTML localStorage CSS问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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