Howdy and welcome to the 8th article I finally got my ass in gear and started to write it so here it is. Last time I went through my design process and came up with a Photoshop mockup of what the design will look like.
In this article I'm going to be coding up my design in HTML/CSS ready for integration with CakePHP. I always try to write clean and semantic code which validates so thats going be important during this article, I also try to avoid CSS hacks and seperate style sheets for the different browsers which means that testing your code at each step in a variety of browsers is a must.
And the corresponding CSS file (note that I've include some filler background colours for the different sections just so that I can see whats going on):
If you preview your code in a browser you should be looking at the below image:
At the end of the day its personal preference but I've quickly come round to the 1 line per rule and standard file structure. For starters it saves your scroll finger from wearing out and you can quickly see where your rules are.
I've changed the background colour to a blue which was taken off the footer so that if the page doesn't scroll it will appear like a large footer. Hopefully that wont be the case as the contents will contain all the DVD covers.
An the CSS for the header:
I've also added a "dvd-last" class to (obviously) the last dvd, this is so I can remove any margin and padding so that the layout is correctly aligned and finally cleared the floats so that it doesn't cause too much havoc.
The CSS for the contents section:
And the CSS for the Footer, nothing too advanced:
If these articles are helping you out why not consider donating I can always use a beer! :)
In this article I'm going to be coding up my design in HTML/CSS ready for integration with CakePHP. I always try to write clean and semantic code which validates so thats going be important during this article, I also try to avoid CSS hacks and seperate style sheets for the different browsers which means that testing your code at each step in a variety of browsers is a must.
Skeleton Structure
The first things you need to do is to create the HTML and CSS file that you will use to code up the design. From the Photoshop mockup there are 3 distinct areas, the header, the contents and the footer. Because each will require a different background colour I need 3 div wrappers that will span 100% of the screen and inside of each I will need another centered fixed width div to hold the main bits of each section.- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Testing</title>
- <link type="text/css" href="style.css" media="all" rel="stylesheet" />
- </head>
- <body>
- <div id="wrapper-header">
- <div id="header">
- </div>
- </div>
- <div id="wrapper-contents">
- <div id="contents">
- </div>
- </div>
- <div id="wrapper-footer">
- <div id="footer">
- </div>
- </div>
- </body>
- </html>
- // style.css
- * { padding:0; margin:0;}
- body { text-align:center;}
- #wrapper-header { width:100%;}
- #wrapper-contents { width:100%;}
- #wrapper-footer { width:100%;}
- #header,
- #contents,
- #footer { width:1000px; margin:0 auto; text-align:left;}
- /* header */
- #header { height: 150px; }
- /* contents */
- #contents { height:300px;}
- /* footer */
- #footer { height: 250px;}
- /* backgrounds & colour */
- body { background:#fff;}
- #wrapper-header { background:#000000;}
- #wrapper-contents { background:#333333;}
- #wrapper-footer { background:#666666;}
- #header { background:#CCCCCC;}
- #contents { background:#999999;}
- #footer { background:#333333;}
- /* typography */
- body { font-family:"Lucida Sans Unicode"; font-size:12px;}
CSS Organisation
I generally try to organise my CSS files in a way thats easy to read and most importantly easy to find what I'm looking for. I tend to write all my rules on 1 line and structure the file into different sections such as "Typography" and "Background and Colours".At the end of the day its personal preference but I've quickly come round to the 1 line per rule and standard file structure. For starters it saves your scroll finger from wearing out and you can quickly see where your rules are.
Background Images
Now that I've got the skeleton structure up and running I need to go back into Photoshop and start cutting up the design for the background images. I'm going to need 2 thin slices for the header and footer and the main wood graphic which will tile to create a seamless effect.- body { background:#206ba4;}
- #wrapper-header { background:url(img/bg_header.png) repeat-x;}
- #wrapper-contents { background:url(img/bg_content.png);}
- #wrapper-footer { background:url(img/bg_footer.png) repeat-x #206ba4;}
- #header { }
- #contents { }
- #footer { }
Header
I've been a bit sneaky in the Header and used a large background image that contains the logo etc but also included some CSS so that the search engines can pick up the text. Then I can just hide the text using CSS and the design wont suffer. I've also created some basic form code so that I can see how it will look, I may or may not use CakePHP's form helper to create this when I'm building up the layout.- <div id="header">
- <div class="logo">
- <h1>CakeCatalog</h1>
- <h2>an online application to track and catalog your collection of dvds built using cakephp</h2>
- </div>
- <div class="filters">
- <form action="" method="post">
- <fieldset>
- <div class="input">
- <select>
- <option>Format</option>
- <option>Option 1</option>
- <option>Option 2</option>
- <option>Option 3</option>
- </select>
- </div>
- <div class="input">
- <select>
- <option>Type</option>
- <option>Option 1</option>
- <option>Option 2</option>
- <option>Option 3</option>
- </select>
- </div>
- <div class="input">
- <select>
- <option>Location</option>
- <option>Option 1</option>
- <option>Option 2</option>
- <option>Option 3</option>
- </select>
- </div>
- <div class="input">
- <select>
- <option>Genre</option>
- <option>Option 1</option>
- <option>Option 2</option>
- <option>Option 3</option>
- </select>
- </div>
- <div class="clear"></div>
- <div class="input">
- <input type="text" value="enter search items" />
- </div>
- <div class="input">
- <button type="submit" name="submit">Filter</button>
- <button type="reset" name="reset">Reset</button>
- </div>
- </fieldset>
- </form>
- </div>
- </div>
- /* header */
- #header { height: 150px; }
- #header .logo h1 { text-indent:-9999px; float:left; }
- #header .logo h2 { text-indent:-9999px; float:left; }
- #header .filters { width:500px; height: 150px; float:right;}
- #header .filters fieldset { border:none; margin:40px 0 0 80px;}
- #header .filters fieldset select option { padding: 0 5px 0 0;}
- #header .filters fieldset .input { float:left; margin:0 10px 20px 0;}
Contents
The contents is coded up quite simply with a "shelf" div that will contain upto 8 "dvds" with each dvd being floated to the left. I'm gonna have to test this and code up some logic when displaying the DVDs so that only 8 will be in each shelf but I can worry about that when I'm integrating the design with CakePHP.I've also added a "dvd-last" class to (obviously) the last dvd, this is so I can remove any margin and padding so that the layout is correctly aligned and finally cleared the floats so that it doesn't cause too much havoc.
- <div id="contents">
- <div class="shelf">
- <div class="dvd"></div>
- <div class="dvd"></div>
- <div class="dvd"></div>
- <div class="dvd"></div>
- <div class="dvd"></div>
- <div class="dvd"></div>
- <div class="dvd"></div>
- <div class="dvd dvd-last"></div>
- <div class="clear"></div>
- </div>
- <div class="shelf">
- <div class="dvd"></div>
- <div class="dvd"></div>
- <div class="dvd"></div>
- <div class="dvd"></div>
- <div class="dvd"></div>
- <div class="dvd"></div>
- <div class="dvd"></div>
- <div class="dvd dvd-last"></div>
- <div class="clear"></div>
- </div>
- </div>
- /* contents */
- #contents { padding: 0 0 20px 0;}
- .shelf { padding:20px 28px; margin:0 auto;}
- .dvd { width:100px; height:150px; float:left; margin:0 20px 0 0;}
- .dvd-last { margin:0;}
- .clear { clear:both;}
- /* backgrounds & colour */
- .shelf { background:url(img/shelf_bottom.png) bottom no-repeat;}
- .dvd { background:#333;}
Footer
For the Footer I've created 4 boxes that will each include a heading and an ordered list, each box has been given a fixed width and has been floated left. I've also given each div an extra class incase I need to specifically target a list in my CSS. Multiple classes is a technique I discovered quite late on and it can be very beneficial.- <div id="footer">
- <div class="box top-rated">
- <h2>Top Rated</h2>
- <ol>
- <li><a href="">Desperado</a></li>
- <li><a href="">From Dusk Till Dawn</a></li>
- <li><a href="">Kill Bill Vol.1</a></li>
- <li><a href="">Pulp Fiction</a></li>
- <li><a href="">Reservior Dogs</a></li>
- </ol>
- </div>
- <div class="box recently-added">
- <h2>Recently Added</h2>
- <ol>
- <li><a href="">Desperado</a></li>
- <li><a href="">From Dusk Till Dawn</a></li>
- <li><a href="">Kill Bill Vol.1</a></li>
- <li><a href="">Pulp Fiction</a></li>
- <li><a href="">Reservior Dogs</a></li>
- </ol>
- </div>
- <div class="box top-genres">
- <h2>Top Genres</h2>
- <ol>
- <li><a href="">Desperado</a></li>
- <li><a href="">From Dusk Till Dawn</a></li>
- <li><a href="">Kill Bill Vol.1</a></li>
- <li><a href="">Pulp Fiction</a></li>
- <li><a href="">Reservior Dogs</a></li>
- </ol>
- </div>
- <div class="box most-active box-last">
- <h2>Most Active</h2>
- <ol>
- <li><a href="">Desperado</a></li>
- <li><a href="">From Dusk Till Dawn</a></li>
- <li><a href="">Kill Bill Vol.1</a></li>
- <li><a href="">Pulp Fiction</a></li>
- <li><a href="">Reservior Dogs</a></li>
- </ol>
- </div>
- <div class="clear"></div>
- <div class="copyright">
- <p>built using <a href="http://www.cakephp.org" target="_blank">CakePHP</a> by
- <a href="http://www.jamesfairhurst.co.uk" target="_blank">James Fairhurst</a></p>
- </div>
- </div>
- /* footer */
- #footer { height: 250px; text-align:center;}
- #footer .box { width:230px; float:left; margin:15px 20px 0 0; text-align:left;}
- #footer .box h2 { text-align:center; margin: 0 0 10px 0; width:230px; height:21px; line-height:21px;}
- #footer .box ol { margin:0 0 0 50px;}
- #footer .box ol a { text-decoration:none; font-size: 16px;}
- #footer .box ol a:hover { text-decoration:underline;}
- #footer .box-last { margin:15px 0 0 0;}
- #footer .copyright { margin:20px auto; width:500px; height:32px; line-height:32px;}
- /* backgrounds & colour */
- #footer .box h2 { background:url(img/bg_footer_heading.png) no-repeat; color:#fff;}
- #footer .box ol { color:#bbd9ee;}
- #footer .box ol a { color:#bbd9ee; }
- #footer .box ol a:hover { color:#bbd9ee;}
- #footer .copyright { background:url(img/bg_footer_copyright.png) no-repeat;}
Wrapping Up
At the end of this you should have a pretty flexible looking layout that will work in all modern browsers. The CSS that I've used is pretty standard and I've avoided using any hacks or conditional stylesheets which is always a positive. I doubt this will be the final version as I will be adding to it as I build up the application but for the front page I think it does its job.If these articles are helping you out why not consider donating I can always use a beer! :)