All posts tagged HTML

From Photoshop to WordPress – Part II – Coding

Here is Part II of our “From Photoshop to WordPress” series. In Part I – Design, we looked at how to make a nice grungy-looking blog design in Photoshop. Today, we’ll be looking at slicing that design and coding it in HTML.

The great thing about Photoshop (and most high-end graphics programs) are the layers. Putting elements on different layers will help you tremendously when comes the time to slice that design up for the web. And so here we go. Let’s get this thing rolling.

Laying down the mark-up

So, let’s start off with some default code for a basic 2 column layout with header and footer. Our layout will be a fixed layout, meaning that it will not stretch depending on the visitors’ browsers’ resolution.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-CA" xml:lang="EN-CA">

<head>
	<title>Some title</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>

<div id="header">
        <div id="navigation"></div>
        <div id="branding"></div>
        <div id="categories"></div>
</div>

<div id="content"></div>

<div id="sidebar"></div>

<div id="site-info"></div>

</body>
</html>

It can’t get more simple than that. It’s pretty bare-bone and that’s how we start the mark-up, just like we did in the tutorial A websites’ structure from A to Z, then we will go and put all our content in and then we will deal with styling it and adding backgrounds, colors and fonts.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-CA" xml:lang="EN-CA">

<head>
	<title>Some title</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<!-- header -->
<div id="header">

<!-- navigation -->
<div id="navigation">
	<ul class="left">
		<li><a href="">Home</a></li>
		<li><a href="">About</a></li>
		<li><a href="">Archives</a></li>
		<li><a href="">Contact</a></li>
	</ul>
	<ul class="right">
		<li><a href="" class="rss-link">RSS</a></li>
	</ul>
</div>
<!-- END OF navigation -->

<!-- branding -->
<div id="branding"><h1>Eroded by Time</h1></div>

<!-- categories nav -->
<div id="categories">
	<ul>
		<li><a href="">CatOne</a></li>
		<li><a href="">CatTwo</a></li>
		<li><a href="">CatThree</a></li>
		<li><a href="">CatFour</a></li>
		<li><a href="">CatFive</a></li>
	</ul>
</div>
<!-- END OF catories nav -->

</div>
<!-- END OF header -->

<!-- content -->
<div id="content">

	<!-- post featured -->
	<div class="post featured">
		<h2>Lorem ipsum dolor sit amet</h2>
		<p class="post-date">Posted August 17th, 2008</p>
		<div class="post-content">
			<p><img src="" class="post-thumb" alt="Lorem ipsum dolor sit amet" /> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce
imperdiet. Sed ullamcorper varius nibh. Vestibulum augue. Aenean id justo. Nullam sit amet lectus. In odio. Vestibulum ante
ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In hac habitasse platea dictumst. Nam feugiat.
Quisque nibh nibh, scelerisque ac, ultrices ut, iaculis at, ligula. Duis tempor odio in ipsum.</p>
			<p>Donec condimentum eros a tellus. Phasellus mauris. Aenean magna. Pellentesque enim ante, hendrerit
sed, luctus ut, tempor in, lacus. Aliquam erat volutpat. Nam semper enim et enim. Sed sagittis nisi a urna. Proin mattis
neque. Vivamus faucibus ipsum eu augue. Proin diam dui, posuere eu, posuere eu, elementum vel, diam.</p>
			<p class="post-continue"><a href="">Continue reading ...</a></p>
		</div>
	</div>
	<!-- END OF post featured -->

	<!-- post -->
	<div class="post">
		<h2>Lorem ipsum dolor sit amet</h2>
		<p class="post-date">Posted August 17th, 2008</p>
		<div class="post-content">
			<p><img src="" class="post-thumb" alt="Lorem ipsum dolor sit amet" /> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce
imperdiet. Sed ullamcorper varius nibh. Vestibulum augue. Aenean id justo. Nullam sit amet lectus. In odio. Vestibulum ante
ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In hac habitasse platea dictumst. Nam feugiat.
Quisque nibh nibh, scelerisque ac, ultrices ut, iaculis at, ligula. Duis tempor odio in ipsum.</p>
			<p class="post-continue"><a href="">Continue reading ...</a></p>
		</div>
	</div>
	<!-- END OF post -->

	<!-- post -->
	<div class="post">
		<h2>Lorem ipsum dolor sit amet</h2>
		<p class="post-date">Posted August 17th, 2008</p>
		<div class="post-content">
			<p><img src="" class="post-thumb" alt="Lorem ipsum dolor sit amet" /> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce
imperdiet. Sed ullamcorper varius nibh. Vestibulum augue. Aenean id justo. Nullam sit amet lectus. In odio. Vestibulum ante
ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In hac habitasse platea dictumst. Nam feugiat.
Quisque nibh nibh, scelerisque ac, ultrices ut, iaculis at, ligula. Duis tempor odio in ipsum.</p>
			<p class="post-continue"><a href="">Continue reading ...</a></p>
		</div>
	</div>
	<!-- END OF post -->

	<!-- page-navigation -->
	<div class="page-navigation">
		<div class="left"><a href="">Older Posts</a></div>
		<div class="right"><a href="">Newer Posts</a></div>
	</div>
	<!-- END OF page-navigation -->
