CSS边距:将列表与浮动左图像对齐

时间:2009-12-20 03:47:57

标签: html css reddit

以下是我在html + css中编写类似reddit的评论的第一篇文章。我有一些关于CSS和一般结构的问题:

  1. 我如何得到评论团体(“国王脱掉他的帽子......”)与评论头(“Nathan,张贴......”)和评论尾部(“回复永久链接... “)?我试着让.comment-margin的底部更长一点,但这并没有解决问题。
  2. 我知道我对标签感到满意。哪些是多余的?
  3. 是否有更好/更严格的方法来获得相同的结构?
  4. 谢谢大家,Nathan

    ps我使用方便的信息here将我的投票箭头叠加在一起。


    alt text


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
      <head>
        <title>CSS sandbox: comments</title>
    
        <style type="text/css">
    
          .vote {
            width: 15px;        
            float: left;
            clear: left;      
          }
          .vote img {
            display: block;
            float: none;
            clear: both;
            width: 15px;
          }
          .userpic img {
            width: 60px;
          }
          .comment-contents li {
            list-style-type: none;
            margin-bottom: 10px;
          }
          .comment-left {
            float: left;
          }
          .head {
            margin-left:10px;
          }
          .tail-list li {
            display: inline;
          }
          img {
            border: 0;
          }
          a {
            text-decoration: none;
          }
        </style>
      </head>
    
      <body>
        <div class="comment">
           <span class="comment-left">
            <span class="vote">
              <a href="#"><img alt="^" title="vote up" src="http://www.reddit.com/static/aupgray.gif"></a>
              <a href="#"><img alt="v" title="vote down" src="http://www.reddit.com/static/adowngray.gif"></a>
            </span>
            <span class="userpic">
              <a href="#">
              <img src="http://www.gravatar.com/avatar/550deada0ac679dfc3c9103b674760af?s=128&d=identicon&r=PG" height="60" width="60">
              </a>
            </span>
           </span>
    
           <span class="comment-main">
            <ul class="comment-contents">
              <li class="head">
               <a href="#">Nathan</a>, posted 2 hours ago
               <a href="#" class="comment-collapse">[-]</a>
              </li>
              <li class="middle">
                <p>The king took off his hat and looked at it. Instantly an immense
                crowd gathered. The news spread like wildfire. From a dozen leading
                dailies,reporters and cameramen came rushing to the scene pellmell in
                highpowered monoplanes. Hundreds of reserves,responding without
                hesitation to a riotcall,displayed with amazing promptness quite
                unparalleled inability to control the everincreasing multitude,but
                not before any number of unavoidable accidents had informally
                occurred.</p>
    
                <p>Chapter 1 - untitled (eecummings)</p>
              </li>
              <li class="tail">
               <ul class="tail-list">
                <li><a href="#">reply</a></li>
                <li><a href="#">permalink</a></li>
                <li><a href="#">offensive?</a></li>
               </ul>
              </li>
            </ul>
          </span>
        </div>
      </body>
    </html>
    

3 个答案:

答案 0 :(得分:1)

使用“.comment-contents li”左边的填充更新你的css并删除“.head”上的边距

.comment-contents li {
list-style-type: none;
margin-bottom: 10px;
padding-left: 60px;
}

.head {
margin-left:0px;
}

当你在这里时,只需使用填充而不是“.comment-contents li”的边距:

.comment-contents li {
list-style-type: none;
padding: 0 0 10px 60px;
}

除非绝对必要,否则我建议不要在课堂上使用填充和边距。

答案 1 :(得分:1)

目前没有时间做CSS(可能更晚),但你应该能够用这个标记来实现:

<div class="comment">
     <p class="user">
        <a href="#">
          <img src="http://www.gravatar.com/avatar/550deada0ac679dfc3c9103b674760af?s=128&d=identicon&r=PG" height="60" width="60">
        </a>
        <a href="#">Nathan</a>, posted 2 hours ago
        <a href="#" class="comment-collapse">[-]</a>
     </p>
     <p>The king took off his hat and looked at it. Instantly an immense
            crowd gathered. The news spread like wildfire. From a dozen leading
            dailies,reporters and cameramen came rushing to the scene pellmell in
            highpowered monoplanes. Hundreds of reserves,responding without
            hesitation to a riotcall,displayed with amazing promptness quite
            unparalleled inability to control the everincreasing multitude,but
            not before any number of unavoidable accidents had informally
            occurred.
     </p>
     <p>Chapter 1 - untitled (eecummings)</p>
  <ul class="commentTools">
    <li class="voteUp"><a href="#">vote up</a></li>    
    <li class="voteDown"><a href="#">vote down</a></li>        
    <li><a href="#">reply</a></li>
    <li><a href="#">permalink</a></li>
    <li><a href="#">offensive?</a></li>
  </ul>
</div>

和CSS

.comment {
   position:relative;
    padding-left:75px;
}
.comment p {

}
.comment .user img {
  float:left;
  margin-left:-60px;
}
.comment .commentTools {
    padding-left:0;
}
.comment .commentTools li {
   display:inline;
}
.comment .commentTools .voteUp, .comment .commentTools .voteDown {
   position:absolute;
   display: block;
   left:0;
}
.comment .commentTools .voteUp {
    top:0;
}
.comment .commentTools .voteDown {
    top:15px;
}
.comment .commentTools .voteUp a, .comment .commentTools .voteDown  a {
  display:block;
  width: 15px;
  height: 15px;
  text-indent:-5000em;
}
.comment .commentTools .voteUp a {
    background: url(http://www.reddit.com/static/aupgray.gif) no-repeat;
}
.comment .commentTools .voteDown a {
    background: url(http://www.reddit.com/static/adowngray.gif) no-repeat;
}

我没有对此进行测试,因此可能存在一些错误。如果您想要解释任何CSS,请告诉我。

答案 2 :(得分:0)

如何将p margin-left设置为30px?