首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >文字在图片下面

文字在图片下面
EN

Stack Overflow用户
提问于 2015-02-12 16:23:54
回答 6查看 65关注 0票数 0

我正在创建一个评论的布局。然而,文字在图像下面,我似乎无法摆脱它。

下面是一个演示这个问题的JSFiddle

代码语言:javascript
复制
.comments {
  padding: 10px;
}
.comments .comment {
  margin-bottom: 10px;
}
.comments .comment .profile-picture {
  vertical-align: middle;
  display: inline-block;
}
.comments .comment .text-block {
  display: inline;
}
.timeago {
  color: rgba(0, 0, 0, 0.5);
}
代码语言:javascript
复制
<div class="comments">

	<div class="comment">

		<div class="profile-picture">
			<img src="http://fakeimg.pl/50x50/" />
		</div>

		<div class="text-block">
			<a href="#">
				Barack Obama
			</a>

			Change will not come if we wait for some other person or some other time. We are the ones we've been waiting for. We are the change that we seek.

			<br />

			<div class="timeago">20 hours ago</div>

		</div>

		<hr />

		<div class="clear"></div>

	</div>

	<div class="clear"></div>
</div>

我如何才能让文字不去下面的图像?

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2015-02-12 16:28:07

可以将两个div的显示更改为表单元格。

代码语言:javascript
复制
.comments .comment .profile-picture, .comments .comment .text-block{
    display:table-cell
}

jsFiddle实例

票数 2
EN

Stack Overflow用户

发布于 2015-02-12 16:27:43

您应该使用display:内联块。在此之后,您应该给文本块一个不大于100%图像宽度(加边距)的特定宽度。

代码语言:javascript
复制
.comments .comment .profile-picture {
  vertical-align: middle;
  display: inline-block;
}
.comments .comment .text-block {
  display: inline-block;
  vertical-align: middle;
   width: calc(100% - 60px);
}
票数 3
EN

Stack Overflow用户

发布于 2015-02-12 16:30:32

你可以用清空和浮动来做,我已经更新了你的小提琴

我在您的代码中添加了以下内容:

代码语言:javascript
复制
.comments .comment .profile-picture {
  clear: both;
  float: left;
  margin-right: 10px;
}
.comments .comment .text-block {
  clear: both;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28482550

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档