Post Ad Area

Saturday, October 9, 2010

Five Useful Design Techniques and Coding Solutions For Web Designers

As designers, we have to create an intuitive user experience, solve design problems and provide a beautiful and functional user interfaces. Unlike print design, we don’t have the luxury of designing in a static area; rather, our canvas is ever-changing in its content, browser width, page length and more. We do need to be able to code to some extent and be able to build a design around a structure of code. Yet, with these complications comes an opportunity for unique functionality, interactive effects and better user experience.
In this article, we’ll look at five useful coding solutions that we’ve stumble upon recently. All of these solutions enhance a website’s design, not just the code. These solutions affect the user interface and the user’s interaction with the design, and they can make for a more usable and interactive website.
[Offtopic: by the way, did you know that there is a Smashing eBook Series? Book #1 is Professional Web Design, 242 pages for just $9,90.]

1. Bar Graph Effect For Multiple Items

This effect (pictured below) can be a great way to add some oomph to a Web page, and make it more user-friendly. Its functionality goes beyond just being a cool trick, though. By organizing any set of items on a page — such as tags, categories, comments, product count — a designer can enhance user interaction, provide useful content clues and improve usability. By seeing a count of items such as tags and product types, the visitor can quickly get an idea of what the website mostly consists of. This is a great way to make quick connections with targeted visitors.
For comment counts, visitors can quickly see where the discussions are at. Highlights on highly commented posts can reinforce user-to-user interaction.
Pictured below are two examples of this design. The left organizes tags, and the second ranks the most commented posts on a blog. Be sure to visit both websites to see the full functionality and CSS effects.
Bargrapheffect in Five Useful Design Techniques and Coding Solutions For Web Designers
Left, Dribbble (number of tags). Right, Engadget, (most commented posts).

How Is It Done?

Recreating this solution is really quite easy. We have to do three things:
  1. Lay out the full list of features,
  2. Create the effect in plain (X)HTML and CSS,
  3. Pull in the counts dynamically and put them into our static version.
Breaking the feature down into simple, specific steps give us the beginnings of a solution. We now have a direction to follow.

List the Bar Graph’s Features

To get started with the first step, let’s lay out exactly what this design does. By laying out the steps in writing, we can sort it out into coding terms.
  1. Dynamically pull in a number count (tags, comments, category count, etc.);
  2. Determine the items with the highest count (perhaps the 10 most commented categories, as opposed to all of them);
  3. Create a horizontal bar corresponding to the count (or a vertical bar for a different look);
  4. Organize the bars in order of quantity.

Recreating the Design (Static)

Now, let’s create the design, only without any dynamic data or automation. We’ll leave out pulling in the number count from a database or other source and make up our own numbers for now. We also won’t create a way to determine the highest results or organize them in descending order; instead, we’ll make up our own numbers, manually organize them and use only 10 for now. After that, we’ll redo this in plain (X)HTML and CSS and do all that dynamic stuff.
The (X)HTML:
01<div class="block">
02    <a href="#" style="width: 100%">Web Interface Design (27)a>
03    <a href="#" style="width: 92.59%">Photoshop Tutorials (25)a>
04    <a href="#" style="width: 74.07%">CSS Tricks (20)a>
05    <a href="#" style="width: 66.66%">Showcases & Inspiration (18)a>
06    <a href="#" style="width: 51.85%">WordPress (14)a>
07    <a href="#" style="width: 48.15%">JavaScript (13)a>
08    <a href="#" style="width: 37.04%">Free Resources (10)a>
09    <a href="#" style="width: 29.63%">Reviews (8)a>
10    <a href="#" style="width: 29.63%">Interviews (8)a>
11    <a href="#" style="width: 25.93%">Typography (7)a>
12div>
The CSS:
01html, body {
02    background: #eee;
03    font: normal 13px/1.5em Arial, Helvetica, sans-serif;
04}
05* {
06    margin: 0;
07    padding: 0;
08}
09.block {
10    width: 400px;
11    margin: 100px auto;
12}
13a {
14    display: block;
15    padding: 5px;
16    margin-bottom: 2px;
17    background-color: #666;
18    color: #fff;
19    text-decoration: none;
20}
21a:hover {
22    background: #9764a0;
23}
The above code will create this static mock-up:
Bargraphdemo in Five Useful Design Techniques and Coding Solutions For Web Designers
Note that we’ve added some basic styling, just to experiment with how hovers could work. For the most part, though, this version is very basic so that you can customize it as you want.
The (X)HTML and CSS should be self-explanatory, but let’s go over how we created the bars. In our style sheet, we created the basic styles and turned each link into a bar using the display: block property. In this simple example, these are the only links on the page, but to be of practical use, some of these bar links would have to be given a class, to distinguish them from the other links on the page. Alternatively, one could use the :nth-child() selector of CSS3 without defining new classes.
We then went into the (X)HTML and set each bar’s width individually with the style attribute. In the (X)HTML code above, we have specified each width as a percentage. We first assume that the highest value, “Web Interface Design (27)”, is 100%. From there, we calculate the percentages of the others relative to that.
Example: “Photoshop Tutorials (25)”
25 × 100 = 2500
2500 ÷ 27 (our 100%) = 92.59%
Photoshop Tutorials (25)

Recreating the Design (Dynamically)

We have now figured out the math and the static code, and we just have to put it all together, pulling the code from a database and automatically organizing and creating the bars.
In this example, we’re working with the number of posts in each of our WordPress categories, but the same logic applies to other uses and other programming languages. The code below might seem long, but don’t worry: it’s mostly comments, which explains how to dynamically calculate the percentages and pull the content into the static (X)HTML/CSS.
01
04 
05
06    $highest = 0; // Initialize our “highest count” variable
07    foreach((get_the_category()) as $category) { // for each category
08        $cat_count = $category->category_count;
09 
10        // If this category’s count is higher than what we have so far
11        // for the highest number…
12        if($cat_count > $highest){
13            // then re-declare our highest value according to this
14            // category’s count
15            $highest = $cat_count;
16        }
17   }
18?>
19 
20
28
class="block">
29 
30foreach((get_categories(‘orderby=count&order=desc’)) as $category) {
31    $cat_name = $category->cat_name;
32    $cat_count = $category->category_count;
33 
34    // Let's calculate this category’s width
35    // (our “100%” is our highest category count number, $highest)
36    $width = ($cat_count x 100) / $highest;
37 
38    // Finally, echo out our link HTML, including our variables
39    // to dynamically bring in the content for the width,
40    // category name and count.
41    echo '$width'.%">
42        .'$cat_name'. (.'$cat_count'.)';
43   }
44?>
45

Demo and Download Files

You can see the demo and download the files from our servers.

2. Animation On Article Hover

Now, this is a very nice aesthetic effect, and it is original, too. Visit CSS Tricks or check out the image below. The articles have a simple clean look, with only an asterisk separating them. When one hovers over a post, we see its meta data: comments, a “Read on” link and date stamp.
What makes this effect especially dynamic is that it features a hover effect for content, not just images. It’s a cool trick and it has some practical uses, too. By hiding content until it’s needed, the designer puts more emphasis on the content and important features. A website can have the appeal of minimalism but still offer rich functionality.
This design solution also makes important content stand out. As on CSS Tricks, when users hover over a post, an action occurs, drawing the user’s eyes to links that will help them interact with the blog.
Hoveronpost in Five Useful Design Techniques and Coding Solutions For Web Designers
When you hover over a home-page post on CSS-Tricks.com, meta content is revealed.

How Is It Done?

This effect might look more complicated than a simple image roll-over, but the same principle applies. With some CSS and a bit of basic JavaScript, we can do the same thing.
Let’s first look more closely at what this effect does. Then we’ll be able to more easily come up with the solution.
  • When any part of a post is hovered over, the effect is triggered.
  • Two pieces of content are revealed, to the left and right of the original image: the date and comments section, and the “Read on” section.
  • On moving the mouse, the post returns to normal.
Seeing how this is similar to image roll-overs is now easier. For image roll-overs, we use JavaScript to change code for onMouseOver and onMouseOut. We’ll do a similar thing here, but use divs instead of images. Also with image roll-overs, we’ll usually replace one image with another. Our action here instead will be just to show and hide content.

The (X)HTML

We need to wrap a div element around the entire post, and we can manage that as a single step. We can then apply the JavaScript events to it: MouseOver and MouseOut. For each, we simply set the content’s display property (defined by a CSS id) to none or inline. Instead of using inline-attributes, it’s better to separate JavaScript and CSS, e.g. using jQuery.
01<div class="post">
02 
03<h2>A Blog Post Titleh2>
04<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque dignissim est ultrices neque fermentum convallis. Nulla libero lacus, accumsan sed porta quis, pulvinar in lectus. Sed id justo lorem, eu ullamcorper sapien. Nullam tincidunt lorem nec nisl egestas gravida vel et massa. Donec arcu nisl, venenatis ac suscipit dignissim, egestas auctor lectus. Quisque vulputate fermentum felis sed tristique. Ut enim felis, faucibus ac fermentum rutrum, posuere id nulla. Duis lectus dolor, eleifend in tincidunt eu, sagittis sed sapien. Duis id purus id magna facilisis luctus. Mauris sodales arcu ut arcu laoreet id pulvinar ligula hendrerit.p>
05 
06
07<p id="postimg" class="center">
08<img src="triangle.png" alt="Triangle" />
09p>
10 
11
12<p id="hiddencontent" class="center">
13Posted on 9/15/10 | <a href="#">23 Commentsa>
14<img src="triangle.png" alt="Triangle" />
15<a href="#">Continue Reading…a>
16p>
17 
18div>
19 
20<script type="text/javascript">
21$('.post').mouseover(function() {
22    $('#hiddencontent').css('display', 'inline');
23    $('#postimg').css('display', 'none');
24});
25 
26$('.post').mouseout(function() {
27    $('#hiddencontent').css('display','none');
28    $('#postimg').css('display', 'block');
29});
30script>

The CSS

Here, we’ve just done some basic styling: centered our div, styled the h2 tag, played with fonts, etc. The thing to note here is the #hiddencontent div. Because we need to hide our content on page load, we must set it in the CSS to display: none.
01html, body {
02    background: #eee;
03    font: normal 14px/1.6em Arial, Helvetica, sans-serif;
04}
05 
06#hiddencontent {
07    display: none;
08}
09 
10h2 {
11    margin-bottom: .5em;
12}
13 
14.center {
15    width: 500px;
16    text-align: center;
17}
Below is our mock-up of the design (top is before the hover, and bottom is after). It’s just some basic CSS and JavaScript, and the code is easy enough to work around when implementing in WordPress or elsewhere.
Posthoverdemo in Five Useful Design Techniques and Coding Solutions For Web Designers

