CSS:如何直接对齐图像而不切入底部?
我在尝试正确对齐布局时遇到了困难。在这里,我有一个博客文章模板,我想使文本围绕正确对齐的图像正确对齐。
这是我的代码进行的方式(此示例我删除了很多代码,我将用于简洁):
html(此代码使用一些bootstrap类)
<div>
<img src="ubuntu.png" style="float: right;">
<p>Image caption</p>
</div>
<p>Some lovely blog post text.</p>
<hr/>
,但是如果&lt的行数量; p&gt;
文本不会使整体文本高于嵌入式图像,图像将通过与水平线“冲突”来打破布局(没有正常的携带,例如float:右
零件被删除)。
因此看起来像下面的图像。在那里,图像切入了博客的底部。但是,如果float
属性被删除,则不会切入其中,但不会正确对齐。
我不是CSS Pro。在这种情况下,如何对齐是什么正确的方法?
I'm having difficulty while trying to align my layout properly. Here I have a blog post template, and I want to make the text flow around an image aligned to the right properly.
Here's how my code goes (I've cut a lot of code unnecessary for this example and I'll use inline styles for brevity):
HTML (this code uses some Bootstrap classes)
<div>
<img src="ubuntu.png" style="float: right;">
<p>Image caption</p>
</div>
<p>Some lovely blog post text.</p>
<hr/>
But if the number of lines of the <p>
text doesn't make the overall text higher than the embedded image, the image will break the layout by "conflicting" with the horizontal line (no normal carrying over happens, like when the float: right
part is removed).
So it looks like the image below. There, the image cuts into the bottom part of the blog. But if the float
attribute is removed, it doesn't cut into it, but doesn't get aligned right.
I'm not a CSS pro. What is a proper way to do the alignment in this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要清除浮子。
将该类添加到
&lt; img&gt;
示例的contrate div中:
You need to clear the float.
add that class to a containing div for the
<img>
Example: