html - 无法将图片和文字彼此对齐

标签 html css image

我一直在尝试完成一项荒谬的基本任务,但无法完成。 我不知道如何使第二张图片位于第一张图片的正下方。这令人沮丧!!

在这里摆弄:http://jsfiddle.net/dvir0776/v9v512tm/

<div class="comment"><img src="d.jpg" style="width:13%; margin-right: 12px; float:left;">
    <div style="text-align:left; font-size:8pt;">
    <h5 style="margin-bottom:0;">Chris Fanelli</h5>
    comment comment comment comment comment comment comment comment comment comment!</div>
</div>

<div class="comment"><img src="d.jpg" style="width:13%; margin-right: 12px; float:left;">
    <div style="text-align:left; font-size:8pt;">
    <h5 style="margin-bottom:0;">Chris Fanelli</h5>
    comment comment comment comment comment comment comment comment comment comment!</div>
</div>

任何修复它的调整都会很棒。

最佳答案

这些答案应该有效,但是 here是另一种选择。它使用 display: table-row;。我添加 padding-top: 10px; 只是为了美观。容器可能不是必需的。

CSS

.container {
    width: Auto;
}
.comment {
    display: table-row;
    padding-top: 10px;
}
.comment img {
    display: table-row;
    padding-top: 10px;
}

HTML

<div class="container">
    <div class="comment">
        <img src="d.jpg" style="width:13%; margin-right: 12px; float:left;">
        <div style="text-align:left; font-size:8pt;">
             <h5 style="margin-bottom:0;">Chris Fanelli</h5>
comment comment comment comment comment comment comment comment comment comment!</div>
    </div>
    <div class="comment">
        <img src="d.jpg" style="width:13%; margin-right: 12px; float:left;">
        <div style="text-align:left; font-size:8pt;">
             <h5 style="margin-bottom:0;">Chris Fanelli</h5>
comment comment comment comment comment comment comment comment comment comment!</div>
    </div>
</div>

关于html - 无法将图片和文字彼此对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25956673/

相关文章:

html - 真气缺口: How do you get rid of a gap between IMG and surrounding content

html - 使用 <picture> 元素防止在移动浏览器中加载标题背景图片

javascript - 鼠标悬停问题

html - 在非 100% 宽度的父级中显示 100% 宽度的子级

css - Bootstrap : how to move form fields to their own lines in mobile view?

swift - iOS 14 MapKit 选择注解图片bug

javascript - 如何使用 jQuery 触发表内的按钮?

php - 在 URL 中传递参数(不使用 php GET)

html - 在 :hover 上显示隐藏的 div

css - 我怎样才能摆脱绝对定位内容下方的差距?