views:

234

answers:

3

Hi, The following is my first cut at coding-up a reddit-like comment in html+css. I have a few questions about css and the general structure:

  1. How do I get the comment body ("The King took off his hat...") to align with the comment head ("Nathan, posted...") and the comment tail ("reply permalink ...")? I tried making the margin-bottom for .comment-left a little longer but that didn't fix the issue.
  2. I know I've been a little trigger-happy with the tags. Which ones are redundant?
  3. Is there a better/tighter way to get the same structure?

Thanks all, Nathan

ps I used the handy information here for stacking my voting arrows on top of each other.


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"&gt;&lt;/a&gt;
          <a href="#"><img alt="v" title="vote down" src="http://www.reddit.com/static/adowngray.gif"&gt;&lt;/a&gt;
        </span>
        <span class="userpic">
          <a href="#">
          <img src="http://www.gravatar.com/avatar/550deada0ac679dfc3c9103b674760af?s=128&amp;d=identicon&amp;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>
A: 

How about setting the p margin-left to be set at 30px?

netrox
I like this because it seems simplest. I added "p {margin-left: 35px;}" to the stylesheet and it seemed to work nicely. However, is this (adding pixel padding) a robust thing to do in general?Here's what it looked like after I made the change:http://i50.tinypic.com/v2wmc6.png
nafe
Yes. I'd say it's the simplest way with your written HTML.
netrox
+1  A: 

Update your css with a left padding on ".comment-contents li" and a remove the margin on ".head"

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

.head {
margin-left:0px;
}

While you are at it, just use padding instead of margin for ".comment-contents li":

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

I recommend not using padding and margin on a class unless absolutly necessary.

superUntitled
Almost perfect! Here's what it looked like after I made your changes: i46.tinypic.com/9786xw.png
nafe
So now the comment head and comment middle both align. The comment tail still seems to a problem because it has a tail-list (which adds more padding?). I can remove this nested list and that will get head, middle and tail aligned -- is that a good fix?
nafe
+1  A: 

Don't have time to do CSS at the moment (maybe later), but you should be able to achieve the look with this markup:

<div class="comment">
     <p class="user">
        <a href="#">
          <img src="http://www.gravatar.com/avatar/550deada0ac679dfc3c9103b674760af?s=128&amp;d=identicon&amp;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>

And the 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;
}

I haven't tested this so there may be some bugs. Let me know if youwant any of the CSS explained.

wheresrhys
Thanks for your answer. I tried it out. Here's what it looks like: http://i50.tinypic.com/2l9xsh.png
nafe
Some of the alignments are alittle off... but I think I can see how to fix it up. I'm interested in your use of "background" in the stylesheet to set the vote up/down images -- is this preferable to embedding an <img> tag in the html?
nafe
The general idea is that, when yo think about it, the vote up arrow's meaning is the words 'vote up'. Putting the text directly in the link means that this info is as clear for somebody who, for wahtever reason, can't use images
wheresrhys
And updated the CSS so it achieves the right layout
wheresrhys