css - 如何对齐 div 中的文本和图像?

标签 css html alignment

基本上我有两段文字和一张图片。

<div class="container">
    <span class="title">Text</span>
    <img src="an_image.png" />
    <span class="note">Other Text</span>
</div>

我希望所有元素都位于容器 div 的底部,标题向左对齐,注释一直向右对齐。该图像将紧挨着标题并与标题文本的底部对齐。到目前为止,我使它起作用的唯一方法是使用相对/绝对位置。有没有办法用 CSS 做到这一点?

这是我要完成的工作的图片。我可以更改容器的宽度和高度,标题、图像和注释将正确对齐到底部、左侧和右侧,就像这样:

enter image description here

最佳答案

试试这个

  <style type="text/css">
    .container { vertical-align: baseline; position: relative; border: solid 1px Gray; }
    .note { position: absolute; right: 0; bottom: 0; }
  </style>

  <div class="container">
      <span class="title">Text</span>
      <img src="an_image.png" height="100" width="100" />
      <span class="note">Other Text</span>
  </div>

抱歉,已更新解决方案...这是有效的 link

关于css - 如何对齐 div 中的文本和图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5757238/

相关文章:

php - CSS - 页脚留在页面底部

java - 如何对齐 JPanel 中的 3 个 JLabel 的底部

css - Chrome 中的连字符

javascript - 依次发送多个文件给用户下载

css - Figcaption 防止图像对齐内联

javascript - window.resize() 函数并返回脚本执行的事实

CSS - 将下拉菜单左、中、右对齐

Java - 将 JTextArea 右对齐

html - 嵌套表结构不正确

html - 无法使媒体查询正常工作。