Professional Documents
Culture Documents
Tutorial Psdtohtmlcss25
Tutorial Psdtohtmlcss25
In this web development tutorial, you will learn how to code a web page template from a Photoshop
mock-up from a previous tutorial called "Create a Clean and Professional Web Design in Photoshop"
using HTML/CSS.
This is the second part of a two-part series that will teach you how to create the layout in Photoshop,
and then how to convert it to a standards-compliant (X)HTML web design.
Final Result
Click on the preview below to see the live demo of the web design that youll be creating in this
tutorial.
Download
You will need the Photoshop (PSD file) of Part 1 of this tutorial, download it from that tutorial.
Also you can download all files including the examples used in this tutorial from the link below if you
want to study it offline (or use it in a project).
clean-professional-website.zip (ZIP, 74.8 KB)
Introduction
In this tutorial, well create a fixed-width web layout using some basic coding techniques. We will go
through step-by-step from the top to bottom. So this means that we will start from the the header, then
content, and then the footer section. Preview the examples when they are available to make sure that
you are following along.
3 Open index.html and styles.css in your favorite text editor. Also, open the PSD file in Photoshop; its
inside the clean-professional-weblayout zip file from Part 1.
4 Our file structure is set up now and we are ready to go.
5 Open the Photoshop file. Open the Info panel from Window > Info (shortcut key: F8). The Info panel
gives useful information depending on the selected tool. Choose the Rectangular Marquee Tool (M)
and set the options as shown below. After the options are set, click on the top left of the canvas (next to
the logo) to make a selection.
6 Use Edit > Copy Merged (Ctrl + Shift + C) to copy the selected area. Create a new document and
paste (Ctrl + V) the copied selection into the new document. Save the file for the web, File > Save for
Web (Alt + Shift + Ctrl + S) as bg_body.jpg in the images folder. Use the same settings for saving all
the files so that there is no issues with how they are rendered on a web page. I used the JPEG Very
High preset but feel free to change these settings (you can probably get away with just JPEG High or
PNG-8 to keep your web page CSS backgrounds as lightweight as possible). If you change the default
settings, be sure to save it the same way every time to provide consistency in the images.
Setting up the HTML and CSS files
7 Move to index.html. The first thing we want to do is reference style.css and in the <head> of
our HTML document.
<head>
<link href="css/styles.css " rel="stylesheet" type="text/css" />
</head>
8 Open styles.css and add some basic style rules. Were going to take a shortcut here and use the
Universal Selector margin/padding CSS reset to zero out all the elements margins and paddings. This
works the majority of the time, but its better to invest some time learning about more robust CSS Reset
techniques which you can find here: Resetting Your Styles with CSS Reset.
9 Here is the style rule declaration for resetting the margins and paddings:
/* CSS Reset */
* { margin: 0; padding: 0; }
Lets preview how the background looks. In Example 1 below, you can see how background is
implemented.
Example 1: See the background in action.
12 Since our content area is 960px, well give #container a width of 960px and add a padding of
10px on the right and left. This will give us sufficient room on either side of the layout for scroll bars
so that when the user minimizes the web browser, theres still a bit of padding on the left and right and
our content is not right at the edges of the view port (making the content hard to read). Center it using
the margin attribute.
#container {
width: 960px;
margin: 0 auto;
padding: 0 10px;
}
21 We will work on the logo style first. We transform our <h1> element into a block element. Float it
to the left. We use the logo we created earlier in Step 15 as the background, and finally indent the text
to the left where it cant be seen to hide our text. This method of replacing text with a background
image is called CSS Background Image Replacement.
#header h1 {
display:block;
float:left;
width:360px;
height:115px;
background:url(../images/logo.jpg) no-repeat 0 0;
text-indent:-9999px;
}
22 To make the logo clickable, we also need the <a> element inside the <h1> element to be a block
element, and give it the same width and height as <h1>.
#header h1 a {
display: block;
height: 100%;
width: 100%;
}
#header #phone h6 {
font-size: 11px;
}
Preview your work in a web browser. Check out Example 2 below to see where we are now.
Example 2: Our header section which includes the logo and phone section is completed.
27 Save the file for the web, File > Save for Web (Alt + Shift + Ctrl + S) as hover.jpg in our images
folder.
30 We will float <ul> element to the left so that it remains with the flow our our web page.
#nav ul {
float: left;
}
31 For the list items, well make them into block elements, then float them to the left so that they
display side by side. Well also add 1px padding to list items at their right.
#nav ul li {
display: block;
float: left;
height: 35px;
list-style-type: none;
padding: 0 1px 0 0;
}
32 The image (hover.jpg) we created in a preceeding step will be used as the background for the <a>
elements with x-position:left and also for <span> element with x-position: right. Well set text-
transform to uppercase so that it is all in capital letters.
#nav ul li a {
color: #3f3f3f;
display: block;
text-decoration: none;
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
height: 100%;
line-height: 35px;
padding: 0 0 0 18px;
}
#nav li a span {
display: block
float: left;
height: 100%;
padding: 0 18px 0 0;
}
33 Finally, for the hover and active states, we adjust the background property. This will show the
"hover.jpg" when you hover on a menu item.
#nav li a:hover, #nav li.active a {
background: url(../images/hover.jpg ) no-repeat left;
color: #fff;
cursor: pointer;
text-decoration: none;
}
34 Here the <span> element shows the background image from the right side.
#nav li.active a span, #nav li a:hover span {
background: url(../images/hover.jpg) no-repeat right;
}
Preview your work in a web browser. Check out Example 3 below to see where we are. Hover over the
menu items to see how our primary navigation works.
Example 3: Our navigation section is completed.
36 Go to our Photoshop file and browse to the header layer group and then to the fp layer group. Ctrl +
Click on the vector mask thumbnail (as shown below). You will get a selection around the big image.
37 Copy Merge (Shift + Ctrl + C) and then paste the image in a new document.
38 Save the file for the web, File > Save for Web (Alt + Shift + Ctrl + S) as fp-01.jpg in images folder.
39 Next well create the Quick Quote form background. With the Rectangular Marquee Tool (M), make
a selection of 1px width and 340px height as shown below.
40 Copy Merge (Shift + Ctrl + C) and then paste the image in a new document. Save the file for the
web, File > Save for Web (Alt + Shift + Ctrl + S) as form_bg.jpg in the images folder.
41 Select the Rectangular Marquee Tool (M) again and make a selection around the submit button as
shown below.
42 Copy Merge (Shift + Ctrl + C) and then paste the image in a new document. Save the file for the
web, File > Save for Web (Alt + Shift + Ctrl + S) as submit_btn.jpg inside the images folder.
47 We will convert the list item into a block element and float it to the left as well. Then we set the
width to 630px.
#featured ul li {
float: left;
list-style-type: none;
display: block;
width: 630px;
}
48 Then, just like the logo, we will display the <a> element as a block element and use text-
indent to hide the text.
#featured ul li a {
display: block;
height: 340px;
text-indent: -9999px;
}
51 Style the <h2> element in the form. Add a bottom margin of 18px.
form#quote h2 {
font: normal 24px "Trebuchet MS", Arial, Helvetica, sans-serif;
color: #fff;
text-decoration: none;
margin-bottom: 18px;
}
52 Well make the <label> element into block elements and float them to the left. Set their width to
100%.
form#quote label {
font-weight: bold;
color: #fff;
font-size: 12px;
display: block;
float: left;
width: 100%;
}
53 Next well style our <input> and <textarea> elements. Well add height to the <textarea>
element separately so that it doesnt affect our <input> elements. We will also use some CSS3
properties here for rounded corners.
form#quote input, form#quote textarea {
background-color: #fff;
border:1px solid #ddd;
color: #666;
float: left;
font: 12px Arial, Helvetica, sans-serif;
margin: 5px 0 8px;
padding: 8px;
width: 240px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
}
form#quote textarea {
height: 45px;
}
54 Lastly for our form, we will add the following CSS attributes for the image button named .btn.
Well hide the border by giving the border property a value of none.
form#quote input.btn {
width: auto;
border: none;
padding: 0;
margin-top: 0;
}
You can find a big list of CSS Rounded Corners Tutorials here if you want to learn more about this in
detail.
CSS3 properties used here are not supported in Internet Explorer, but still, it looks decent in Internet
Explorer.
See the difference below between Firefox and Internet Explorer.
The Featured section is completed. Checkout the Example 4 below to see how it looks like in your
browser.
Example 4: Our featured section is completed.
56 Copy Merge (Shift + Ctrl + C) and then paste the image in a new document. Save the file for the
web, File > Save for Web (Alt + Shift + Ctrl + S) as col_bg.jpg in our images folder.
60 Preview your work in your web browser. It should look like Example 5.
Example 5: Content section is completed.
64 Copy Merge (Shift + Ctrl + C) and then paste the image in a new document. Save the file for the
web, File > Save for Web (Alt + Shift + Ctrl + S) as subscribe_btn.jpg in our images folder.
Coding the Footer
65 To show the footer background with 100% width, well create a div outside the #container div
and call it #footer. Inside #footer, well create another div and name it #footerContainer.
We will be using one <p> element for footer links. We can also use footer links as standard unordered
list items.
There is a newsletter section as well in the footer which well wrap with a <form> element named
#newsletter. The form will contain a label, input fields and an image button.
<div id="footer">
<div id="footerContainer">
<p>Copyright © 2010 SmashingDzine | <a href="#">Privacy Policy</a></p>
<p>
<a href="#">Home</a> /
<a href="#">About SmashingDzine</a> /
<a href="#">Our Services</a> /
<a href="#">Portfolio</a> /
<a href="#">Blog</a> /
<a href="#">Contact Us</a>
</p>
<form id="newsletter" action="#" method="post">
<label>Enter your email to subscribe for RSS Updates</label>
<input type="text" class="textBox" />
<input class="btn" type="image" src="images/subscribe_btn.jpg"/>
</form>
</div>
</div>
67 Set #footerContainer as 960px wide to align the content inside of this div with the rest of the
page. We give this div a relative position so that we can absolutely-position the newsletter form on the
right side.
#footerContainer {
margin: 0px auto 0;
width: 960px;
font-size: 12px;
color: #ddd;
padding-top: 20px;
position: relative;
}
69 Well have #newsletter absolutely positioned on the right and 20px from top. For <input>
fields, we will use the same styles we used above for the Quick Quote form input fields and set their
width to 190px.
form#newsletter {
position: absolute;
right: 0;
top: 20px;
width: 300px;
}
form#newsletter label {
font-weight: bold;
color: #fff;
}
form#newsletter input {
background-color: #fff;
border:1px solid #ddd;
color: #666;
float: left;
font: 12px Arial, Helvetica, sans-serif;
margin: 5px 0 0;
padding: 8px;
width: 190px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
}
70 And lastly, well hide the border that is around the image button by giving the border attribute a
value of none.
form#newsletter input.btn {
width: auto;
border: none;
padding: 0;
margin-left: 3px;
}
Congratulations, you have done it! Thank you for sticking through this tutorial I hope you have
enjoyed this tutorial and learned a few tips and tricks on converting a design mockup to an HTML/CSS
template.