CSS 仅针对评论中的第一行

标签 css ruby-on-rails

所以我在我的应用程序中有评论,问题是一旦评论中的内容变成三行,它就会环绕在用户图片下方,而不是从其他行所在的位置开始。我对 CSS 很陌生,但似乎我应用的任何边距都只会移动第一行。

enter image description here

CSS:

#comment_border {
  border: 1px solid $grayLighter;
  border-radius: 3px;
  background-color: #d6e5f1;
  margin-left: 90px;
  padding: 2px;
}

.comment_info {
  display: block;
  margin-left: -20px;
  color: #767676;
}

#comment_content {
  /* dont know what to put here */
}

查看/评论:

<div class="row" id="comment_border">

<span class="comment_info">
  <aside class="span2">
    <%= link_to gravatar_for((comment.user), size: 35), comment.user %>
    <%= link_to comment.user.name, comment.user, id: "feedusername" %>
  </aside>
  <span id="comment_content"> <%= comment.content %> </span>
</span>

</div>

最佳答案

问题描述不完整(缺少必要的 CSS 等),但主要问题似乎是您在内联元素上设置了左边距。使用给定的标记,以下 CSS 修改以一种似乎大致是什么意思的方式呈现它:

.comment_info {
  display: block;
  margin-left: 0px;
  color: #767676;
  /* margin-left:-20px; NOT set here */
}
#comment_content {
  margin-left: 90px;
  display: block;
}
.span2 { 
  width: 80px; 
  height: 35px; 
  float: left;
  border: solid 1px red;
 }

评论内容使用div元素而不是span会更符合逻辑;这样做,您可以删除 display: block 声明。

附言你真的不应该在这里使用 aside;它不是为了这样的目的,它只是混淆了一些旧的浏览器;请改用 div

关于CSS 仅针对评论中的第一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14827800/

相关文章:

javascript - 使用jCrop时如何使头像预览图像流畅

css - 将 div float 在(绝对定位?)背景 div(或图像)上

CSS Sprite 在其下方创建不需要的重复图像

css - 多行 <Li​​stItemText>

jquery - 复选框和 Ajax

ruby-on-rails - Rails 嵌套 with_option :if used in validation

html - 我可以在不裁剪图像的情况下使用方形图像来填充 Bootstrap 背景图像 slider 吗?

ruby-on-rails - Rails 窗体 : How to add field beside checkboxes on Many-to-Many Relationship

ruby-on-rails - 使用 pgTAP 框架来测试 postgresql 函数是一种好方法吗?

ruby-on-rails - Ruby on Rails link_to 路由路径,同时保留原始查询字符串参数