</div>
<!-- END OF content -->

<!-- sidebar -->
<div id="sidebar">

	<!-- sidebar-ads -->
	<div class="sidebar-ads">
		<a href=""><img src="" /></a>
		<a href=""><img src="" /></a>
		<a href=""><img src="" /></a>
		<a href=""><img src="" /></a>
	</div>
	<!-- END OF sidebar-ads -->

	<!-- sidebar-search -->
	<div class="sidebar-search">
		<form action="">
			<p><input type="text" name="search" /> <input type="submit" value="Search"/></p>
		</form>
	</div>
	<!-- END OF sidebar-search -->

	<!-- sidebar-tags -->
        <h4>Tags</h4>
	<div class="sidebar-tags">
		<ul>
			<li><a href="">Bloggers</a></li>
			<li><a href="">CSS</a></li>
			<li><a href="">Miscelaneous</a></li>
			<li><a href="">Standards</a></li>
			<li><a href="">Web Design</a></li>
		</ul>
	</div>
	<!-- END OF sidebar-tags -->

	<!-- sidebar-pop-posts -->
        <h4>Popular Posts</h4>
	<div class="sidebar-pop-posts">
		<ul>
			<li><a href="">Lorem ipsum dolor sit amet</a></li>
			<li><a href="">Lorem ipsum dolor sit amet</a></li>
			<li><a href="">Lorem ipsum dolor sit amet</a></li>
			<li><a href="">Lorem ipsum dolor sit amet</a></li>
		</ul>
	</div>
	<!-- END OF sidebar-pop-posts -->

	<!-- sidebar-comments -->
        <h4>Recent Comments</h4>
	<div class="sidebar-recent-com">
		<ul>
			<li><a href="">Someone</a> on <a href="">Lorem ipsum dolor sit amet</a></li>
			<li><a href="">Someone</a> on <a href="">Lorem ipsum dolor sit amet</a></li>
			<li><a href="">Someone</a> on <a href="">Lorem ipsum dolor sit amet</a></li>
			<li><a href="">Someone</a> on <a href="">Lorem ipsum dolor sit amet</a></li>
		</ul>
	</div>
	<!-- END OF sidebar-comments -->

</div>
<!-- END OF sidebar -->

<!-- site-info -->
<div id="site-info">

	<div class="left">
		<p>Copyright 2008 - Karinne Legault</p>
		<p>Hosted by <a href="">Hosting Company</a> / Powered by <a href="http://www.wordpress.org">Wordpress</a></p>
	</div>
	<div class="right">
		<ul>
			<li><a href="">Home</a></li>
			<li><a href="">About</a></li>
			<li><a href="">Archives</a></li>
			<li><a href="">Contact</a></li>
			<li><a href="">RSS</a></li>
		</ul>
	</div>
</div>
<!-- END OF site-info -->
</body>
</html>

There! Mark-up is pretty much done. We will probably come back to it to either adjust/change the names of some of our classes or ID’s, or even add some but for now, this has pretty much all the important components.

Slicing it up

Back in the days when tables for layout were everybody’s business, we could go in Photoshop and use the Generate HTML with the slicing tool. But then that generates an insane amount of images and deprecated code so we will be staying well clear of that and instead, we’ll do it by hand.

I can hear the exasperated sigh’s from here. The way I look at it, we only need to slice/copy/cut 6 images. Yep… not 50, like the generator would normally give you, but 6, six, seis. One for the main grungy background (1), one for the top navigation (2), one for the header (3), one for the logo (4), one for the category menu (5) and one for the footer (6). That’s it. The rest are icons that we have already downloaded from pinvoke so we don’t need to touch those.

Ready? Let’s get started!

Our main background

As I previously stated, the great things about Photoshop (and most advanced graphics programs) is the layers and the ability to hide/show them at will. So in order to get out background, we’ll hide pretty much everything in our document.

Now it’s just a matter of flattening the layers and saving it to main-bg.jpg

Header

Now we need to get that checkered background. And we want it as a transparent file so the grunge from our main background image will show through. So, like we did with the main background, we’ll hide all the layers except those making the grungy checkered image.

So you’ll end up with something like this

To get our image, we’ll change the Canvas Size to 1000px x 235px

And save that image as a Transparent PNG named header-bg.png

Top navigation

Since our top navigation has a slight gradient effect, we need a background image for that as well. We don’t need a big image for this. Only 5px x 55px will suffice.

So you would end up with this and save it as top-nav-bg.jpg

Branding

Here want simply the title to show up against a transparent background. So what we will do is open up a new document of 350px x 60px

and put our title in there using the same font (Times New Yorker – 48px) and save that as branding.png

Category menu

Pretty simple now that we’ve done a few already. Here we’ll hide everything except our image that makes up that grungy background.

Now, by hitting Command+Mouse click (ctrl+right mouse-click in Windows) on that Layer 7 copy, it automagically hightlights everything I need.

Then I copy, create new file, paste and voilà, my category background. I just need to set the Opacity to 65% and I’m off to the races. Let’s save that one as cat-nav-bg.png

Footer

