I’m currently working on a new WordPress theme called ♥grid, which lives up to its name with a clear grid based design. Follow this step by step walkthrough of the design and build process, right from the initial Photoshop concept, through to writing the HTML structure, styling up with CSS then adding clever functionality with the jQuery library.
The ♥grid concept is pretty minimal in its design, using a limited colour palette of light grey, dark grey and a highlighting colour of red. The background of the design makes use of a subtle texture for a tactile feel, but the main feature is the strict grid based layout. The design makes use of a 24px baseline and 6 column grid, which becomes a design feature itself as it remains visible as part of the design.
The design concept
The design of ♥grid started in Photoshop. I always begin my website designs with a fairly large canvas of around a 1680px wide, this helps me gauge how the site will look on a typical widescreen monitor.
The background of the canvas is filled with a light grey tone, then given a touch of texture using the Photoshop Noise filter at just 3%.
A new 24x24px document is created, in which the repeating pattern for the baseline grid is created. Just a single 1px line across the lower edge of the canvas is all it takes. This pattern is then defined as a pattern.
The pattern is then filled across a new layer and set to Multiply to render the white area transparent. The vertical grid lines are drawn manually, then duplicated and moved by hand. The cursor keys nudge the lines by 1px, or by 10px while the Shift key is held. Gutters are measured at 21px, and the column widths are 139px.
All the vertical lines are grouped together once six columns are created, then aligned centrally on the document. The basic grid is now ready to be decorated with the actual page elements.
The logo comes first in the top left corner. A selection is made within the first column and filled with red.
The ♥grid logo is then placed inside the logo container, and aligned on the baseline grid.
Navigation elements are then placed on the same baseline, and aligned to the right of each of the five remaining columns. Being links they’re given a red colouring.
Being a theme for a blog the content is made up of sample blog posts. The first post is laid out and spread across columns two to six. Georgia is used for the post titles as a stark contrast against the Helvetica body text. The body text itself is edited so the line height matches the height of the baseline grid.
The first column is reserved for some meta information about the post, such as post date and category. These are laid out in a lighter grey to give less prominence, but at a larger type size. The 24px line height is maintained to keep the consistent leading across the design.
Read more buttons are styled up with a red background and serif Georgia text to give the links extra prominence.
The design begins to take shape as two sample blog posts show the white space and structure across the layout.
The lower portion of the design switches to a darker grey, giving a contrasting footer area. A large selection is filled with a dark grey and given the same noise treatment as the background.
The footer area features a range of lists, these lists begin with two short lists of Categories and Social links. Headers are set in Helvetica, while the links are treated with Georgia at double the line-height.
Links in the lower portion of the design are set in white to give contrast against the dark grey background. The first two lists fit within a single columns, while the second two span across two columns.
Now the design concept is complete, the individual images can be exported ready for the building stage. This starts with the repeating background graphics, taking into account the gridlines so they are recreated when the graphic repeats.
Being a lightweight design, the number of image files is pretty low. Two versions of the background are exported, one with, and one without the grid. This will be developed as a feature at a later stage where the user can toggle the grid lines on and off.
Creating the HTML structure
The next stage of the build is to write out the HTML structure. This begins with a typical webpage layout with Doctype, head and body.
The top portion of the design is contained in a
<div> with an ID of
upper, this will be a hook for the baseline grid pattern in the CSS stage. The logo and navigation list are written out as
<div> with an ID of
main contains the main content, and each post is separated with individual
<div> elements. Inside each post the content is split into two
<div> elements, so the post content and post details can be floated side by side. Despite the details coming first in the design, they are written second in the HTML to keep a logical order of information, these can be positioned correctly by floating them with CSS. Post titles are laid out as
<h2> headings, following on from the
<h1> used in the header.
<p> elements with a class of
btn are used to represent the read more buttons.
In the lower portion of the design, each panel is laid out in its own
<h3> elements identifying the lists of anchor links.
After the four list panels, the three credits are laid out in a
<ul>. Information is given in the anchors, but the actual logos will be displayed using CSS. Finally a back to top link is placed in a
<p> element. This back to top link targets the
Styling the design with CSS
With the HTML strucutre in place, the design can now be styled with CSS to match the original Photoshop concept. The CSS starts with a reset to remove any browser defaults, then begins styling up the page body. A global font style of Helvetica is set, followed by a
line-height of 24px to match the baseline grid. The baseline grid itself is added as a
background-image to the
body, whereas the vertical gridlines are set as background images on the
<h1> is given specific dimensions and a red background to match the design. The”Show/Hide Grid” button in the header is styled accordingly with the small icon as a background image, but is set to
<li> elements in the header are floated side by side and given specific widths and margins to match the size of the grid columns and gutters.
Fonts are styled up in the
#main section, with headers being set in Georgia, body text set in grey Helvetica and buttons set with a red background. Each elements also has a 24px bottom margin to bump the following content down an extra line on the baseline grid.
<div> has 48px of bottom padding, this equates to two baselines as well as the 24px margin on the paragraph elements, leaving three lines between each post. The
details divs are floated side by side, and their contents styled appropriately in accordance to the Photoshop concept.
#footer sections of the design are given new background images to generate the darker footer styling. Font styling for the footer is then reset, making headings a subtle grey colour and links in a more legible white against the dark background.
The four links panels are all floated side by side and given left margin to space them according to the grid gutter. The footer already has padding to take into consideration the first gutter, so the margin on the first div is removed with the
:first-child pseudo selector. Panels one and two are set at the width of one column, while panels three and four span across two columns so are given a greater width, as measured from the Photoshop document. The list of links in each panel is styled to match the concept, with type set in Georgia at a doubled line-height.
The credits list items are floated and given the appropriate margin, as well as the sprite background image. Each individual
<li> is then given specific
background-position settings to display the correct logo. Finally the back to top link is floated over to the right, given the smaller font size and treated with a background image to render the small arrow. A small 3px margin helps tweak the text into place on the grid, ensuring the link is aligned by the text baseline, not the bottom of the icon.
Enhancing with jQuery
The first function to be added is the auto-scrolling back to top link. This code states that when the
#back-top anchor is clicked, animate the
html to the position zero.
Next, the “Show/Hide Grid” button functionality is created. First, the button needs making visible after the CSS was set to
visibility:hidden; earlier. Then the
toggle() function gives commands for when the button is turned on and off, these include adding or removing the class
nogrid to the
body and changing the text of the anchor.
In order for the effect to work, extra CSS styling needs to be added to actually change how the page looks when the page body has the
nogrid class. This is where those alternative background images come into play.
The effect works great, when the user clicks the “Show/Hide Grid” button, the grid is toggled on and off, but once the page is refreshed, or a new page is visited the grid comes back. In order to save the setting the jQuery Cookie plugin needs setting.
$.cookie("grid", "hidden"); creates a new cookie named
grid with the value of
hidden when the button is clicked. A couple of lines of jQuery then check if the cookie is present, and if so the
.html() functions are repeated. Now whenever the user visits the effect will be in the same state as they left it.