In this web design tutorial, you’ll see a process for converting a Photoshop mockup to working HTML/CSS template. This is Part 2 of a tutorial series that will show you how to create the design, and then convert it to an HTML/CSS template.

Minimal and Modern Portfolio Layout Tutorial Series

Demo

Click on the image preview below to launch the demo of what we’ll be creating today.

Before you begin

If you haven’t already, you’re highly encouraged to do the Part 1: Design a Minimal and Modern Portfolio Layout in Photoshop of this tutorial series before you go any further. This is because the following will require the Photoshop mockup file from the first part. If you’ve done the first part, get your PSD mockup ready as we’ll be using it here.

If you want to skip the creation of the Photoshop mockup, you should go back to Part 1 and download the source files, as we’ll need it in this tutorial.

Creating the file structure and preparing the files

1 Create a new empty folder on your desktop called portfolio.

2 Inside the empty portfolio folder, create another folder called images that will contain our CSS background images and other image assets.

3 Next, create an empty CSS document called styles.css and an empty HTML file called index.html.

4 Open up your index.html file in your favorite source code editor; I’ll be using Adobe Dreamweaver in this tutorial.

5 At the top of your document inside the <head> tags, link to your style sheet (styles.css) so that it’s ready to go. You can use the code below.

Code block 1

<link href="styles.css" rel="stylesheet" type="text/css" />

Coding the layout sections

Below, you can see the basic structure of our web template. We’ll start our conversion by creating the basic sections of our minimal and modern web page template.

6 We are going to start with a main container (also commonly referred to as a wrapper), which will hold our document in place, centered on the web browser. Inside the container were going to have five div’s which will make up the sections of our website: the sections are #top, #welcome, #sidebar, #content and #footer.

Slicing the template’s body background

7 Before we start diving into coding each section, let us first add our web page’s background. Open up your PSD file in Photoshop, select the Rectangular Marquee Tool (M) and then make a small selection covering the header/navigation and a bit of the background; the selection can be as little as 1px wide (because we’ll repeat it horizontally using CSS).

8 At the bottom of the selection, take note of the hexadecimal color code by using Eye Dropper Tool (I).

9 Once you’ve made the selection, go to Edit > Copy Merged, create a new Photoshop document (Ctrl + N), and then paste the selection to a new document. Usually, Photoshop will automatically fill in the width and height dimensions with the item on your clipboard, but in case it doesn’t, make sure that the dimensions of the new Photoshop document matches that of your rectangular marquee selection.

10 Once you’ve copied the selection into the new Photoshop document, go to File Save for Web & Devices (Alt + Shift + Ctrl + S), choose PNG-8 as the file format, and then save it as background.png inside the images folder.

Coding the template’s body background

11 Now that we have our background image sliced out of the Photoshop document, we can begin to code it nto our template. Open up your CSS file (styles.css) in your source code editor, and then use the following code.

Explanation of Code block 3

First, we reset all of our elements’ margins, paddings, and borders to 0 to avoid cross-browser inconsistencies. We do this with the * selector.

