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

Starting the CSS: Creating the header and basic style structure

From: WordPress 3: Creating and Editing Custom Themes

Video: Starting the CSS: Creating the header and basic style structure

So with out HTML in place, we are ready to start working with CSS in styling our page. I want to make a working copy of this, put it on our desktop, and open it up in TextMate as a project. So this is our HTML, our whole project. Here I am going to open up our index.html file. Notice this line here we are linking out to a style.css file. That's here in our project. This is what we are going to be working with. Notice there are a few lines in here already, a basic reset, we're setting the font to Georgia here and then this line here is all about those new HTML5 elements, ensuring that they are display block as they should be.

Starting the CSS: Creating the header and basic style structure

So with out HTML in place, we are ready to start working with CSS in styling our page. I want to make a working copy of this, put it on our desktop, and open it up in TextMate as a project. So this is our HTML, our whole project. Here I am going to open up our index.html file. Notice this line here we are linking out to a style.css file. That's here in our project. This is what we are going to be working with. Notice there are a few lines in here already, a basic reset, we're setting the font to Georgia here and then this line here is all about those new HTML5 elements, ensuring that they are display block as they should be.

We are going to be using two other applications in this movie. One is Photoshop, we are going to have our Photoshop mockup open, as this is what we are trying to write CSS to match, this is how we want it to look, and the other is just the browser. So I'm going to have the browser open. I want to open our project here, drag the HTML file into the browser, and this is what our HTML file currently looks like and that we are going to be styling. So let's take a look at that Photoshop file.

We have this big white box that's our page wrap. That's a great place to start, so we'll start there. Remember we originally made that 800 pixels, so an ID of page-wrap. We are going to set the width to 800 pixels and we are going to centre it on our page. We want it centered in the browser window. You can't see that it is centered in the Photoshop file of course, but that's what we are intending on the web. You normally do that with CSS with margin 0 auto. This is short hand for the margin property. It means 0 margin top and bottom and automatic margin left and right, which does the centering.

But we really not have 0 margin on the top and bottom. We have about 30 pixels on the top which we can see in the ruler and may be 10 pixels after the bottom of this white rectangle and before the text. So we will put 30 pixels, 10 pixels here. That means 30 pixels on the top, automatic margin left and right does the centering, 10 pixels on the bottom, and we will make sure that the background is white. So now let's deal with outside here, this whole outside region.

Now the nicest way to handle that is to style the HTML element itself. That ensures that just everywhere, everything that you see is going to be covered in that background. We can't just set our color like gray because our background actually has that noise texture on it. So if we zoom in here, you can really see that noise. The cool thing about a noise pattern is it's very easy to repeat. I can actually just take a small section of it, I grab the Crop tool and I am going to press Return here and just have our screen really just be that tiny bit that I just cropped out. Save that for Web & Devices. We will make it a JPEG, which is going to compress it really small.

It's only 684 bytes. I am going to hit Save, and I am going to save it our project files on the Desktop here into our images folder and I am just going to call it bg. That's our background. Now I am going to jump back out of this so I don't accidentally save our Photoshop file zoomed in like that. That wouldn't be good. And come back over to our CSS file, and on the HTML element, I am going to say we want the background of it to be, well we will make it black. We won't see black because it's going to be completely covered by this image.

So it's actually in the images folder, bg.jpg, and if we don't pass it anything else here it's just going to mean please repeat these images wide and far as you can get. So you will never see any black but if this image fails to load, it would be black and there it still be some contrast and that would be good. So I am going to hit Save there and we can jump back out to the web and see if that worked for us. Now it did! Now if we make the browser window wide enough, you will see that texture back there and you can see how it just repeats pretty seamlessly. You can still see the noise but it looks pretty good there and then the white from our page wrap, so that's looking pretty good.

Structurally we have already come pretty far here, very nice. Our header though, we need to deal with that. So let's think about the header. How does it look in the HTML? It's this bit here called header. So we know it's display block, because in our HTML header has display block. So it's going to default to 100% wide. We could do something like padding: 20px on it and just kind of see with that does. It's going to push everything in this block, this kind of invisible black on the top, now it has 20 pixels of padding to it, so that's neat.

We can accomplish in our design these lines by just using borders, so we don't even have to use images for that. So we will say border-bottom is one pixel solid and then we'll just kind of pick a gray color like 666. Come back up to the web. I'm going to see what that did. It makes a perfect line there just like we want it to be. Now it's a padding of 20 pixels, maybe we should push this over to make room for the logo up here. How far should we push it? Looks like, I don't know, maybe 250 pixels.

