HTML/CSS : I can't add some margin's in a span next to a floated element

标签 html css css-float

我试着有一个 float 的图像和它后面的一段。但我希望段落从中间开始,所以基本上没有对齐。所以我想把 margin-top 放在我的跨度上,但没有这样做。

例如我的代码

<div class="container">
  <article>
    <section>
      <p>
        <img style="float:left;" src="https://www.w3schools.com/images/w3schools_green.jpg" />
        <span style="margin-top: 25px;">Hello World! My name is James polar Good morning</span>
      </p>
    </section>
  </article>
</div>

代码笔:http://codepen.io/pango143/pen/LWJpmL

最佳答案

您可以使用 line-height 属性修复它。

将以下CSS代码添加到span元素

line-height: 110px;

设置display: table;为父元素和display: table-cell; vertical-align: middle; 到子元素。并且仅仅因为您的图像包含阴影并且它让眼睛认为图像比实际结束时间早,您可以使用 margin-top 属性将其向下移动。

这是你的CSS:

section p {
  display: table;
}

section p span {
  display: table-cell;
  vertical-align: middle;
}

section p img {
  margin-top: 25px;
}

关于HTML/CSS : I can't add some margin's in a span next to a floated element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43042317/

相关文章:

javascript - Stringify 返回 Object 对象?

javascript - 为什么 insertAdjacentHTML 将 HTML 转换为对象

html - 如何在链接或表单中指定 DELETE 方法?

css - 父div的高度设置干扰了子div的 float

css - 带图像的 li 的奇怪 float 行为

javascript - 我如何在正确的数组中添加元素

javascript - CSS 子级宽度由光标在父级上的位置决定

css - 条件注释不加载 IE6 特定的 CSS 文件

html - Bootstrap 汉堡按钮问题

css - 如何修复这个 float ?