For our footer, we’ll be using the same technique we used for our category navigation background. So ctrl+right-click on the footer layer, and paste in a new file, change the opacity to 15% and we’re done. We’ll save this last one as footer-bg.png.

And now we’ve got all our images so we’re ready to go ahead and put it all together.

Creating the stylesheet and putting it all together

First thing we need to take into consideration is that our original canvas was 1000 pixels in width so we will want to contain certain parts of our content in a 960 pixels space. We will make adjustments to our mark-up as we go along and add wrapper div’s.

First things first, let’s add a link to our stylesheet in the our mark-up:

<head>
	<title>Some title</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

	<link rel="stylesheet" media="screen" href="css/styles.css" />

</head>

Now let’s remove the default borders around the page. We’ll also go ahead and add our main background to the body element as well as font sizes and family, and text colors.

html, body {
	margin: 0;
	padding: 0;
}

body {
       font: 12px/16px Verdana, Geneva, sans-serif;
       color: #000;
       background: url(../i/main-bg.jpg) repeat 0 0;
}

Header

For our header, all we need to set here is the grungy checkered background and we’ll center it to stay in our 960px width with the rest of the content.

/*** header
****************************************/
#header {
	background: url(../i/header-bg.png) no-repeat top center;
	height: 235px;
	overflow: hidden;
}

Notice that we’ve set a height (235px) as well as the overflow: hidden property to clear the floats from our navigation.

Navigation

Our top navigation has a slight gradient which we have sliced up from our Photoshop file and we have one part of our navigation on the left and one to the right. Not sure if you’ve notice in the mark-up but those 2 classes that I have used in there (.left and .right), I also use them in a few more spots so we’ll set up a “Common class and ID” section in our CSS where we will put those 2 classes as well as styles for links, etc….

/*** common styles
****************************************/
.left {
	float: left;
}

.right {
	float: right;
}

Since we will want to contain our navigation in a 960px space, we will add a wrapper div to our navigation.

<!-- navigation -->
<div id="navigation">
<div id="navigation-wrapper">
	<ul class="left">
		<li><a href="">Home</a></li>
		<li><a href="">About</a></li>
		<li><a href="">Archives</a></li>
		<li><a href="">Contact</a></li>
	</ul>
	<ul class="right">
		<li><a href="" class="rss-link">RSS</a></li>
	</ul>
</div>
</div>
<!-- END OF navigation -->

Our black bar with the gradient we want to have it stretch the width of the browsers’ viewport so it’s only the links that we want to contain.

/*** navigation
****************************************/
#navigation {
	background: #2c2c2c url(../i/top-nav-bg.jpg) repeat-x 0 0;
	height: 55px;
}

#navigation-wrapper {
	width: 960px;
	margin: 0 auto;
	padding: 15px 0 0 0;
}

#navigation-wrapper .left {
	width: 400px;
}

#navigation-wrapper .right {
	width: 80px;
	text-align: right;
}

#navigation-wrapper ul {
	margin: 0;
	padding: 0;
	list-style: none;
}

#navigation-wrapper ul li {
	float: left;
	display: inline;
	margin: 0 20px 0 0;
	padding: 0;
}

#navigation-wrapper ul li a {
	color: #fff;
	font: 14px Georgia, serif;
	text-decoration: none;
	text-transform: uppercase;
}

#navigation-wrapper ul li a:hover {
	text-decoration: underline;
}

#navigation-wrapper ul li a.rss-link {
	background: url(../i/icons/feed.png) no-repeat 0 0;
	padding: 0 25px;
}

Branding

Our heading has that square tiled background as well as the custom font so we’ll be using an image for this. We’ll set our image in an &ht;h1<>/h1< for SEO purposes and for the visually impaired, the text we will put in the >img alt="text" /< will be read.

So let’s go ahead and change this line here:

<!-- branding -->
<div id="branding"><h1>Eroded by Time</h1></div>

…to incorporate our logo and a link back to the home page as well.

<!-- branding -->
<div id="branding"><h1><a href=""><img src="i/branding.png" width="350" height="60" alt="Eroded by Time" />&amp;l;/a></a></h1></div>

Category menu

This is where our categories for our blog posts will be showing up on our pages. In our “Slicing up” section, we created a jagged background that we’ll be repeating horizontally. Like our navigation at the top, we will want to contain this in a 960px zone and for this we’ll need to add a wrapper div to do this.

<!-- categories nav -->
<div id="categories">
<div id="categories-wrapper">
	<ul>
		<li><a href="">CatOne</a></li>
		<li><a href="">CatTwo</a></li>
		<li><a href="">CatThree</a></li>
		<li><a href="">CatFour</a></li>
		<li><a href="">CatFive</a></li>
	</ul>
</div>
</div>
<!-- END OF categories nav -->

We’ll use much of the same code as with our nav.

/*** cateogies
*******************************/
#categories {
	background: url(../i/cat-nav-bg.png) repeat-x 0 0;
	height: 80px;
}

#categories-wrapper {
	width: 960px;
	margin: 0 auto;
	padding: 30px 0 0 0;
}

#categories-wrapper ul {
	margin: 0;
	padding: 0;
	list-style: none;
}

#categories-wrapper ul li {
	float: left;
	display: inline;
	margin: 0 20px 0 0;
	padding: 0;
}

#categories-wrapper ul li a {
	color: #363636;
	font: bold 18px Verdana, Geneva, sans-serif;
	text-decoration: none;
	text-transform: uppercase;
}

#categories-wrapper ul li a:hover {
	text-decoration: underline;
}

And that concludes our header section! Hooray!

On to the next section: content

Content

Before we start diving into our content, we’ll need to add another wrapper div around the content and sidebar to contain both those elements in a 960px area.

<!-- END OF header -->

<!-- content-wrapper -->
<div id="content-wrapper">

<!-- content -->
<div id="content">

	<!-- post featured -->
	<div class="post featured">
		<h2>Lorem ipsum dolor sit amet</h2>
		<p class="post-date">Posted August 17th, 2008</p>
		<div class="post-content">
			<p><img src="" class="post-thumb" alt="Lorem ipsum dolor sit amet" /> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce
imperdiet. Sed ullamcorper varius nibh. Vestibulum augue. Aenean id justo. Nullam sit amet lectus. In odio. Vestibulum ante
ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In hac habitasse platea dictumst. Nam feugiat.
Quisque nibh nibh, scelerisque ac, ultrices ut, iaculis at, ligula. Duis tempor odio in ipsum.</p>
			<p>Donec condimentum eros a tellus. Phasellus mauris. Aenean magna. Pellentesque enim ante, hendrerit
sed, luctus ut, tempor in, lacus. Aliquam erat volutpat. Nam semper enim et enim. Sed sagittis nisi a urna. Proin mattis
neque. Vivamus faucibus ipsum eu augue. Proin diam dui, posuere eu, posuere eu, elementum vel, diam.</p>
			<p class="post-continue"><a href="">Continue reading ...</a></p>
		</div>
	</div>
	<!-- END OF post featured -->

	<!-- post -->
	<div class="post">
		<h2>Lorem ipsum dolor sit amet</h2>
		<p class="post-date">Posted August 17th, 2008</p>
		<div class="post-content">
			<p><img src="" class="post-thumb" alt="Lorem ipsum dolor sit amet" /> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce
imperdiet. Sed ullamcorper varius nibh. Vestibulum augue. Aenean id justo. Nullam sit amet lectus. In odio. Vestibulum ante
ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In hac habitasse platea dictumst. Nam feugiat.
Quisque nibh nibh, scelerisque ac, ultrices ut, iaculis at, ligula. Duis tempor odio in ipsum.</p>
			<p class="post-continue"><a href="">Continue reading ...</a></p>
		</div>
	</div>
	<!-- END OF post -->

	<!-- post -->
	<div class="post">
		<h2>Lorem ipsum dolor sit amet</h2>
		<p class="post-date">Posted August 17th, 2008</p>
		<div class="post-content">
			<p><img src="" class="post-thumb" alt="Lorem ipsum dolor sit amet" /> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce
imperdiet. Sed ullamcorper varius nibh. Vestibulum augue. Aenean id justo. Nullam sit amet lectus. In odio. Vestibulum ante
ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In hac habitasse platea dictumst. Nam feugiat.
Quisque nibh nibh, scelerisque ac, ultrices ut, iaculis at, ligula. Duis tempor odio in ipsum.</p>
			<p class="post-continue"><a href="">Continue reading ...</a></p>
		</div>
	</div>
	<!-- END OF post -->

	<!-- page-navigation -->
	<div class="page-navigation">
		<div class="left"><a href="">Older Posts</a></div>
		<div class="right"><a href="">Newer Posts</a></div>
	</div>
	<!-- END OF page-navigation -->

</div>
<!-- END OF content -->

<!-- sidebar -->
<div id="sidebar">

	<!-- sidebar-ads -->
	<div class="sidebar-ads">
		<a href=""><img src="" /></a>
		<a href=""><img src="" /></a>
		<a href=""><img src="" /></a>
		<a href=""><img src="" /></a>
	</div>
	<!-- END OF sidebar-ads -->

	<!-- sidebar-search -->
	<div class="sidebar-search">
		<form action="">
			<p><input type="text" name="search" /> <input type="submit" value="Search"/></p>
		</form>
	</div>
	<!-- END OF sidebar-search -->

	<!-- sidebar-tags -->
	<div class="sidebar-tags">
		<ul>
			<li><a href="">Bloggers</a></li>
			<li><a href="">CSS</a></li>
			<li><a href="">Miscelaneous</a></li>
			<li><a href="">Standards</a></li>
			<li><a href="">Web Design</a></li>
		</ul>
	</div>
	<!-- END OF sidebar-tags -->

	<!-- sidebar-pop-posts -->
	<div class="sidebar-pop-posts">
		<ul>
			<li><a href="">Lorem ipsum dolor sit amet</a></li>
			<li><a href="">Lorem ipsum dolor sit amet</a></li>
			<li><a href="">Lorem ipsum dolor sit amet</a></li>
			<li><a href="">Lorem ipsum dolor sit amet</a></li>
		</ul>
	</div>
	<!-- END OF sidebar-pop-posts -->

	<!-- sidebar-comments -->
	<div class="sidebar-pop-posts">
		<ul>
			<li><a href="">Someone</a> on <a href="">Lorem ipsum dolor sit amet</a></li>
			<li><a href="">Someone</a> on <a href="">Lorem ipsum dolor sit amet</a></li>
			<li><a href="">Someone</a> on <a href="">Lorem ipsum dolor sit amet</a></li>
			<li><a href="">Someone</a> on <a href="">Lorem ipsum dolor sit amet</a></li>
		</ul>
	</div>
	<!-- END OF sidebar-comments -->

