简体   繁体   English

如何移动此图像的位置?

[英]How do I move the position of this image?

I'm trying to move these images created with javascript.我正在尝试移动这些用 javascript 创建的图像。 I have multiple images created with javascript and when I press the button to generate them, all the pictures stack up left to right in the order they were created.我有多个用 javascript 创建的图像,当我按下按钮生成它们时,所有图片都按照创建顺序从左到右堆叠。 I want to position some of them on the website.我想在网站上定位其中一些。 Not sure how to do it.不知道该怎么做。

Here is the code for one of the images that is created with javascript, the others are the exact same, just different names:这是使用 javascript 创建的图像之一的代码,其他图像完全相同,只是名称不同:

var headPic = document.createElement("img");
  headPic.src = headList[head];
  document.body.appendChild(headPic);

You can consider using flexbox.您可以考虑使用 flexbox。

You can refer to the web page :你可以参考网页

You can also try my code.你也可以试试我的代码。

 headList=[]; headList[0]="https://image.flaticon.com/icons/svg/1373/1373204.svg"; headList[1]="https://image.flaticon.com/icons/svg/1373/1373203.svg"; headList[2]="https://image.flaticon.com/icons/svg/1373/1373208.svg"; function go() { var container=document.getElementById("container"); for (var i=0;i<headList.length;i++) { var img=document.createElement("img"); img.src=headList[i]; container.append(img); } }
 div.container { display:flex; flex-direction:row; }
 <div class="container" id="container"> </div> <button onclick="go()"> Go </button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM