Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Styling the Navigation panel

From: WordPress 3: Creating and Editing Custom Themes

Video: Styling the Navigation panel

So our CSS is really coming along here. We have some good structure built and our header has taken shape. It's changed a little bit since you've last seen it and then I have this vertical bar added here which I added with a border-left on the H1 tag and this mailmark added in the upper-right by giving a background image to the page wrap, this graphic here. So now it's time to dig into the Sidebar and specifically the navigation. Now, you can see we're looking at this page on the web that our navigation is way down here.

Styling the Navigation panel

So our CSS is really coming along here. We have some good structure built and our header has taken shape. It's changed a little bit since you've last seen it and then I have this vertical bar added here which I added with a border-left on the H1 tag and this mailmark added in the upper-right by giving a background image to the page wrap, this graphic here. So now it's time to dig into the Sidebar and specifically the navigation. Now, you can see we're looking at this page on the web that our navigation is way down here.

Now, that's not where we want it of course. We want it to be up here. We want our whole Sidebar over here on the left block, and the main content here in a bigger area on the right. We can accomplish that layout pretty easily just using float left and float right on those two things. Our sidebar is called an aside. We'll make it float left and we'll give it a width of 275 pixels. Now, our main content is float right, and we'll give it a width of 500 pixels.

So if we save that and go back out to the web it's going to look broken, fair warning. Where did all the white go? Very weird. It's because our parent container collapsed upon itself. Now, when a parent contains floated items like that it doesn't know how to calculate its own height and it just basically falls into nothing. Now, there're a few different ways you can handle it. My favorite way is by using what's called the clearfix. All one word. If you want to learn more about specifically how it works, you can google it.

Pretty easy to find but I'm just going to copy and paste it into this code and we'll look at it. Now, it has a class name of group. Could be anything, could be clearfix if you want it to be. I like group just because I like that word. It kind of makes sense to me. It means it's wrapping multiple things. Now there is some backslashy stuff in here. That's just ensuring that it's going to work in all browsers. So to use the clearfix we have to apply this class of group on the element we want to clear and in our case it's the page-wrap.

So let me add a class of group to this page-wrap, and you'll see if we refresh in the browser, we're going to be all good. Now, I've got to save the CSS file for that to take effect. We're all good. No problem. So we have our sidebar in place here. I mean, it's tucked up underneath the logo, but we can fix that with just a little top padding on the aside. So we'll apply padding here. Remember it's like a clock. We'll say 70 pixels on the top, but nothing for all the rest of the values for now.

That pushes it down just wherever you want it. Now, each one of these is a link. So let's look at our Photoshop file and see what we are trying to match. We want to be able to click anywhere in this block and go to the appropriate page that this is navigation for. So let's make this whole block our anchor link, and let's take a look at the HTML that makes that area. It's this here, down here. So it's within the nav tag, within this unordered list, within these list items.

These anchor links are what we're trying to style. So in the CSS we kind of follow the trail there. nav ul li a. We'll make them display block because anchor links by their nature are in-line elements, and we'll start just describing what we're seeing here a little bit. There's some padding on each of them. Maybe 10 pixels all the way around. Except for in the left it's a little wider, so I'll say maybe 25 pixels for that value.

The color is white. The font size is a little bigger than the default. Maybe 16 pixels. Text-decoration, we're going to set to none, anchor links by default are underlined, so that's going to get rid of that underline for us. We'll just give it a background color. Maybe just some dark gray for now and we'll deal with this coloring here in a minute. You can see that they're set apart from each other a bit, maybe 5 pixels. So none on the top, none on the right, 5 pixels in the bottom, and none on the left.

That's how those shorthand properties work. I'm going to hit Save. We'll go back up to the browser to see how we're doing. So, pretty good, not bad. We do have these little bullet points that are coming from the list. We should get rid of those. Those come from the list itself. So if we say nav ul, list-style none, and reload the browser, those will go away, no problem. Looking pretty good. Let's handle the coloring and do a little thinking in Photoshop here for a minute.

So there's four navigation items right now on top of each other and they kind of follow a nice color pattern, from blue to a little bit lighter blue, to yellow, to a green to kind of a muddy yellow. I think if we were to switch some of these things around, and we've got to be smart and assume that maybe our client will someday want to switch these things around, I think the color pattern that's going on here is more important than the specific tie between what the link is and the color. So we kind of want to color in the right order no matter what.

We're going to do that in a special way by using the nth-child selector. So you notice that they're all grey now, and instead of having them be gray, we'll have the default be with that top one, is this blue. So let's grab this blue color and replace this. We're going to say the background-color is that blue, and then we'll reload the browser, and they're blue. Now, we want to target the second one, just the second one only.

I am going to sample the color there, grab that color code from the color picker, and then say nav ul li and we'll use this nth-child selector, it looks like this, and say we just want number 2. The second one. So that anchor link within that, we want to have a background color of this that we just sampled. Let's check that out in the browser. Second one got the color perfectly. That's how you can target individual elements depending on their position.

So we have two other positions to deal with. So let me copy and paste the CSS there and say three and four and then copy those color codes from Photoshop as I sample them. Copy the green. Copy the yellow color. We'll go to the web and see how we're doing. Pretty good! Pretty good, perfect! Looking very good! Now, in Photoshop, another thing, the last thing we need to deal with are these little kind of nubs that stick down, giving us that ribbon effect, that kind of 3D effect there.

We're going to need a separate HTML element to deal with this. So let's jump over to the HTML and give us that element. It could be anything. We're just going to give it a span. I am just going to chuck that right within the anchor tag on each one of our menu items. It gives us a little bit of a thing to play with there. So let's go ahead and save that, and we're going to want to target it uniquely. So let's say nav ul li a span.

We're going to position them absolutely, so we can target exactly where we want them to be and remember when we use position absolute, the parent of it needs to have position relative so we can kind of make sure that it's relative to what's going on here. Otherwise if we give it position absolute, it'll be relative to who knows what? Maybe the body or who knows. So we'll make sure that the anchor tag has position: relative. It's not going to move it.

It's just going to set the context for us and then we want to position it with a right value of 100%. So no matter what, as wide as this thing is, we're going to start counting at the way left edge here. That's what right at 100% is able to do, and the top value of maybe 5 pixels will push it down, and give a width 15 pixels, and then a height of however tall that anchor link was, 100%. So let's just give it a background color of that blue for now that we used as the default and see how we're doing in the browser.

Very good! We've got the nub sticking out here, but they're all blue. So let's deal with that coloration first. All we have to do is just copy this selector, put a comma so it's kind of a multi-selector, put a span after this, so that it will share the color properly, and we'll do that on all three of these. Save it, and reload, and now we have the color working out nicely.

It's just that the color, they just bleed into each other. We need to give it that 3D effect. That little shadow that sticks out. So let's jump into Photoshop and make that shadow just a really tiny little box. 12 pixels wide, 10 pixels tall, and I'm going to go ahead and zoom-into it so you can see real close what's going on. I'll double-click the Background layer to unlock it, select all and delete the white that's by default there, and now this has a transparent background. I'm going to grab the Gradient tool.

Make sure that I have black selected as my color, and then make sure that our gradient is on the second one in here, this foreground color to transparent, and then hold Shift, and kind of just drag a little bit of background in here and then knock down the Opacity maybe to 40% on that layer. I'm going to save this image out as a graphic called navshadow. Jump back over to our CSS. We're going to use that on the spans, so it's going to have a background image of url(../images/navshadow.png).

We're going to make sure that it's positioned on the right, starting at the top, and it's going to be able to repeat vertically. Let's hit Save and see how we're doing there. Great! Now, we have that shadow giving it that 3D effect in the navigation. So that's the CSS for our navigation. Great start as we move forward with our CSS.

Show transcript

This video is part of

Image for WordPress 3: Creating and Editing Custom Themes
WordPress 3: Creating and Editing Custom Themes

40 video lessons · 51097 viewers

Chris Coyier
Author

 
Expand all | Collapse all
  1. 6m 44s
    1. Welcome
      1m 19s
    2. Using the exercise files
      5m 25s
  2. 40m 42s
    1. Reviewing the client spec and deciding on WordPress
      6m 50s
    2. Reviewing assets and resources and creating a mood board
      8m 41s
    3. Building a home page mockup
      11m 26s
    4. Finishing the home page
      12m 27s
    5. Planning the rest of the site
      1m 18s
  3. 1h 8m
    1. Starting with a base project
      3m 6s
    2. Writing HTML code for the home page
      12m 7s
    3. Starting the CSS: Creating the header and basic style structure
      11m 28s
    4. Styling the Navigation panel
      10m 59s
    5. Styling the sidebar
      7m 55s
    6. Styling the home page, pt. 1
      8m 20s
    7. Styling the home page, pt. 2
      8m 17s
    8. Finishing the CSS
      3m 14s
    9. Moving on: One page is enough
      2m 43s
  4. 1h 56m
    1. Setting up WordPress and MAMP on a Mac
      6m 7s
    2. Setting up WordPress and WAMP on a Windows computer
      5m 38s
    3. Modifying important settings
      6m 26s
    4. Starting with a blank theme template
      4m 35s
    5. Introducing template file structure
      4m 55s
    6. Breaking up the HTML
      9m 53s
    7. Building the sidebar
      3m 54s
    8. Building the navigation
      7m 20s
    9. Showing one recent post
      4m 1s
    10. Fetching external content
      8m 23s
    11. Creating a custom home page
      3m 30s
    12. Introducing custom fields
      5m 23s
    13. Creating custom product pages
      9m 52s
    14. Creating custom category pages
      15m 39s
    15. Creating the blog home page
      5m 39s
    16. Creating a single blog entry page
      4m 15s
    17. Implementing comments
      5m 57s
    18. Finishing the home page
      4m 45s
  5. 34m 17s
    1. Will this work with WordPress?
      3m 10s
    2. Using JavaScript in themes the right way
      8m 35s
    3. Implementing something fun with JavaScript
      7m 53s
    4. Introducing plug-ins
      6m 31s
    5. Setting up security
      8m 8s
  6. 2m 7s
    1. Goodbye
      2m 7s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed WordPress 3: Creating and Editing Custom Themes.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.