</div>
<!-- END OF sidebar -->

</div>
<!-- END OF content-wrapper -->

<!-- site-info -->
<div id="site-info"></div>

And our CSS for our content-wrapper is basically like our navigation and categories menus.

#content-wrapper {
	margin: 20px auto 20px;
	width: 960px;
}

Notice the margin: 20px auto 20px;? I’m applying a 20px margin to the top and bottom but the left and right have auto so it will center.

Now we are ready to style the content area. Nothing very complicating is happening to this apart from floating the whole thing to the left. If you’ve never use the float property in CSS, no better time like the present to dive right in.

The total width of our content box is 655 but since we are adding a 1px border all around and 15px of padding, we’ll need to adjust the width.

/*** content
*******************************/
#content {
	background: #f4f1e2;
	border: 1px solid #b4b2aa;
	float: left;
	padding: 15px;
	width: 623px; /*655px - 1px - 1px - 15px - 15px = 623px */
}

Styling the posts

When creating our markup, we went ahead and assigned a class called post to each post sections. The first one (or latest entry) will be slightly different so we’ve added a second class (yes, you can do that) called featured.

Let’s start with the general posts then we’ll add the styles for the featured post.

/*** content - post
*******************************/
.post {
	border-bottom: 1px solid #ada997;
	padding: 20px 0;
}

.post h2 {
	font-size: 24px;
}

.post-date {
	background: url(../i/icons/calendar.png) no-repeat 0 0;
	color: #777777;
	font-size: 10px;
	padding: 0 0 0 25px;
}

img.post-thumb {
	border: 10px solid #fff;
	float: right;
	margin: 0 0 10px 10px;
}

.post-continue a {
	color: #b54646;
	font-size: 14px;
	font-weight: bold;
	text-decoration: none;
}</pre>
Now let's add our styles for the featured post
1.featured {
	background: #fefdf6;
	padding: 5px 15px;
}

.featured img.post-thumb {
	border-color: #000;
}

.featured .post-content {
	font-size: 14px;
}

Page navigation links

The page navigation links that the bottom of the page will enable the user to navigation through the archives.

/*** content - page navigation
*******************************/
.page-navigation {
	margin-top: 25px;
}

.page-navigation .left {
	background: url(../i/icons/arrow-180-medium.png) no-repeat 0 0;
	padding: 0 0 0 25px;
}

.page-navigation .right {
	background: url(../i/icons/arrow-000-medium.png) no-repeat right 0;
	padding: 0 25px 0 0;
}

.page-navigation a {
	color: #89835a;
	text-decoration: none;
}

Sidebar

The sidebar is very easy to do now that the content’s done. A few blocks here and there without too much styling.

/*** sidebar
*******************************/
#sidebar {
	float: right;
	margin-left: 10px;
	width: 295px;
}

Ads
For the ads, I usually have a stack of “dummy images” with different sizes already created. So for this I’ll just change the colors of one I already have on my computer to match the scheme of this site. I suggest you do the same. They are so easy to make: create a new 125×125 image, fill it up with color, add a nice 1px stroke (on the inside) and put the side of the ad. These are very helpful to simply just drop on your mock-ups for client work.

The ads as you can see are 2 x 2 and that will arrange itself in the browser due to the width we have given to our #sidebar so there really isn’t any need to add CSS to this.

<!-- sidebar-ads -->
<div class="sidebar-ads">
	<a href=""><img src="i/ads-blank.png" alt="Ad image" /></a>
	<a href=""><img src="i/ads-blank.png" alt="Ad image" /></a>
	<a href=""><img src="i/ads-blank.png" alt="Ad image" /></a>
	<a href=""><img src="i/ads-blank.png" alt="Ad image" /></a>
</div>
<!-- END OF sidebar-ads -->

If you are running this along with me and you check out the page right now, you’ll notice some big ugly borders around our ads. Eewwww! To fix this, we’ll set our images and linked images to have a border of 0.

/*** common styles
****************************************/
.left {
	float: left;
}

.right {
	float: right;
}

img, a img {
	border: 0;
}

Ahhh… That’s better!

Search

The only we will do here is add a little padding to this section so that it’s not stuck up to the ads.

/*** sidebar - search
*******************************/
.sidebar-search {
	margin: 20px 0 0;
}

Tags
Like the other 3 sections that will follow, we have to style the heading and the box.

#sidebar h4 {
	color: #776a23;
	font-size: 18px;
	font-weight: normal;
}

.sidebar-tags, .sidebar-pop-posts, .sidebar-recent-com {
	background: #f4f1e2;
	border: 1px solid #b4b2aa;
	padding: 8px;
}

The only thing (apart from the icons) that’s different with the tags is that the list is inline with no style.

