[英]Gravatar interferes with CSS Styling
I'm following Michael Hartl's Rails Tutorial, and I've reached the point where I'm styling a user's micropost feed. 我正在关注迈克尔·哈特尔(Michael Hartl)的Rails教程,并且已经达到了设计用户的微型帖子供稿样式的地步。 The microposts render out of a partial, which Hartl's website shows should look like this but mine looks like this .
这些微型帖子来自部分内容,Hartl的网站显示这些内容应该看起来像这样,而我的看起来像这样 。 After playing around a bit, I noticed that the posts render in a column just fine until the Gravatars are loaded;
玩了一段时间之后,我注意到帖子在列中渲染得很好, 直到载入了Gravatar。 then the microposts indent improperly.
则微帖缩进不正确。
Here's my micropost partial: 这是我的微博部分内容:
<li id="micropost-<%= micropost.id %>">
<%= link_to gravatar_for(micropost.user, size: 50), micropost.user %>
<span class="user"><%= link_to micropost.user.name, micropost.user %></span>
<span class="content">
<%= micropost.content %>
</span>
<span class="timestamp">
Posted <%= time_ago_in_words(micropost.created_at) %> ago.
</span>
</li>
If I comment out the link to the Gravatar, the column of microposts renders fine. 如果我注释掉指向Gravatar的链接,则微博栏会很好。 This isn't the first time I've had trouble with Gravatar in this tutorial and I really have no idea how to implement it in a way that will allow this page to render the way I want.
这不是我在本教程中第一次遇到Gravatar的麻烦,而且我真的不知道如何以允许该页面呈现所需方式的方式实现它。 Any and all help would be appreciated!
任何和所有帮助将不胜感激!
Edit: Here's the relevant styling for microposts: 编辑:这是微博的相关样式:
.microposts {
list-style: none;
padding: 0;
li {
padding: 10px 0;
border-top: 1px solid #e8e8e8;
}
.user {
margin-top: 5em;
padding-top: 0;
}
.content {
display: block;
margin-left: 60px;
img {
display: block;
padding: 5px 0;
}
}
.timestamp {
color: $gray-light;
display: block;
margin-left: 60px;
}
.gravatar {
float: left;
margin-right: 10px;
margin-top: 5px;
}
}
aside {
textarea {
height: 100px;
margin-bottom: 5px;
}
}
span.picture {
margin-top: 10px;
input {
border: 0;
}
}
You need to add a clearfix before the closing </li>
so the floats are cleared before the next row. 您需要在结束
</li>
之前添加一个clearfix,以便在下一行之前清除浮点数。 Otherwise they will stack like in your image because every gravatar is floating left. 否则它们会像您的图像一样堆叠,因为每个图像都向左浮动。
...
<span class="timestamp">
Posted <%= time_ago_in_words(micropost.created_at) %> ago.
</span>
<span class="clearfix"></span>
...
CSS: CSS:
.clearfix {
clear: both;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.