css - 将标题与图像对齐并在图像和内容之间添加边距不起作用

标签 css

我想实现这样的布局:

enter image description here

但它不能正常工作,我得到这个:http://jsfiddle.net/9cfqjmkb/ .标题应该与图像的顶部对齐,但它不起作用。你知道为什么吗?

此外,我希望图像与带有标题和发布日期的其他 div 之间有一些边距,如上图所示,但边距不起作用。你知道为什么吗?

HTML

<div class="container">


  <div class="row">
    <div class="col-3">
      <div class="bg-custom-light2 p-0">
        <h2 class="font-weight-bold text-custom-blue-dark h5 border-color p-2">Title</h2>
        <ul class="list-group">

          <li class="list-group-item d-flex justify-content-between align-items-center">
            <div>
              <h6 class="font-weight-bold text-custom-blue-dark">Test title example for
                example test post</h6>
              <p>post date date</p>
            </div>
            <img class="ml-2" src="https://via.placeholder.com/50" alt="">
          </li>
          <li class="list-group-item d-flex justify-content-between align-items-center">
            <div>
              <h6 class="font-weight-bold text-custom-blue-dark">Test title example for
                example test post</h6>
              <p>post date date</p>
            </div>
            <img class="ml-2" src="https://via.placeholder.com/50" alt="">
          </li>
        </ul>
      </div>
    </div>
  </div>
</div>

最佳答案

?

.list-group {
  width:300px;
}

.ml-2 {
  align-self:flex-start;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">


  <div class="row">
    <div class="col-3">
      <div class="bg-custom-light2 p-0">
        <h2 class="font-weight-bold text-custom-blue-dark h5 border-color p-2">Title</h2>
        <ul class="list-group">

          <li class="list-group-item d-flex justify-content-between align-items-center">
            <div>
              <h6 class="font-weight-bold text-custom-blue-dark">Test title example for
                example test post</h6>
              <p>post date date</p>
            </div>
            <img class="ml-2" src="https://via.placeholder.com/50" alt="">
          </li>
          <li class="list-group-item d-flex justify-content-between align-items-center">
            <div>
              <h6 class="font-weight-bold text-custom-blue-dark">Test title example for
                example test post</h6>
              <p>post date date</p>
            </div>
            <img class="ml-2" src="https://via.placeholder.com/50" alt="">
          </li>
        </ul>
      </div>
    </div>
  </div>
</div>

关于css - 将标题与图像对齐并在图像和内容之间添加边距不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53488929/

相关文章:

具有固定宽度和自动调整高度的CSS图像

html - 表单输入文本区域垂直对齐不起作用

html - CSS:清除 anchor 标记的所有格式

css - 避免边框重叠 CSS

css - HTML 和 CSS 布局帮助

css - 我的一种 Web 字体无法在 Firefox 上呈现

javascript - 为什么未将此JavaScript函数添加到我的属性中?

javascript - 如何将(可编辑)表单数据传输到另一个(不可编辑)表单?

html - 如何计算移动浏览器的div的高度

javascript - 如何使用 Javascript 在同一个 div 中显示表单数据?