Professional Documents
Culture Documents
Step 1 Preparation
If you read the Photoshop tutorial for creating this layout you probably noticed that 960gs grid system
was used for guidelines creation. Well, in this tutorial we will also need the 960gs grid system as a CSS
framework. Using CSS frameworks makes layout and styles creation a lot easier and saves time in web
development. Now you should download the 960 Grid system source files for usage in this tutorial.
You will also need a good code editor of your choice; you can use a plain text editor such as the
Notepad. I always recommend you use a free code editor and get used to it, this helps you get things
done faster.
Now in the process of creating this tutorial you should test your layout in different browsers, you dont
want to return to the beginning because of browser compatibility issues. In this tutorial I am using some
CSS3 styles but as you might know not all browsers support CSS3 features. The results shown in this
tutorial will be from Firefox version 3.6 which supports all CSS3 styles used in this tutorial.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Portfolio Layout</title>
<link type="text/css" href="styles/reset.css" rel="stylesheet" media="all" />
<link type="text/css" href="styles/text.css" rel="stylesheet" media="all" />
<link type="text/css" href="styles/960.css" rel="stylesheet" media="all" />
<link type="text/css" href="styles/style.css" rel="stylesheet" media="all" />
</head>
<body>
<div class="header_container container_12">
Header Content Goes Here.
</div>
<div class="featured_container">
<div class="container_12">
Featured Project Goes Here.
</div>
</div>
<div class="content_container container_12">
Main Contect Goes Here.
</div>
<div class="footer_container">
Footer Content Goes Here.
</div>
</body>
</html>
As you can see in this layout we added links for the CSS files in the header, created four main <div>
sections each with a unique class name for styling later, youll notice that both header_container
and content_container class argument includes also container_12 because both need to have the
same style as container_12 implemented in the 960gs framework. Theres also a <div> section with
a class attribute container_12 inside featured_container and we separated it from the main
<div> so it can hold the overlay background. Now the repeating background image for the header and
featured section is going to be styled in the body. Now lets add the CSS as follows (all CSS should be
added in style.css file):
body {
color: #1d1d1d;
background: #fff url(../images/bg.png) repeat-x top center;
font-size: 12px;
font-family: Arial;
}
a {
color: #0cb0ca;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.header_container {
height: 100px;
overflow: hidden;
}
.featured_container {
height: 454px;
overflow: hidden;
color: #fff;
font-size: 14px;
}
.featured_container .container_12 {
background: url(../images/featured_bg.png) no-repeat top center;
height: 454px;
}
.content_container {
color: #1d1d1d;
line-height: 24px;
padding: 38px 0 60px 0;
}
.footer_container {
background: #000 url(../images/footer_bg.png) repeat-x top center;
height: 234px;
width: 100%;
display: block;
overflow: hidden;
color: #fff;
}
Lets see what we have here, we set the whole page font color to dark gray #1d1d1d and set the
background color to white #fff with a horizontally repeating image bg.png. We also set the default
font family and size then styled the links color to #0cb0ca with no text decoration and a hover state
with an underline text decoration. Next we styled the header_container with a fixed height of
100px and set overflow to hidden. Now lets look at featured_container style, a fixed height of
454px, hidden overflow, white font color and a font size of 14px. then we added the overlay
background image featured_bg.png to container_12 with no repeat and aligned to center top. We
then added the style for content_container with 24px line height (which controls the space between
lines of text), a 38px top padding and a 60px bottom padding to keep the space between featured,
footer section and content section.
Finally, we style footer_container with a horizontally repeating background image
footer_bg.png, a fixed height, a 100% width to fill the browser visible area horizontally, set display
to block, overflow to hidden and set font color to white. The result should be as the image below.
Here I used a grid_5 class to hold the logo and a grid_7 to hold the menu items. I added an <h1>
element with a link inside it that will represent the logo and a link to home page. I also added a <div>
element to hold menu items with simple links, the only thing different here is that each link has a
special class name which we will use to set the style of each item. You will also notice that the home
link has an added class active which will hold the style for the active state of the link.
Now lets add the style for the header content.
.header_container .grid_5 {
padding: 36px 0 0 0;
}
.header_container .grid_5 a {
display: block;
text-indent: -9999px;
height: 61px;
width: 280px;
background: url(../images/logo.png) no-repeat;
float: left;
}
.header_container .grid_7 a {
display: block;
text-indent: -9999px;
height: 100px;
background: url(../images/menu_items.png) no-repeat;
float: left;
margin: 0 40px 0 0;
}
To style the logo I added top padding of 36px to grid_5 style holding the heading and the link of the
logo, then I styled the link with block display, fixed height and width, a background image logo.png,
a float to the left and a value of -9999px to text indent and this value is set to make the link text
invisible when you view it in browsers and it also has SEO benefits.
Now lets style the menu items, to style the menu items I used a technique called CSS Sprites which
allows all the menu item images to be in a single image and then we choose what to show using CSS
background position properties. Now all normal state and hover state images are available in
menu_items.png, now I set the style for menu_items to float to the right so that all menu items
stay on the right side of the header and then set the a links style to display block, a fixed height, set
background image to menu_items.png, a right margin to make a space between menu items and a
-9999px text indent to hide link text. Now I add a style for each menu item class and for its hover and
active states. Finally, I set respective width and background position to show the part I want from the
Sprite image. The result should be as the image below.
Now lets see what we added, I added a <div> with a grid_12 class which will take the full width
and hold project title, description and buttons. Then added two more div elements with grid_8 and
grid_4 which holds the content for customer testimonials. Now lets add the CSS style for Featured
Project Content, heres the CSS.
.featured_container .container_12 .grid_12 .current_project {
width: 470px;
height: 300px;
overflow: hidden;
padding: 78px 0 0 0;
}
First I styled current_project with a fixed height and width, hidden overflow and a top padding of
78px to make a space between header and featured content, then I set the header 2 style with a Georgia
as font, 30px font size a normal font weight and 24px line height. Now I set the paragraph style with
line height, fixed width and a bottom margin.
Now to style both READ MORE and MY PORTFOLIO buttons I used CSS3 features which
gives you the same results you have in Photoshop without using images. There are two sections here,
one for normal button state .featured_container .container_12 .grid_12 .current_project a and the
other for hover state .featured_container .container_12 .grid_12 .current_project a:hover, for normal
state style I set text color to #1d1d1d to override the default color of links, float to left, fixed width
and height, text align to center, bold font weight and a line height similar to height for the text to center
align vertically, a 5px border with a border radius of 14px, a right margin to make a space between
both buttons, set text-shadow property which allows the text to have a shadow to 1px horizontal and
vertical length and 0px to blur radius and a white shadow color, and then set the button to have a
gradient effect for the background.
I recommend this tool CSS Gradient Generator which I use to generate gradient background effect
easily. Now for the hover effect, we will change only the gradient effect using the gradient generator.
Youll notice that I styled the paragraph element in customer testimonial section to have a smaller font
size, fixed height, zero margins, a top and left padding and a bigger line height, then I styled the span
element which contains the name to be italic and have #0cb0ca as text color. Finally I styled the
Project On Your Mind? Hire Me button the same way I did on the previous buttons with a few
values changed. Now our layout should look like this.
Notice that the header section contains an image, a normal text and a text inside a span element. You
should either export the icons from the PSD file or just use the ones included in source files. All we
have to do now is add a little CSS styles. Heres the CSS for the main content section.
.content_container {
line-height: 24px;
padding: 38px 0 60px 0;
}
.content_container .grid_4 h2 {
font-family: Georgia;
font-size: 24px;
line-height: 18px;
font-weight: normal;
}
.content_container .grid_4 p {
text-align: justify;
margin: 0 0 42px 0;
}
.content_container .grid_4 ul {
float: left;
}
.content_container .grid_4 ul li {
list-style-type: none;
margin: 0 40px 0 0;
}
First we set h2 style to have Georgia for font, fixed font size and line height with no normal weight.
Then we style the image in the header (icon) with left floating, a positive right margin and a negative
top margin to make the image align similar to the original design. Now we style the span to have a
different font family and a smaller font size. We then style the paragraph with a text align of justify and
a bottom margin. Now we style the unordered list items in the left content section, first we style ul
element to float to left and then we style li element with no list type and a right margin 40px. Now you
should notice that when we used list-style-type: none the list items has no bullets of any kind but in
the original design we have a dash character - as a bullet, because the dash isnt supported as list
item bullet character we are going to insert it before each list item text using .content_container
.grid_4 ul li:before and content: - .
Finally, we style the social icons in the right content section by styling the link normal and hover states
along with a style for the icon image. Now our layout should look like this.
Now lets style the footer content. Heres the CSS for the footer content.
.footer_container {
background: #000 url(../images/footer_bg.png) repeat-x top center;
height: 234px;
width: 100%;
display: block;
overflow: hidden;
color: #fff;
}
.footer_container .container_12 {
padding: 20px 0 0 0;
}
.footer_container .container_12.copyright {
padding: 0;
}
Notice that we set the top margin for container_12 to 20px which will make the upper space
between the footer and the main content. Then we styled header 3 with Georgia font, 18px font size,
12px line height and a normal font weight. We styled list elements with no list type (no bullet), a
similar line height and list height to center text vertically, a bottom border of 1px, a left margin and a
right padding. Then we style the paragraphs, links and contact details icons. Finally, we set copyright
section with no padding and align grid_12 text to center with small font size and equal line height
and height values.
Now if you followed this tutorial correctly then you should have a full working HTML/CSS layout
from a PSD one that looks exactly like this.
Conclusion
In this tutorial you learned how to convert a layout from PSD to HTML/CSS using CSS sprites and
CSS3 techniques. Dont forget to validate and check browser compatibility, of course all CSS3 styles
wont validate so make sure to remove all CSS3 styles before validating. Now if you think that
anything is not clear to you or you have a better technique to create something, please be kind and say
something in the comments.