Ready to watch this entire course?
Become a member and get unlimited access to the entire skills library of over 4,900 courses, including more Developer and personalized recommendations.Start Your Free Trial Now
- View Offline
- Building a design in Photoshop
- Converting Photoshop design to HTML and CSS
- Setting up MAMP on Mac and WAMP on Windows
- Moving HTML and CSS into a WordPress theme
- Building navigation
- Using custom fields
- Creating a commenting system
Skill Level Intermediate
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.