/*** sidebar - tags
*******************************/
.sidebar-tags ul {
	list-style: none;
	margin: 0;
	padding: 0;
}

.sidebar-tags ul li {
	display: inline;
	margin: 0;
	padding: 0 3px;
}

Popular Posts and Recent Comments

As we said above these three blocks are all very similar. So we’ll combine the last 2 together and reuse code to shorten our CSS.

/*** sidebar - popular posts / recent comments
*******************************/
.sidebar-pop-posts ul, .sidebar-recent-com ul {
	list-style: none;
	margin: 0;
	padding: 0;
}

.sidebar-pop-posts ul li, .sidebar-recent-com ul li {
	background: url(../i/icons/bookmark-document.png) no-repeat 0 0;
	margin: 8px 0 10px;
	padding: 0 0 0 25px;
}

.sidebar-recent-com ul li {
	background: url(../i/icons/balloon.png) no-repeat 0 0;
}

Oh and let’s not forget changing the color of those links too

"]
/*** common styles
****************************************/
.left {
	float: left;
}

.right {
	float: right;
}

img, a img {
	border: 0;
}

a:link, a:visited, a:active {
	color: #b54646;
	text-decoration: none;
}

a:hover {
	text-decoration: underline;
}

And the sidebar is done.

Site info (or footer)

Now if you look at the site in a browser, you’ll notice the footer stuff is tucked in the sidebar. Not good. So we’ll add a clearing div to clear the floats (see Extending the background around two floating div’s) and have the footer site nicely under all the content.

/*** common styles
****************************************/
.left {
	float: left;
}

.right {
	float: right;
}

img, a img {
	border: 0;
}

a:link, a:visited, a:active {
	color: #b54646;
	text-decoration: none;
}

a:hover {
	text-decoration: underline;
}

.clear {
	clear: both;
}

And in our HTML

<!-- END OF sidebar -->

<div class="clear"></div>

<!-- END OF content-wrapper -->

Alright, now we start styling. When we started Part II, we cut up a few background/images we would need and now it’s time to use the last one, footer-bg.png. We’ll add that to our site-info div

/*** site-info
*******************************/
#site-info {
	background: url(../i/footer-bg.png) repeat-x 0 0;
	height: 61px; /*81px*/
	padding-top: 20px;
}

Notice I’ve added a bit of padding at the top and that’s because of the rough edge. We don’t want the text to just lie up there so that’s why our height is 61 instead of 81, we need to compensate for the padding.

Now, like our content area, we want our text in the footer to stay within our 960px boundaries. So we’ll add a site-info-wrapper div to help us achieve that.

<!-- site-info -->
<div id="site-info">
<div id="site-info-wrapper">

	<div class="left">
		<p>Copyright 2008 - Karinne Legault</p>
		<p>Hosted by <a href="">Hosting Company</a> / Powered by <a href="http://www.wordpress.org">Wordpress</a></p>
	</div>
	<div class="right">
		<ul>
			<li><a href="">Home</a></li>
			<li><a href="">About</a></li>
			<li><a href="">Archives</a></li>
			<li><a href="">Contact</a></li>
			<li><a href="">RSS</a></li>
		</ul>
	</div>

</div>
</div>
<!-- END OF site-info -->

Bottom navigation

Let’s tackle the bottom navigation first. We’ll re-use much of the code we wrote for the tags box, except we’ll add border to the right of the menu item.

/*** site-info - navigation
*******************************/
#site-info .right ul {
	list-style: none;
	margin: 0;
	padding: 0;
}

#site-info .right ul li {
	border-right: 1px solid #000;
	display: inline;
	margin: 0;
	padding: 0 10px 0 5px;
}

If you look at this in your browser, you’ll notice the last menu item (RSS) has a border on the right which sort of look funny since there’s nothing after it. So let’s go ahead and add a class to that last item and remove the border.

<div class="right">
	<ul>
		<li><a href="">Home</a></li>
		<li><a href="">About</a></li>
		<li><a href="">Archives</a></li>
		<li><a href="">Contact</a></li>
		<li class="last"><a href="">RSS</a></li>
	</ul>
</div>

and the code to remove the border

"]
/*** site-info - navigation
*******************************/
#site-info .right ul {
	list-style: none;
	margin: 0;
	padding: 0;
}

#site-info .right ul li {
	border-right: 1px solid #000;
	display: inline;
	margin: 0;
	padding: 0 10px 0 5px;
}

#site-info .right ul li.last {
	border-right: none;
}
[/html]

<strong>Copyright and other info</strong>

Let's make the copyright and other info fit nice and snug together. In order to do this, we'll simply remove all margins and padding to the <code>&gt;p&lt;&gt;/p&lt;</code> tags

1"]
/*** site-info
*******************************/
#site-info {
	background: url(../i/footer-bg.png) repeat-x 0 0;
	height: 81px;
	padding-top: 20px;
}

#site-info-wrapper {
	margin: 20px auto 0;
	width: 960px;
}

#site-info p {
	margin: 0;
	padding: 0;
}

We’re done!

That’s it! We are done!

I hope this helps some of you in understanding how to slice a mock-up in Photoshop. Like anything else in Web Design, understand that this is merely one way of doing it. It’s how I’ve done it for the past 10 years and it’s worked great for me.