Demo and Download Files

You can see the demo and download the files from our servers.

3. A Color For Each Category

This technique gives each category on a website a different color (see Emprnt for a full implementation). This is a great way to color-code a design to give it better organization and easier navigation. For now, let’s figure out how to repeat this effect with WordPress and categories, as on Emprnt.
The same solution could be applied to other items: roles (authors have one color, editors another); authors (assign colors based on posts, tags, etc.); highlighting popular posts (highlight posts that have 150 to 200 page views with one color, and then 75 to 150 with another, and so on). The experience will vary according to your application. For example, by color-coding categories, you aid navigation and usability. By color-coding popular posts, you help users see which posts are getting the most attention.
Categorycolors in Five Useful Design Techniques and Coding Solutions For Web Designers
Emprnt uses CSS and a bit of code to create a different color for each category as a post is published.

How Is It Done?

To pull this off, we need to pick a color for each category, identify each category’s id and then match each id with a CSS class that specifies the color and any other basic styling. First, let’s take care of the static (X)HTML and CSS:

Recreating the Effect (Static)

The (X)HTML:
01<div class="block">
02    <div class="post cat_1">
03        <h2>A Blog Post Titleh2>
04        <small>Category 1small>
05        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
06        Pellentesque dignissim est ultrices neque fermentum convallis.
07        Nulla libero lacus, accumsan sed porta quis, pulvinar in lectus.
08        Sed id justo lorem, eu ullamcorper sapien. Nullam tincidunt
09        lorem nec nisl egestas gravida vel et massa. Donec arcu nisl,
10        venenatis ac suscipit dignissim, egestas auctor lectus.p>
11    div>
12 
13    <div class="post cat_2">
14        <h2>A Blog Post Titleh2>
15        <small>Category 2small>
16        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
17        Pellentesque dignissim est ultrices neque fermentum convallis.
18        Nulla libero lacus, accumsan sed porta quis, pulvinar in lectus.
19        Sed id justo lorem, eu ullamcorper sapien. Nullam tincidunt
20        lorem nec nisl egestas gravida vel et massa. Donec arcu nisl,
21        venenatis ac suscipit dignissim, egestas auctor lectus.p>
22    div>
23 
24    <div class="post cat_2">
25        <h2>A Blog Post Titleh2>
26        <small>Category 2small>
27        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
28        Pellentesque dignissim est ultrices neque fermentum convallis.
29        Nulla libero lacus, accumsan sed porta quis, pulvinar in lectus.
30        Sed id justo lorem, eu ullamcorper sapien. Nullam tincidunt
31        lorem nec nisl egestas gravida vel et massa. Donec arcu nisl,
32        venenatis ac suscipit dignissim, egestas auctor lectus.p>
33    div>
34 
35    <div class="post cat_3">
36        <h2>A Blog Post Titleh2>
37        <small>Category 3small>
38        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
39        Pellentesque dignissim est ultrices neque fermentum convallis.
40        Nulla libero lacus, accumsan sed porta quis, pulvinar in lectus.
41        Sed id justo lorem, eu ullamcorper sapien. Nullam tincidunt
42        lorem nec nisl egestas gravida vel et massa. Donec arcu nisl,
43        venenatis ac suscipit dignissim, egestas auctor lectus.p>
44    div>
45 
46    <div class="post cat_1">
47        <h2>A Blog Post Titleh2>
48        <small>Category 1small>
49        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
50        Pellentesque dignissim est ultrices neque fermentum convallis.
51        Nulla libero lacus, accumsan sed porta quis, pulvinar in lectus.
52        Sed id justo lorem, eu ullamcorper sapien. Nullam tincidunt
53        lorem nec nisl egestas gravida vel et massa. Donec arcu nisl,
54        venenatis ac suscipit dignissim, egestas auctor lectus.p>
55    div>
56div>
As you can see, we’ve given each post two classes: post and cat_#. This example has only three categories, with their classes named cat_1, cat_2 and cat_3, but keep in mind that these numbers will change according to our category ids later.
The CSS:
01html, body {
02    background: #eee;
03    font: normal 13px/1.5em Arial, Helvetica, sans-serif;
04}
05 
06* {
07    margin: 0;
08    padding: 0;
09}
10 
11h2 {
12    margin-bottom: .5em;
13}
14 
15small {
16    font-size: 9px;
17    line-height: 1.4em;
18    font-weight: bold;
19    text-transform: uppercase;
20}
21 
22.block {
23    width: 500px;
24    margin: 50px auto;
25}
26 
27.post {
28    padding: 15px 0 15px 15px;
29    margin-bottom: 2px;
30}
31 
32.cat_1 { border-left: 10px solid #cb005b; }
33.cat_1 small { color: #cb005b; }
34.cat_2 { border-left: 10px solid #0064cb; }
35.cat_2 small{ color: #0064cb; }
36.cat_3 { border-left: 10px solid #cb7700; }
37.cat_3 small{ color: #cb7700; }
At the top we have basic styling, and toward the bottom we have our category-specific styling. We have given each category’s unique class a colored border and name. With our static (X)HTML and CSS, we should get the following mock-up:
Categorycolorsdemo in Five Useful Design Techniques and Coding Solutions For Web Designers

Recreating the Effect (Dynamically)

Doing this dynamically in WordPress is not difficult at all:
01
class="block">
02 
03if (have_posts()) : ?>
04while (have_posts()) : the_post(); ?>
05 
06    
class="post cat_foreach((get_the_category()) as $category)
07            {echo $category->cat_ID . ' ';}
08            ?>">
09        

10 
11        ', ') ?>
12        'Continue reading', 'example')); ?>
13    
14 
15endwhile;?>
16else : ?>
17    

class="center">Not Found

18 
19    class="center">Sorry, but you are looking for something that isn't here.
20 
21    include (TEMPLATEPATH . "/searchform.php"); ?>
22endif; ?>
23 
24
For our essential piece of code, we just need to dynamically place the category id number inside
#">. Note that the ids will likely not be 1, 2 and 3 (as in our static example), so we’ll have to adjust. Find your category ids, and adjust the CSS class names accordingly. For example, if a featured category has an id of 24, then the corresponding CSS class to create that category should be cat_24.Note: with this solution, if a post has multiple categories, the post will default to the color of the first listed category.

Demo and Download Files

You can see the demo and download the files from our servers.

4. Interesting Image Captions

This last solution is simple but often overlooked. Image styling and positioning are important in any type of Web design, and attractive captions are also a must. There is really no set HTML standard for image captions, so creating seemingly simple effects requires a bit of creativity.
Imagecaptions in Five Useful Design Techniques and Coding Solutions For Web Designers
Left, Boagworld. Right, UXbooth

The (X)HTML

To group caption text and images, we need to place them in a div. Then, we’ll style the div and its components.
1<div class="image-caption">
2<img src="images/testimage.jpg" alt="Test Image" />
3<p>Here is the image caption text, and a <a href="#">linka>.p>
4div>
Remember, the div must be identified by a class, because we’ll be displaying images and captions multiple times throughout the website. The above code is a great starting point and could yield a number of different solutions. Below are a few CSS options and examples.

CSS Examples

Imagecaption1 in Five Useful Design Techniques and Coding Solutions For Web Designers
01.image-caption {
02    width: 240px;
03    background: #fff;
04    padding: 3px;
05    border: 1px dotted #aaa; }
06.image-caption img {
07    border: 1px solid #aaa; }
08.image-caption p {
09    clear: both;
10    font: normal 9px/1.45em Verdana, Tahoma, sans-serif;
11    color: #444; }
12.image-caption a {
13    color: #444;
14    text-decoration: underline; }
15.image-caption a:hover {
16    font-style: italic; }
Above is a very simple image caption style: clean, organized and minimal. The “Polaroid” look, if you will.
Imagecaption2 in Five Useful Design Techniques and Coding Solutions For Web Designers
01.image-caption {
02    width: 240px;
03    position: relative; }
04 
05.image-caption img {
06    border: 1px solid #333; }
07 
08.image-caption p {
09    position: absolute;
10    bottom: 5px;
11    width: 232px;
12    filter:alpha(opacity=70);
13    -moz-opacity:0.7;
14    -khtml-opacity: 0.7;
15    opacity: 0.7;
16    background: #000;
17    padding: 5px;
18    color: #fff;
19    clear: both; }
20 
21.image-caption a {
22    color: #fff;
23    text-decoration: underline; }
24 
25.image-caption a:hover {
26    font-style: italic;
27}
Above is a simple overlay technique for captions. The most important properties here are position: relative under .image-caption, and position: absolute, bottom: 5px and width: 32px under .image-caption img. The bottom would usually be set to 0, but in our case we adjusted it to 5px because of the added padding. Same goes for the width: we adjusted it to accommodate the added padding and image border.
Imagecaption3 in Five Useful Design Techniques and Coding Solutions For Web Designers
01.image-caption {
02    width: 240px;
03    background: #fff; }
04.image-caption img {
05    border: 1px solid #aaa; }
06.image-caption h1 {
07    padding: 0 5px;
08    font: bold 10px/1.4em Arial, Helvetica, sans-serif;
09    color: #cc0000; }
10.image-caption p {
11    clear: both;
12    padding: 0 5px 10px;
13    font: normal 9px/1.45em Verdana, Tahoma, sans-serif;
14    color: #444; }
15.image-caption a {
16    color: #444;
17    text-decoration: underline; }
18.image-caption a:hover {
19    font-style: italic; }
To add other styles (such as the image title here), just add them to the CSS under the .image-caption class, and then remember to add

Image title

where desired in the mark-up.It takes minimal yet creative CSS to create some pretty cool effects. Experiment with a few other things, such as CSS3 rounded corners, different positioning, border styles and more. Below are more resources and techniques to get interesting image captions, some with plain (X)HTML and CSS and others requiring JavaScript and WordPress.

Demo and Download Files

You can see the demo and download the files from our servers.

Other Neat Solutions

5. Print Layouts For The Web

Print-inspired layouts can be a refreshing change from standard Web layouts. While not suitable to all website types, this technique is definitely catchy for those that pull it off. Of course, with Web design, we must use code to create the look we’re going for. How can we create Web designs that resemble print layouts efficiently — with unconventional layouts and interesting typography — and code them in a way that still adheres to web design best practices?
Printdesign in Five Useful Design Techniques and Coding Solutions For Web Designers
This Web page has a layout and design that look more like a print piece than a traditional website.
Because print-inspired designs can vary so much, there are many various coding solutions available. But there are best practices. Below are just a few of the things to consider.

Web Design Must Be Fluid, While Print Does Not

One reason print design can look so creative is that the content doesn’t have to adapt to varying widths and lengths. On the Web, though, text, images and other content change all the time, sometimes straining the layout. There are a couple solutions to this. First, as in the example above, if the content is set and won’t change (such as blog posts), then feel free in designing around the text. Line height, letter spacing and other elements can be adjusted precisely to play around the images and background and then be left alone.
For non-static content, some thinking may be required:
  • Fixed-width designs are probably best if possible. Then, the designer will only have to expect the content to change vertically. (For a different approach, you could set a fixed height and then worry only about varying widths.)
  • With well-organized and properly nested code, content that expands or contracts should not be a problem; it might just take some brainstorming to consider design solutions that would look good in a couple of different scenarios.
  • Learn how to use (X)HTML and CSS together, avoid div-itus as much as possible, and always look for ways to make code shorter and smarter.
Coding and positioning a print-inspired design can be difficult, but never impossible. However the content varies, for the most part it will stay within a certain range in each section, which is helpful. For example, an “About us” blurb will not suddenly jump from 200 to 1000 words, but it might increase in height by a few lines of text.

Organized and Reusable CSS

Make CSS classes and ids as reusable as possible by making them as general as possible. Then, apply area-specific styles directly on the page where they need to be applied. Always be thinking of ways to better organize and reuse CSS in the mark-up. Without consistency in the layout, this can be difficult and therefore requires more attention.

Get Inspired

Devising one unique coding solution for a print-inspired Web design is difficult indeed, and so the only real solution is to learn best coding practices and use them to create the most efficient solution for that particular design. For some print-design inspiration on the Web and some live coded examples, check out a few of the showcases below.
Heartdirected in Five Useful Design Techniques and Coding Solutions For Web Designers
Heart Directed is a showcase of print-inspired blog posts and other website designs.
Coldheat in Five Useful Design Techniques and Coding Solutions For Web Designers
Coldheat has a general Web design showcase and a a special section for unique layout designs.
Blogpostdesigns in Five Useful Design Techniques and Coding Solutions For Web Designers
This post on WebdesignerDepot showcases several blog posts with a unique print look.

Further Resources

Below are a few more related articles, some from right here on Smashing Magazine and others from around the Web. All share some great ideas and techniques you can experiment with.

Conclusion

Without calling ourselves “developers,” we, designers, can add some nice effects and added functionality with a bit of extra coding knowledge. None of these effects are difficult to figure out, but each can really add to a website. Some create an attractive visual experience, while others provide visitors with more information or functionality. Whatever the purpose, each has its proper use.
We’d love to cover more coding solutions that are unique, useful or just interesting. Please feel free to suggest more examples of advanced techniques in the comments below. Hopefully, we’ll be able to include them in a future article.
  1. Thanks for your HTML tips man. I have heard that there is a new version of HTML named HTML5 in the market and it has new and great features. If we use it, we wont need any flash player as it has an inbuilt feature of playing flash.
    Thanks for your efforts.

    ReplyDelete
  2. Thanks for being with us. Matching the exact domains make the site SEO friendly and will contribute to rank it better in search engines. But it can increase the prices of domains…

    ReplyDelete

Start typing and press Enter to search