简体   繁体   English

如何在 div 元素中左右移动两个图像?

[英]How do you move two images to the left and right in a div element?

I am using HTML, and I am trying to make a part of a webpage where I have a textbox in the center of the screen and five images surrounding the textbox.我正在使用 HTML,并且我正在尝试制作网页的一部分,其中屏幕中央有一个文本框,文本框周围有五个图像。

I am able to place three images above the box, but when I try to place an image to the left and to the right of the textbox, the images seem to be "stuck" in the center of the page.我可以在框上方放置三个图像,但是当我尝试将图像放置在文本框的左侧和右侧时,图像似乎“卡”在页面的中心。 All this is in a div element.所有这些都在一个 div 元素中。

Easiest way to do this is with grid system.最简单的方法是使用网格系统。 In example if you use Bootstrap grid system you can do it like this:例如,如果您使用Bootstrap 网格系统,您可以这样做:

<div class="wrapper">
<div class="row">
  <div class="col-md-4"><img src="source" alt="something" ></div>
  <div class="col-md-4">Textbox</div>
  <div class="col-md-4"><img src="source" alt="something" ></div>
</div>

You can also do it without grid system like Gerasimos answer.你也可以在没有网格系统的情况下做到这一点,比如 Gerasimos 的回答。

Try using the CSS position property if this doesn't work try entering this code in your style sheet:如果这不起作用,请尝试使用CSS position 属性尝试在样式表中输入以下代码:

#left-image { position: absolute; left: 10px}
#right-image { position: absolute; right: 10px}

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

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