Download and Demo



YUI CSS Framework Tutorial

What is YUI?

The Yahoo User Interface library is comprised mostly of Javascript utilities and controls to help front-end developers create a rich user interface. It also comes with a great CSS framework to make developing websites a lot faster. This CSS framework is what we’ll be focusing on today. It’s lightweight (less than 6KB when minified), easy to use, and most importantly, it works with all major A-grade browsers.

Why use it?

Any good UX designer will tell you that one of the keys to making your website easy to use is consistency. Your goal should be to not make users use more than the necessary brain power it takes to understand the point you’re trying to get across. People are used to seeing sites designed in certain ways and the YUI CSS Framework covers these basic design patterns without having to make you think too hard as well. Everybody wins.

This doesn’t mean that Yahoo is trying to make everyone design the way they say, however. They leave plenty of room for customization for the “wild at heart” amongst us that want to dish out the newest interesting custom design pattern. More on this in a bit.

Getting Started.

The first step is to get the YUI CSS Framework. I gave you the direct link for it here, but I would also recommend taking a look at the YUI Developer Site. If you head to that page, on the left menu there’s a navigation header labeled “YUI Components”. Most of those are the YUI JS utilities but if you scroll down, you’ll see that the last four sub links are for CSS. There’s a lot of great information there for you to check out including a 42 minute video that explains probably more than you’ll want to know about how the CSS Framework works (well maybe not more).

You may have noticed when you clicked the link that the name of the file is “reset-fonts-grids.css”. This is actually a combination of the three main components that make this all work all combined into one minified CSS file for your convenience. If you find yourself asking whether or not you can download them separately, the answer is yes…however they are a bit dependent upon each other, so use caution. If you’re using another reset file such as the famous Eric Meyer’s Reset CSS, you can (most likely) safely use that instead of Yahoo’s version, but why try and fix what isn’t broken? Now when it comes to the other two components, fonts and grids, grids relies on the fonts css to declare the proper width for an “em”, which grids uses for just about everything.

Reset

If you’re not already using a reset css file, I definitely recommend you seriously look into using one – even if you don’t want to use YUI. Each browser has it own set of defaults when it comes to margins, line-heights, padding, etc. that can make life tough when trying to code out your layout. What reset does is simple, yet extremely useful. It takes away all of the browser defaults and sets them to all use the same stuff. The days of using “*{margin: 0; padding: 0;}” are over. It’s time to get with the program.

Fonts

As described above, the fonts portion defines the width of the “em” for which everything is based on. It also, however, takes away all of the browser font defaults and sets every relevant html tag to use a font size of 13px, a line-height of 16px, and all but the pre and code tags to use the Arial font (pre and code use the monospace font family). What does this mean for you? It means you’re going to need to define the font sizes and/or families you’re going to want on your website yourself. Don’t look at that as a bad thing though, you’re most likely doing this already (or you should be). This, like reset, takes away the differences in the default styling of the browsers for a consistent look and feel. Yahoo provides a recommended way to define your font sizes using the percentages defined on their fonts page.

Grids

Now this is where things start to get fun. YUI makes it very easy to layout everything on your site without having to use those cumbersome tables. Let’s take a look.

Setting up the page.

YUI breaks up a page in a very familiar way to most designers. You’ve got your wrapper div, which also determines the width of your site. And within that you’ve got your header, body and footer. Pretty easy right? Here’s how it looks.

<!DOCTYPE html>
<html>
	<head>
		<title>My first YUI Layout</title>
		<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;css/reset-fonts-grids.css&quot; />
	</head>
	<body>
		<div id=&quot;doc2&quot;><!--Wrapper div -> doc, doc2, doc3, doc4, or doc-custom-->
			<!--These three are not required to use if you prefer something else, but they're pre-defined for you-->
			<div id=&quot;hd&quot;></div>
			<div id=&quot;bd&quot;></div>
			<div id=&quot;ft&quot;></div>
		</div>
	</body>
</html>

We’ll start by focusing on the wrapper div. YUI offers you four different standard widths:

doc – 750px
doc2 – 950px
doc3 – Fluid
doc4 – 974px

And for all you “rebels” out there, you can create a custom width in your own stylesheet using the doc-custom wrapper. It’s a good thing to keep these widths in mind when designing your site. It will make your life much easier. The rest of the document is pretty self-explanatory.

Templates.

Now that we’ve got the basic layout of the page, we’re going to add content using yahoo’s predefined template classes. The concept behind the templates is extremely easy. You’ve got two main blocks of content that you want to position within your body (bd). You’re going to put all of your content within one of these two blocks. You define a block simply by giving the div a class of “yui-b”. Once you’ve done that, you need to tell YUI which block is the main block for content (i.e. the wider block) by wrapping it in a div with an id of “yui-main”. The reason you need to do this is some browsers don’t support the pseudo class of “:first-child”. And by some, of course, I mean IE.

...
<div id=&quot;bd&quot;>
	<div id=&quot;yui-main&quot;>
		<div class=&quot;yui-b&quot;>
			...some content here...
		</div>
	</div>
	<div class=&quot;yui-b&quot;>
		...some content here...
	</div>
</div>
...

