css - 将图像左上、居中和右下对齐

标签 css image alignment

我想将图像放在图中所示的 div 中。一个应该与左上对齐,一个与中心对齐,一个与右下对齐。宽度和间隙也需要根据窗口大小调整大小。实现这一目标的最佳方法是什么?

enter image description here

最佳答案

只需使用位置样式即可。

<style type="text/css">
  div {
    width: 100%;
    height: 200px;
    position: relative;
  }
  #img1 {
    position: absolute;
    top: 0;
    left: 0;
  }
  #img2 {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
  }
  #img3 {
    position: absolute;
    bottom: 0;
    right: 0;
  }
</style>
   
<div>
  <img id ="img1" src="http://lorempixel.com/200/100/">
  <img id ="img2" src="http://lorempixel.com/200/100/">
  <img id ="img3" src="http://lorempixel.com/200/100/">
</div>

关于css - 将图像左上、居中和右下对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41374511/

相关文章:

xaml - 使用RelativePanel 与面板中心右对齐

html - 我有一个 z-index 下拉问题

php - 使用php获取字符串中的第一张图片

c# - 将图像添加到视频末尾

html - float 功能无法正常工作,因为 div 大小不同

css - 将推特分享按钮添加到 Shiny 的 R 导航栏

javascript - 在 Meteor-Angular 应用程序中动态更改背景 CSS

javascript - 使用组件内 &lt;style&gt; 标签(未使用的 CSS 选择器)为 Svelte 组件的 {@html...} 标签设置样式

css - 元素在开发工具中消失

ios - 如何循环显示图像(来自网络)?