So instead of padding 20 here we will do like padding 20px 20px 20px and then the last one is 250px. So how that works is like a clock. This is like 12 noon up and then you go clockwise on top, right, bottom, left is the last one. Hit Save there and take a look. So it's just going to push that over and make room for that logo. That's pretty cool. Now it's not the right font, is it? Of course, we got Helvetica going here and kind of a lighter gray, so that's that h1 tag. Well let's make-- target all h1s may be and say that the font there is really Helvetica, we have to declare size though may be 36 pixels of Helvetica, and we can declare fall back fonts like Arial and then just generically San-Serif. That's cool.

In our HTML you will notice Widget Corp is lowercase but here it's uppercase. So we could just do Widget Corp here, but that's not the right way to do it. If one day we decide that we don't like uppercase anymore, instead of having to change the markup, we can change the CSS. And it's generally little smarter. So we will say text-transform: uppercase and it's not pure black. This is going to default to pure black. We will make the color the same as the rule underneath it.

Check on our progress. Doing pretty good. There is a subtle little shadow here. If I zoom way in on this, we add a shadow to that. Let me sample that color from Photoshop and grab it out here. We are going to use that. I opened up the Color Picker and grab that value. We can set that shadow by using text shadow. So we will say text-shadow and how far to the right and down do we want it? Maybe 2 pixels and how much do we want it to blur? Zero pixels and then that code.

Hit Save and we'll get that subtle shadow going on there. That's looking pretty good. No this isn't the placement we want for that certainly. It more or like kind of goes over here. Let's take a look in the HTML. It's this paragraph tag within the header and it's the only paragraph tag in there. So we can target it uniquely with something like header p. Now we want to place it just where we want it, just over here. So we can do that generally when you have a like this exact place you want to put something is with position: absolute. You got to be really careful with position absolute though. What we want to do is maybe place it like 20 pixels in from the right and we will see what happens from the bottom.

From this block, notice how it's kind of measuring with my mouse from this block and to sort of limit position absolute to be within these boundaries, we will make the header position: relative. So we will say in from the right, may be 20 pixels and from the bottom we will just put like 0 from for now. You see what happened there. Now our box collapsed because it disappeared from here, but it pushed right over here.

So we'll make that bottom little taller, maybe also 20 pixels, in the right maybe 30 pixels, and that's going to work on positioning that more properly, more like how we want it. So still have to deal with that logo, now maybe we should think about that right now. Here is the logo. We can find that in our Photoshop file. One of quick way to find it is just grab this black pointer and just kind of Command+Click on it. It's going to tell you what folder it's in, and that's easier to find. And if I Option+Click on this little eyeball here on this layer, it's going to turn off everything except for it.

That can be convenient because I am trying to just get a tight crop of their logo here. I'm going to go under Image then and Trim, so it's going to trim away every transparent pixel here, so we just get a nice tight crop of this logo and then Save for Web & Devices and use PNG-24 here to make sure it's nice and alpha-transparent. I am already in the images folder. I am going to call this logo. Back out of that. Okay, so what is the logo? If we look in our HTML's div with an id of logo. We will go into our CSS here for logo, make a new selector for it, logo.

We want it to be absolutely positioned as well. Now we are going to give it a background image of that image that we just created. Now we are going to have do ../, because the CSS files are located one level deeper in our images folder. And we want to make sure that it doesn't get repeated. It's not going to matter very much because we need to know the exact width and height of it.

Let's jump back to Photoshop and we will move forward after that Trim and just check out what the size of this is exactly. 295X191, so a width of 295 pixels, a height of 191 pixels. That's cool. That should do us there. Now we set position: absolute, but we didn't tell it where we want it to be position absolute. Now the bounding box for this, it's within the header. So that should work for us okay.

Only if we take a look at the Photoshop file, it's actually has negative values. Top 0, left 0, would be this exact little point right here. It's actually you know maybe now 50 pixels left and -30 pixels tall. So let's give it negative values here. So top of maybe -25 pixels, left -50 pixels. Save and take a look at what we did there. Now we have got our logo in there, hanging off the side and to the top just kind of how we want it there.

So we have made great progress on this structure but you can tell from the Photoshop file, it's not exactly quite matching yet. There is a lot of work yet to be done.

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 · 51894 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 preferences from 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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

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.