This tells YUI which block of content is the main focus of the site. Regardless of whether the main content block is to the left or to the right of the sidebar, you can always put it above the less important code (the sidebar). This way you can keep your best content at the top of the source (helps with SEO).

Now that we have defined the blocks of content, we need to tell YUI where to display it. That’s as simple as adding a template class to the wrapper div (the doc). Yahoo has provided six different pre-defined layouts for use:

.yui-t1 – Two columns, narrow on left, 160px
.yui-t2 – Two columns, narrow on left, 180px
.yui-t3 – Two columns, narrow on left, 300px
.yui-t4 – Two columns, narrow on right, 180px
.yui-t5 – Two columns, narrow on right, 240px
.yui-t6 – Two columns, narrow on right, 300px

Yahoo has chosen these layouts as one of the most common things found in sidebars are ads and most ad networks have a consistent set of sizes for the ads they serve. Wouldn’t you know it? Most of the them match up to the template sizes YUI provides.

Let’s continue by adding the template class of “yui-t6″ to our document wrapper as it’s a fairly common layout.

<div id=&quot;doc2&quot; class=&quot;yui-t6&quot;>

Now add some dummy text in there and look for yourself. Voila! You have a layout.

Special Grids.

Now what if you don’t want to use any of the pre-made templates? Say your design calls for 3 columns instead of two. Or maybe you want to add something with the template you created that needs to be broken up into sections? Not a problem. YUI has a grid layout system that pretty much covers any custom block layout you want without the need to use tables.

The Grid system works very similar to the templates shown above. You have your outer div (the grid), and your inner divs (called units) which work very much the same as blocks (remember .yui-b?). Let’s take a look at how to set one up.

<div class=&quot;yui-g&quot;>
	<div class=&quot;yui-u first&quot;>
		...some content here...
	</div>
	<div class=&quot;yui-u&quot;>
		...some content here...
	</div>
</div>

This will create a grid with two equal width blocks that will fill whatever container they are inside. The only real thing to take note of here is that whichever div you want to appear first (on the left), make sure to give that div a class of “first” along with the unit class.

Similar to templates, there are six different types of grids you can use:

.yui-g – Standard grid, 1/2 – 1/2
.yui-gb – Special grid, 1/3 – 1/3 – 1/3
.yui-gc – Special grid, 2/3 – 1/3
.yui-gd – Special grid, 1/3 – 2/3
.yui-ge – Special grid, 3/4 – 1/4
.yui-gf – Special grid, 1/4 – 3/4

Now the thing that makes this great is that you can also nest grids as much as you’d like. Want a grid that displays in quarters as opposed to halfs? Let’s check out how to do that.

<div class=&quot;yui-g&quot;>
	<div class=&quot;yui-g first&quot;>
		<div class=&quot;yui-u first&quot;>
			...some content here...
		</div>
		<div class=&quot;yui-u&quot;>
			...some content here...
		</div>
	</div>
	<div class=&quot;yui-g&quot;>
		<div class=&quot;yui-u first&quot;>
			...some content here...
		</div>
		<div class=&quot;yui-u&quot;>
			...some content here...
		</div>
	</div>
</div>

The thing to keep in mind here is that when you nest a grid within another grid, that grid also acts as a unit for it’s parent grid. There’s no need to nest it within a div with a unit class attached to it.

Conclusion

This framework really helps with cutting down on development time and making sure that the more important content is displayed before the rest within the source (great for SEO). If you keep this in mind the next time you design a website, you’ll notice a huge gain on time and quite possibly a relief of the stress of making your website look the way you want without hacking away at it.

Once again I’d like to stress taking a look at Yahoo’s site for YUI CSS, as it’s got great references on how to use this including videos, examples and a nice little cheat sheet so you don’t have to remember everything off the top of your head.

Download and Demo

CSS Table Tutorial

Here’s the css and html for this tutorial!

< !DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;>
<html>

<head>
<title> CSS Tables >> A Screencast by Jack Franklin</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; />
</head>

<body>

<table border=&quot;0&quot;>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Shoe Size</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bob</td>
<td>15</td>
<td>11</td>
</tr>
<tr>
<td>Jack</td>
<td>10</td>
<td>9</td>
</tr>
<tr>
<td>Bobette</td>
<td>17</td>
<td>3</td>
</tr>
<tr>
<td>Jim</td>
<td>12</td>
<td>6</td>
</tr>
<tr>
<td>Jacob</td>
<td>97</td>
<td>4</td>
</tr>
<tr>
<td>Karinne</td>
<td>12</td>
<td>5</td>
</tr>
<tr>
<td>Linda</td>
<td>20</td>
<td>8</td>
</tr>
<tr>
<td>Simon</td>
<td>11</td>
<td>12</td>
</tr>
</tbody></table>
</body>
</html>
table {
    border-collapse: collapse;
    width: 500px;
    font-family: 'Trebuchet MS';
}

tbody tr:nth-child(odd) {
    background-color: grey;
}

tbody tr:hover {
    background-color: #E3E3E3;
}

tr {
    height: 50px;
}

td, th {
    text-align: center;
    border: 3px solid #ccc;
}

thead tr {
    background-color: #111;
    color: white;
}