Viewers: in countries Watching now:
With the comments themselves styled, so they appear as they do in my designs, it's time to focus on the comment form, that you find on the bottom of the comments section. When you work with a comment form, you have to consider that there's actually two comment form versions. You have the one you see right now, which is the one you see when you're logged in, so that would be for you. And your authors and possibly some of your users if you allow them to register to your site. And then you have the public forum which asks the user to input their name, their email address, and their website before they can leave a comment.
And you have to apply styles to both of these forms. So the trick here is to apply styles to the public forum because the private one, the one you see here, the logged in one will automatically inherit the same styles. To get to that public forum, I'm going to copy out the URL, right now. And then hit Ctrl+Shift+N in my Windows computer or Cmd+Shift+N and this will open an incognito window. In Chrome you see the little spy up in the corner here. And then I'll paste in my URL here.
and the reason why I do that is because now, I'm not logged in this incognito window. But I'm logged in in my previous window, so I can switch back and forth between the logged in state and not logged in state and make sure that everything looks right in both situations. Looking back at my design you see here I have some very basic design for my comment form. I have a nice large title for the comment form. Then I have each of the labels for the form items, displaying above the form items. And then I just have simple borders around each of the form fields.
And when you look at the common form out of the box from underscores, you see that we already have the borders, and we have all the elements we need. So, we just need to apply styles to change them. To here, I'm going to do exactly what I did previously. I'll target the classes for each of the elements and just work my way down, from top to bottom. So, I'll start with the title. And, if I look at the title, you'll see it has the class comment-reply-title. So here I can go to the code-snippets for this movie, and you see I start off with a class called common-reply-title.
I'll go into my style.css file and find my comments section, and here I'll scroll all the way to the bottom of the comment section below the responsive section, because the comments form appears below all the comments. And here I'll first paste in my rule for, comments-reply-title. And you can see I'm just setting the font-weight and the font-size, and setting a little but if a margin on the bottom, to separate it from the rest of the contents. I'll save that. And reload in my incognito browser. And now we have a nice big title.
The next thing I want to do is make sure all the font, within my comments form, is set to Lato, so I have Lato here, I have Lato for the labels, I have Lato inside the each of the form elements. But, I want to set the font face for the actual comment itself to PT Serif because this is going to be real content. So here I have the two rules that set that. I target all of comment-form and set the font-family to Lato. And then I target just a comment-form textarea, which is the main comment area, and then I set the font here to PT Serif.
You'll also notice I changed the font sizes, so I have very large font in both of these areas, so I'll copy out these two rules. And paste them in below the title, and reload my incognito window. And now you see we have the Lato font face, it's smaller than it was before, and inside the regular fields we have Lato font face, and inside the comment field we have PT Serif. Now I need t reconfigure the overall design because in my design I want the labels for each of the comment fields to appear above the comment field.
But right now they appear to the left. So, I'm going to set the labels within the comment section to be block elements. That way, they'll take up an entire line and bump the fields down. At the same time, I want to make this asterisk, that indicates that this field is required, red. So, if I look at the markup, here you'll see that, within the author label, I have the word name. And then, I have a span, with a class required. And, that's the span that contains the asterisk. So, if I target the class required, I can set required to red and then the asterisk will be red.
So here I have comment-form label and display it as block and then I have class required color red. Copy that out, paste it in, and reload and now my labels display above the form fields and my asterisk is red. And here you notice one of those design in the browser things. In my original design, I had my form fields span across the entire screen. But now that I look at this design with the form fields are smaller, I realize this actually works better because you're not going to have a name that's long enough to fit the entire screen here, and you're not going to have an email address or a website that fits the entire screen.
So, it's actually better to have a smaller field for these. Now my public forum is fully styled. And I should check back with my logged in form just to make sure that I'm inheriting the same styles. And here you see I am. So now I just need to check one more thing, and that is to make sure any warning that appears, when people leave a comment is actually displayed properly. Because, if I go into my settings here and go to Settings and Discussion. I can change the moderation of my comments, so that every comment must be manually approved.
That way when someone leaves a comment the comment will be held for moderation until you say it is. And when that happens they'll get a warning saying, hey, your comment is being held for moderation. So now I'm going to go back to my incognito window and put in a fake name, Fake Name at firstname.lastname@example.org, put a Website, and a Comment. Here is a comment that will be held for moderation.
And, I'll post this comment. Now the comment will be posted, but the only person who can see it is the person who left the comment, and as that poster I can see the warning which says your comment is awaiting moderation. If I inspect this element you'll see it's wrapped in a class that says comment awaiting moderation. And here you have to remember, when a comment is held for moderation there's a good chance that the person who left the comment will be annoyed. So, when you style this warning you want it to be as friendly as possible.
So what I like to do is wrap it in a green background, so that even though it's a warning, it's not red and blaring, it's green, saying hey, this is a friendly reminder that your comment is awaiting moderation. But I'll probably approve it very soon. So the final rule, I'm going to apply is this one, comment awaiting moderations, copy it out. And paste it into my style sheet. And when you look at it, you'll see here I set the font-family to Lato, because this is a message from WordPress. I set a nice large font-size. I set the font-color to white and the background to a greener color, and then I give the box some padding, and some margin, so that it is nicely separated from the rest of the content.
So, now I'll save that, go back to my incognito browser and reload the page one last time. And you'll see now the warning, your comment is awaiting moderation, is a nice friendly warning that is not going to stress the person who left the comment out, but it's still telling them that something is off. And there you have it. Now we have a fully styled comments section, both the comments themselves, and the comments form. And you know how to work with the comments section within the WordPress site, so if you want to add additional elements or you want to change something in my design, or you want to add your own flair to the styles, you can do so from your style sheet or from the comments.php template.
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.