Next, we style the body element; we set background.png as it’s background property and we repeat it horizontally (repeat-x). We also set our background color to a dark blue (#001b32).

Finally, we style the #container margins to auto to center the layout, and set a fixed width of 850px.

Slicing the logo/site name

12 We’ll move on to our web template’s logo/site title. Using the Rectangular Marquee Tool (M), make a selection around the website’s title and slogan (look at the following figure for guidance).

13 Just like with the background.png, copy the marquee selection into a new document, and save it for the web as a transparent PNG called title.png inside the images folder.

Coding the logo/site name

14 With our logo/site name all ready to go, switch back to your HTML document. Inside the #top div, create a new div with an ID of title.

15 Then, inside the newly created #title div, add an <h1> element with the name of your website; we’ll also create a hyperlink element (<a>) that will link back to the home page of our website. For the template, we’ve simply assigned the href property of the a element a value of #, but if you’ll use this on a live website, you can use a backslash (/) instead to link them back to your home page.

Explanation of Code block 5

Let’s look at the above code in more detail.

Firstly we need to float the #top div to the left and give it a fixed width and height. The width should be 850px, identical to the #container and the height is the same as the light gray area on the web layout mockup.

Next, we use a technique called CSS background image replacement using the text-indent method. We indent the text inside #title h1 by -9999px to the left, which essentially pushes it out of the browser view port. This is a good technique for screen reader accessibility and search engine optimization.

Coding the Navigation

17 Still inside the #top, create another div with an ID of navigation right after the #title div. Inside the #navigation div, add a simple unordered list containing your navigation links and give it a class of nav-links. Here’s the code block for the #navigation div.

Explanation of Code block 6

Giving the unordered list a class of nav-links allows us to target it with CSS and not have other unordered lists in the web page affected. Note that the last list item has a class of borderx2, which basically means "border times two"; this is because our PSD web layout mockup had separators in between each navigation link and when we add our CSS styles later on, we’ll give the last item a 1px border on the left and the right (hence border x 2).

Slicing the hover indicator

18 Before we add the CSS styles for our navigation, we must first slice our little hover triangle. Head over to your PSD file and make a selection around the triangle using the Rectangular Marquee Tool (M). Copy and paste the little triangle to a new document with a transparent background then save it as nav_hover.png in the images folder.

Styling the navigation

19 Now, it’s time to add the CSS code for the navigation of the web template. Head on over to your stylesheet and use the following CSS:

Explanation of Code block 7

First, to display the list items side by side, we float them to the left. We give them a fixed width and height so that they’re evenly spaced. Then we remove the default underline on hyperlinks by giving it a text-decoration attribute of none (browser default is underline). We give each list item a 1px gray border on its left.

We then style hover states with the :hover psuedo-selector. When hovered on, we give the list item the CSS background of nav_hover.png.

Finally, to deal with the situation that the last list item doesn’t have a 1px gray border on the right, we declare border attributes for the .borderx2 class.

Creating the Welcome Area

The welcome area will be split into two parts, the left side (#welcome-text) and the right side (#welcome-image).

20 To start, go back to your HTML document (index.html). Inside the #welcome div we created earlier, create two new divs: give the first one an ID of welcome-text and the second one an ID of welcome-image. We’ll continue to filling in these two new divs after we slice out the things we need for the welcome are.

Slicing the Welcome Images

21 Head over to the PSD file, inside the layers window hide all your layers (click on the eye icons beside each layer to turn off the visibility) apart from the dark blue background which has the radial gradient applied to it.

23 Copy and paste the dark blue background to a new document and save it as content_background.png inside the images folder. Using the same method explained above, turn the visibility of the respective layers back on and then slice the welcome image and bullet point (see the figures below for reference).

24 Inside the #welcome-text div, we add some welcome text like that shown in our Photoshop mockup. Use an <h2> element for the heading of the welcome text, and then add a simple unordered list underneath.

Explanation of Code block 10

Let’s look at the important CSS declarations in more detail. Firstly, we give the #welcome div the radial gradient as a background attribute (content_background.png). The image is added as a background that doesn’t repeat (repeat: no-repeat). We’ve then given the div a set a fixed width and height; the width should span the width of our web template (850px) and the height is as high as the welcome image (236px).

We then have our <h2> elements. We make it all caps by using the text-transform property. We wrap the second ‘yourwebsite’ text inside a span with a class of heading-color2 to give it a different color.

For our unordered list that has a class of list, we give its list items a background image property set to bullet.png and remove the default rounded bullets of list items by declaring a list-style-type property of none.

Finally, so that our #welcome-image div displays on the left of #welcome-text, we float it to the right and give it a fixed width (which is good practice when floating elements). We also give it a width and height equal to welcome_image.png that we sliced out of our PSD file.

Slicing the 3D Separator

27 For the 3D separator, I’ve decided to use an empty div element with a class of separator so that it can be used numerous times very easily. To start creating the 3D separator, head over to your PSD file and make a selection around the 3D separator using the Rectangular Marquee Tool (M); the selection should be no bigger than 850 pixels wide and no higher than the separator itself, but make sure you get it all in.

28 Copy and paste the separator to new document with a transparent background and save the file for the web as separator.png inside the images folder.

Coding the 3D Separator

29 The HTML and CSS for the separator is quite easy. In your HTML document, pleace the following code right after where the {#welcome} div ends. We use a non-breaking space (&nbsp;), to put something inside our .separator div.

Code block 12

Explanation of Code block 12

We give .separator a background-image property equal to the separator.png we obtained from the PSD mockup. We give it a fixed width of 850px, equal to the width of our layout and float it to the left. The height property is set equal to separator.png. We give it some top and bottom margin so that there’s always a 20px gutter on top and at the bottom of the elements that it separates.

Slicing the Sidebar

31 For the sidebar, all we will need is the sidebar box. The sidebar box will have fixed dimensions for this tutorial, but it can be easily expandable later on if you desire (we’ll leave that part up to you). In your PSD file chose the Rectangular Marquee Tool (M) from the Tools Panel and make a selection around the box; my selection is 259 x 259px.

32 Copy and paste the sidebar box to new Photoshop document with a transparent background and save the image for the web as contentbox.png inside the images folder.

33 Once you’ve saved your image, head back to the PSD file and make a 1px wide by 2px high rectangular marquee selection around the small separators in between each dummy list text (see the following figure).

34 As per usual, copy it into a new Photoshop document and save it for the web with the filename of divider.png inside the images folder. The selection only has to be small for the separators as it will be repeated horizontally using CSS.

Marking up the Sidebar box in HTML

35 Lets look at our HTML for our sidebar box. Head on over to your HTML document and use the following HTML markup right after the .separator div. Notice that we have a third level heading (<h3>) for the sidebar’s heading. Also note that we assign the unordered list a class of sidebar-list so that we can target it easily with CSS and give it its own styles.

Explanation of Code block 14

We give the #sidebar div a fixed width and height equal to the width and height of contentbox.png. We float it to the left so that it will display to the left of the content section (which we’ll tackle next). Also, we set the background-image property to the contentbox.png.

We transform the text of our h3 elements of our web page to all uppercase letters with the text-transform property and center it using the text-align property.

Finally, remove the default bullets from the .sidebar-list list items by setting the list-style-type property to none, as well as set their background-image to divider.png and repeat it horizontally (repeat-x). We then give them some margins and paddings to give them some space in between each other.

Coding the Content Area

37 The content area is really simple as it only contains a couple of paragraphs and headings. Inside our #content div, just add a second-level heading element (<h2>) and wrap the second part of the text with span.heading-color2 to give it a different color. To fill out the content area, just insert some paragraph elements with lorem ipsum text. The HTML looks like this.

Code block 16

Explanation of Code block 16

The #content div is floated to the right and with a fixed width so that it displays on the right of the sidebar box. We don’t give it a fixed height because we want the text inside it to control the height. We give the paragraph (<p>) elements a margin at the bottom to give them some space in between one another (since we’ve reset our margins and paddings earlier on, this needs to be done).

Slicing the Footer

39 We’re coming close to the end, so let’s keep going and finish this bad boy up! Switch to your Photoshop file and make a rectangular marquee selection with dimensions of 850px x 60px around your footer background image (see the following figure as a reference).

Coding the Footer

40 Once again, the footer is really simple to code: we just use the {#footer} div that we already created earlier on in the tutorial. Inside the #footer div, we add our copyright text embedded using a <p> element. The HTML looks like this:

Code block 18

Explanation of Code block 18

We use footer.png as the background-image property value of the #footer div; floated to the left and making sure that the CSS background image doesn’t repeat with the no-repeat property value. The #footer div has a fixed width and height equal to the dimensions of the footer background in our Photoshop file. We give it a top margin to give it a bit of space from the div’s on top of it.

Finito!

We are done! Thank you for reading this tutorial and following along, I look forward to your comments and questions! If everything went well, you should have ended up with something like this:

About the Author

83 Comments

Ben

Jesse Kaufman

Great article! I do this regularly and follow a lot of the same workflow (except that i do images in sprites as much as i can including backgrounds). Just dealt with an HTML file from another company and it was horrid … nested tables upon nested tables!!! I was able to recreate it (and match the original PSD much more closely) with half the total size (while ADDING jQuery) … and now it’s easy to read, simple to update, and validates :) … not to mention looks the same in IE6/7/8, Firefox and Safari ;)

Andy

* No media hinting on the stylesheet. I don’t want the same stylesheet for printing.

* You could combine your background rules into a single one instead of wasting time and space by typing out every individual rule separately.

* You are using an absolute unit instead of a relative one on your font-size properties, which is a very bad idea.

* There’s no point in floating #top (same goes for #welcome, .separator, #content and any I might have missed) as it’s spanning the whole width of the container. If you want to contain floats, use overflow instead.

* There’s also no point in writing out the width on #top. 100% (#top) of 850px (#container) is still 850px.

Mark R

Tweeter

Good catch. I didn’t see Richard attributed in the blog copy, and since it was written in first person, it sounded like the other guy was ripping Richard’s material off. But he mentions Six Revisions in the blog post, so I was wrong. Sorry!

Thank you very much for the great tutorial. I followed both the photoshop and html/css tutorials and got a great result.

I had a few things, that didn’t work “out of the box”, which I want to share:
- You didn’t show the creation of the divider inside the sidbar box, or I missed out on it.
- I don’t have the font Helvetica, so I used Arial.
- I had to add the following two css definitions: 1. #navigation { float: right; } to create the space in between the title and the navigation. 2. .nav-links li { float: left; } to make the right border of the last navigation element visible.

- I added some simple css comments, because in total the styles.css became quite long. I added /* TOP STYLES */ for example.

- I had some problems croping the elements off the photoshop layout. Later I switched to using the Crop Tool (C) instead of the Rectangular Marquee Tool (M), because this way I could easily adjust the size. It seemed you always already knew the size of the elements somehow. ;D

I want to close by saying, that I really enjoyed your well written tutorial and look forward browsing your other tutorials.

Sahan

Roy

Good tutorial. However I have one comment. Most tutorials I see about webdesign are based on the idea that things like menu, text ect are fixed. I work a lot with CMS software and you’ll never know what the CMS user will type and where. A link could be entered as “click here” or “click here to read more”. Most sites and templates use a technique that adds a left and right element to the a tag so that a rounded edge can be added and a fixed width background image for the a tag itself. But in a CMS you cannot use that technique.

Would be nice if a new HTML/CSS standard would allow you to add images to the left and/or right of an element instead of only 1 background image.

ivy

peacepeijal

Wilson Walker

I am severely grateful for the attempt, but I expected this to be more thorough. The author wasn’t very specific at all once it got to the coding. I guess they expected people to know what and how to do it, but then there wouldn’t a point of a tutorial. I am amateur, which probably has A LOT to with it, but I was lost. One example was creating “#top div”; it was not said where it was supposed to go and how to create it. As an avid PS user, I was hoping to get my feet wet with web design, but I think I’ll keep on my socks and shoes for now.

Scott Stoddard

Yeah…this part is missing…I was wondering what the heck I couldn’t get rid of the bullet points and the stairstepping of nav links and separators!!!! Make sure you fix this line of code! Otherwise, decent tutorial for beginners,

agon

i had same problem whith those bullet’s showing up on the #top, but when i start reading the comments, i saw a mostafa’s comment i tried it, and it works :), after that mik ans scot mention’s, thanx to richard for the good effor, and the guys who’s helped whith comments..

i finally finished this awesome tutorial (esp. for a first timer). my last question is, why would my page show up on the left side of the screen when the live demo shows up in the center? can’t figure this one out!

ratna

I am new to webdesigning.this tutorial is awesome.
But when i preview this in IE the container is nt at the centre and there are some missmatch.So i downloaded the code from here and previewed in IE ,the container was in the center but lots of missmath.Im mozilla it works fine.
Could someone suggest where i am wrong?And hw to make this a template and use?
thanx!!

This is such a fantastic tutorial. I’m a big fan of designing sites, but coding them can be a chore, so this will be a great way for me to learn to break away from old, clunky methods. Thank you very much!

Great tutorial, but man it would be nice if you could edit this to include the styling for both #navigation and .nav-links li

Yes, we can get this from the source code, but I’m sure a lot of people are going to wonder why their site still looks like poop even after following the instructions lol. I don’t know a whole lot about CSS, but I was starting to wonder if this was going to correct itself later on or what. I’m most of the way through, but I feel sorry for COMPLETE beginners…

octavianusb

Hi! i like very much your tutorial, you are very methodical and that’s good. But i would like to see something much complex(both steps, creation and conversion the PSD file). Anyway, this is a very very good tutorial. Thx a lot that you share your ideas and knowledge with us.
(Excuse my bad english :D)

Vince

Thanks for the great tutorial. I was looking for a tutorial on portfolio site design in Photoshop and this was what I needed. I didn’t need the coding part, but read through the explanations as I wrote my own code. Having went through Part I and II entirely, here are my comments/issues and suggestions which I hope will be helpful to others.

COMMENTS:

1. The Demo
The demo’s Welcome, Sidebar, and Footer slices are a different shade of blue than the background color in my Firefox browser. The slices don’t look like the same color as the PSD.

3. Float
- I don’t see why #top div, .separator and other elements would need to be floated.
- None of the floats are cleared.
- You have .nav-links li a {float: left;} but anchors are inline elements—float the li instead, which are block elements.
- You don’t need a {float:right} on the welcome image since the #welcome-text {float: left;} will push it to the right.

6. (Step 15) A forward slash (/ is not backslash) WILL NOT necessarily link back to your homepage—it depends on your site’s folder structure. “../” is to get out of a folder.

7. Placing the header repeating background-image in
I think there should be a separate div for the repeating header. If you also wanted a repeating footer you can’t use as a selector for both so it makes semantic sense to give it it’s own div.

8. In some instances such as the title and navigation, there’s only padding-top and the height is filling the remaining space. I think padding-bottom should be added to achieve vertical center alignment.

9. I liked the hover effect in the navigation bar using a background-image.

SUGGESTIONS:

10. Slicing – the Slice tool in Photoshop is a better way to go.

11. You could have used list-style-image and margin-left for the bullet.png.

12. Sidebar
- I liked the sidebar divider as a background-image positioned at the bottom of the .

- It looks different from the PSD mockup. 1 – The last doesn’t fill up the space where the triangle is. I targeted it using the sibling selector li+li+li, and changed just that last spacing. 2 – There’s no divider after the last in your PSD. In the same rule I set background-image to “none.”

13. I would’ve liked to see styling for links!

14. Lastly, it’s good to see the markup was valid.

Vince

*These are the same comments without tags because the comment form escaped the HTML characters in my previous comments*

Thanks for the great tutorial. I was looking for a tutorial on portfolio site design in Photoshop and this was what I needed. I didn’t need the coding part, but read through the explanations as I wrote my own code. Having went through Part I and II entirely, here are my comments/issues and suggestions which I hope will be helpful to others.

COMMENTS:

1. The Demo
The demo’s Welcome, Sidebar, and Footer slices are a different shade of blue than the background color in my Firefox browser. The slices don’t look like the same color as the PSD.

2. Float
- I don’t see why #top div, .separator and other elements would need to be floated.
- None of the floats are cleared.
- You have .nav-links li a {float: left;} but anchors are inline elements—float the li instead, which are block elements.
- You don’t need a {float:right} on the welcome image since the #welcome-text {float: left;} will push it to the right.

4. The link tag should really include a media attribute set to “screen”.

5. (Step 15) A forward slash (/ is not backslash) WILL NOT necessarily link back to your homepage—it depends on your site’s folder structure. “../” is to get out of a folder.

6. Placing the header repeating background-image in body
I think there should be a separate div for the repeating header. If you also wanted a repeating footer you can’t use body as a selector for both so it makes semantic sense to give it it’s own div.

7. In some instances such as the title and navigation, there’s only padding-top and the height is filling the remaining space. I think padding-bottom should be added to achieve vertical center alignment.

8. I liked the hover effect in the navigation bar using a background-image.

SUGGESTIONS:

9. Slicing – the Slice tool in Photoshop is a better way to go.

10. You could have used list-style-image and margin-left for the bullet.png.

11. Sidebar
- I liked the sidebar divider as a background-image positioned at the bottom of the li.
- It looks different from the PSD mockup. 1 – The last li doesn’t fill up the space where the triangle is. I targeted it using the sibling selector li+li+li, and changed just that last li spacing. 2 – There’s no divider after the last li in your PSD. In the same rule I set background-image to “none.”

12. I would’ve liked to see styling for links!

13. Lastly, it’s good to see the markup was valid.

Hamed

Calel

Great write up.
Can I suggest that you name your ID’s according to HTML 5 tag names. For instance id=”Sidebar” should be id=”aside”. Also [code]* { margin: 0px; padding: 0px; border: none;
}
[/code] is pretty heavy. I would suggest including Eric Meyer’s CSS Reset.

tushar pandit(Nagpur,India)

Nicole

Thanks for the tutorial. I’ve been reading books, viewing sources on various websites, and doing various tutorials to help me learn more about XHTML/CSS coding. This is the first tutorial I have seen that explains several things that I’ve had questions about. Thank you for spending the time to create it.

After looking through the comments I see that several people made comments about how your code could have been done better and some were even a bit pushy and insisting that you’ve done something terribly wrong. My questions to THEM are…

1) If you think you are an expert coder then why are you doing a beginner tutorial on coding?

2) And if you insist on telling people how wrong they are then why don’t you create a tutorial yourself explaining to all of us “beginners” how to apparently do it the “correct” way?

As a designer who sub-contracts her coding work, I felt really confident that I could code a simple website layout after I went through this tutorial. THEN I read through the comments and now I have more questions than anything.

So frustrating. However, I do really appreciate your time and effort in writing up this tutorial. You have helped me quite a bit. Thanks!