Viewers: in countries Watching now:
Now that the comments structure and markup matches what we need, and our Gravatar are the correct size. It's time to start applying styles to make our comments match her design. Here it's important to remember what I said earlier on in the course, that when you design something in Photoshop try to just design the overall look and then you can make changes to it later. because here you'll see that the design I have for my comments will not match the final result of the actual live comments exactly. That's because as I was setting it up in the browser and designing in the browser, I decided to change some aspects.
But the overall look is going to be the same. We start out with a nice and bold title, telling us how many comments are available. Then we have for each comment, the comment meta section which has the Gravatar on the left and then the commenter name in bold at the top and then the commenter meta which has the date and time below. Then we have the full comment itself and then we have a reply button. And then we end each comment with a line so that it's separated from the next and when we have threaded comments so responses to previous comments, those threaded comments are shifted into the right by exactly 50 pixels, which is the same width as the Gravatar.
Before we start applying styles, we need to understand the formatting of the comments themselves. And if we go and use the code inspector here and look at one of our comments, you'll see that the markup that WordPress generates for the comments is extremely well structured and very easy to work with. The entire list of comments is contained within an ordered list with a class comments list. And each of the top level comments and each of all the comments is either a top level list item or an ordered list underneath a top level list item.
Inside each list item you'll find an article that has the class common body and this is each of the comments themself. Within the comment body, you find a footer, and within the footer, you have the comment author V-Card, which contains the gravitar, the name, and the word it says, and then you have the comment meta, which has the date, and publishing time. Below the footer you have a div with a class comment content which contains the comment content. And then, finally, we have a div with a class reply which contains the reply button.
So now we can apply styles to these specific classes to target each individual element and make them all match our overall design. And like before, when I style content, I always start at the top and work my way down. The comments are design elements, so therefore we're going to place all of the styles within styles.css. And here, if you look at our table of contents, you'll see the common section is 10.3. So I'll search for 10.3. And here you see underscores, out of the box, only has two rules.
So we're going to add a bunch of new rules here. And I'm going to start with the title. So I go to my code snippets and find the first rule, which is just a comments title and paste it in. It says the font weight and the font size. I'll reload my page and I see the comments title looks great. And now I'll get to work on the comments themself. The first thing I need to deal with is the numbering because right now we're outputting an ordered list and ordered list by default display the order number. Here you see on, one, one because these are all nested.
So I need to get rid of this numbering. And for that I have these two rules. The first one, targets only the first level of the ordered list, that's why you have this arrow and it sets the padding to zero, margin to two Ms and also sets the list type to none. The second one, targets only the children of ordered lists and sets the list style type to none. Save that. And reloaded in the browser and you'll see now my comments list shift to the left and we got rid of the numbers. Now I'm going to shift each of the responses 50 pixels to the right.
So I'll use this style here comment list OL which targets just the ordered list within the comment list and shift it 50 pixels to the right. So, now you see each of the comments will match up with the width of the Gravatar. And now, I'll start working on the comment meta. So, the first thing I'm going to do is add a margin below the common meta, so we separate the meta from the comment content. So, I'll grab that rule, which just targets comment meta and sets a margin on the bottom. Then, I'll float the avatar to the left and give 20 pixels of margin to the right so that we separate the gravatar from the name and the meadow.
So I'll target the avatar class for that. Now that the avatar floats on the left I can restyle my meta here. So here I have two rules. One for the comment author, which is bold and has a lato font face and then one for the meta data which sets the font size. And now it's time to work on the actual comment content itself. And here I'm going to navigate down and get to the older comments because I want to see the comment that has all the HTML markup. Now when you look at this, you'll see this looks kind of weird because the text has shifted all the way to the right.
So I want to shift the text in so that it lines up nicely with my comment meta. And I also want to make sure that the text within my comment is slightly smaller than the text on the actual post. So I'll grab these two rules here and paste them in and you see the first rule, comment content sets the font size for everything to 90% so that the font is slightly smaller. The next rule targets comment content and also the reply class and shifts at 70 pixels to the right. And the reason my shift is 70 pixels is I have a gravatar of 50 pixels and I gave the gravatar a margin right of 20, so that becomes 70.
And now you'll see the comment content will shift in exactly 70 pixels and line up with a meta data. Next, I'll go back to my previous page and reload it and here, I'm going to apply some styles to separate each comment from each other and add a line between each comment. So I'll grab this class, common body, which as you can see contains padding on the bottom, margin on the bottom, and also a border and this will create nice separation between each of the comments. Then I'll apply some general styling just to the comments content and here I'll replace the existing style.
And finally I'll style the reply button. So now my comments actually look exactly as I want them. So the only thing is to make them responsive and when I make them responsive, all I want to do is make sure that on smaller screens we don't have this indentation. Because that will create for a very awkward experience when you have a lot of indentations. So I'm going to go to my code snippets and grab the media query here at the bottom. And paste it in below the bipols author class which is currently empty and all this media query does is it targets screens smaller than 600 pixels wide and it just sets the margins so that we don't have such aggressive indentation.
And when I reload my comments the final time I can now resize my window. And you see when I get down to a small enough size, all the indentation just disappears. But now, we have fully response of comments, the design matches the overall idea of our original design and they look great on both, big screens and small screens.
There are currently no FAQs about WordPress: Building Themes from Scratch Using Underscores.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.