css - 将文本与 float img 对齐

标签 css css-float

我想要完成的是让文本与 float img 的顶部和左侧对齐,并立即在下方无边距地换行。当我注释掉“p”中的填充时,图像没有底部边距,但我希望填充属性在我的样式表中处于事件状态。

http://codepen.io/BennyHH/pen/vGxVwz HTML

<div id="box">
  <div id="xob">
  </div>
  <p><!-- Text --></p>
</div>

CSS

#box {
 width: 300px;
 height: 300px;
 background: silver;
}

#xob {
 width: 50px;
 height: 55px;
 background: blue;
 float: left;
 margin: 15px 15px 0;
}

p {
 padding: 13px 13px 0;
}

* {
 box-sizing: border-box;
}

最佳答案

完全不清楚预期的结果是什么,但我认为您只需要图像/ float 元素的负底部边距。

What I want to accomplish is for the text to be aligned with the top and left side of the floated img and to wrap immediately underneath with no margin.

#box {
  width: 300px;
  height: 300px;
  background: silver;
}
#xob {
  width: 50px;
  height: 55px;
  background: blue;
  float: left;
  margin: 13px;
  margin-bottom: -13px;
}
p {
  padding: 13px;
}
* {
  box-sizing: border-box;
}
<div id="box">
  <div id="xob">
  </div>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>

关于css - 将文本与 float img 对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36140786/

相关文章:

javascript - 将固定宽度层内可变高度的 float 元素相互底部对齐,行之间没有边距或空格

html - 为什么清除两者都不适用于 css?

css - 没有 JavaScript 的只有 CSS 的两种状态翻转

html - 图像旁边的按钮对齐

javascript - 定期检测 HTML 元素内的特定字符串

css - 奇怪的谷歌浏览器 float 错误 - 在其他浏览器中正常

css - 左边两个 div,右边一个,HTML 没有变化,只有 CSS

javascript - <button> 在 HTML 中单击时改变颜色?

html - 使用 :after psudeo selector? 清除 float

html - float div 中的内容导致下面的 div 下降