http://aux.iconpedia.net/uploads/10875870971013046993.pnghttp://aux.iconpedia.net/uploads/1540998406962263282.png !

Featured Post 1 Title

Replace these every slide sentences with your featured post descriptions.Go to Blogger edit html and find these sentences.Now replace these with your own descriptions.This theme is Bloggerized by Lasantha - Premiumbloggertemplates.com.Download more free blogger templates from www.premiumbloggertemplates.com.

Read More

Featured Post 2 Title

Replace these every slide sentences with your featured post descriptions.Go to Blogger edit html and find these sentences.Now replace these with your own descriptions.This theme is Bloggerized by Lasantha - Premiumbloggertemplates.com.Download more free blogger templates from www.premiumbloggertemplates.com.

Read More

Featured Post 3 Title

Replace these every slide sentences with your featured post descriptions.Go to Blogger edit html and find these sentences.Now replace these with your own descriptions.This theme is Bloggerized by Lasantha - Premiumbloggertemplates.com.Download more free blogger templates from www.premiumbloggertemplates.com.

Read More

Featured Post 4 Title

Replace these every slide sentences with your featured post descriptions.Go to Blogger edit html and find these sentences.Now replace these with your own descriptions.This theme is Bloggerized by Lasantha - Premiumbloggertemplates.com.Download more free blogger templates from www.premiumbloggertemplates.com.

Read More

Featured Post 5 Title

Replace these every slide sentences with your featured post descriptions.Go to Blogger edit html and find these sentences.Now replace these with your own descriptions.This theme is Bloggerized by Lasantha - Premiumbloggertemplates.com.Download more free blogger templates from www.premiumbloggertemplates.com.

Read More

Featured Post 7 Title

Replace these every slide sentences with your featured post descriptions.Go to Blogger edit html and find these sentences.Now replace these with your own descriptions.This theme is Bloggerized by Lasantha - Premiumbloggertemplates.com.Download more free blogger templates from www.premiumbloggertemplates.com.

Read More

Featured Post 6 Title

Replace these every slide sentences with your featured post descriptions.Go to Blogger edit html and find these sentences.Now replace these with your own descriptions.This theme is Bloggerized by Lasantha - Premiumbloggertemplates.com.Download more free blogger templates from www.premiumbloggertemplates.com.

Read More
Tampilkan postingan dengan label CSS and jQuery. Tampilkan semua postingan
Tampilkan postingan dengan label CSS and jQuery. Tampilkan semua postingan

Juli 02, 2011

Achieving Double Background Effect with CSS

Tags:


Recently I was put into a situation where one of my client’s liquid layout site was in need of a redesign going back to a fixed/center aligned layout. The site’s layout and design was not designed to be centered aligned and so when implementing the design in code, I ran into some issues trying to achieve the same look and feel.

Do we sacrifice the design for implementation boundaries?

Typically when creating a stretch effect with CSS backgrounds, we would take a fixed width of the background and repeat it on the X-axis until it fills the page. Of course to achieve this effect, the center aligned header image would have to match the repeating background on both ends.
Typical Stretch Technique
Double Backgrounds with CSS

In our scenario, we would need a repeating background to accommodate for the left side and the right side of the header. How do we achieve this effect?
Double Background Stretch Technique
Double Backgrounds with CSS

Well we all know our current CSS version cannot handle double backgrounds. Hopefully in the future this will be available so we don’t have to pull these work-a-rounds.

The Double Background Effect

The solution is to use two repeating images, one for the left-side background, and another for the right-side background.
HTML
For the left-side repeating image, we will add a background to the body tag. Then, to accomodate the right-side repeating image, we will add an additional <div> tag, which will contain the second background.
<div id="bg_wrap"></div> <!--Right-Side Repeating Background Image-->
<div class="container"> <!-- Container Class to center align and have a fixed width / The image header.gif is just as an example for placement -->
 <img src="header.gif" alt="" />
</div>
CSS
body {}
For the left-side repeating image, we apply the background to our body tag.
body {
 margin: 0;
 padding: 0;
 background: #e5e5e5 url(bg_body.gif) repeat-x;
 position: relative;
}
#bg_wrap {}
Then we will create the other half by adding an absolution position that will stick to the right.
#bg_wrap {
 height: 96px;
 width: 50%;
 right: 0;
 background: url(bg_wrap.gif) repeat-x;
 position: absolute;
}
.container
This class will be the container of your contents, it will contain the width, background color, center alignment, and the position set to ‘relative’.
.container {
 width: 960px;
 background: #e5e5e5;
 margin: 0 auto;
 overflow: hidden;
 position: relative;
}
Final Output
<!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=iso-8859-1" />
<title>Double Backgrounds with CSS - CSS/XHTML Tutorial by Soh Tanaka</title>
<style type="text/css">
body {
 margin: 0;
 padding: 0;
 background: #e5e5e5 url(bg_body.gif) repeat-x;
 position: relative;
}
#bg_wrap {
 height: 96px;
 width: 50%;
 right: 0;
 background: url(bg_wrap.gif) repeat-x;
 position: absolute;
}
.container {
 width: 960px;
 background: #e5e5e5;
 margin: 0 auto;
 overflow: hidden;
 position: relative;
}
</style>
</head>

<body>
 <div id="bg_wrap"></div>
 <div class="container">
  <img src="header.gif" alt="" />
 </div>
</body>
</html>

Conclusion

Some may say that the additional empty div tag is not good semantics coding. Which I agree, it has no meaning to the content of our website. But I feel it can be appropriate to add one single line of html so that we don’t have to sacrifice our design to fit our implementation roadblocks and boundaries. If you have any questions, comments, or have a better solution I would love to hear your thoughts!
(Continue)..

(Continue)..

CSS Vertical Navigation with Teaser

  Tags:

This technique is a simple way to display some teaser information for your vertical navigation. I won’t waste any of your time with an intro, let’s get right into the code.

HTML

We will start by creating a list item, but in this case, we will add an empty ‘span’ tag inside of the hyper link. The CSS will look at the content of the span tag as a display: none until it’s hovered over.
<ul class="sidenav">
 <li>
  <a href="#">Home
  <span>Blandit turpis patria euismod at iaceo appellatio, demoveo esse. Tation utrum utrum abigo demoveo immitto aliquam sino aliquip. </span>
  </a>
 </li>
 <li>
  <a href="#">Blog
  <span>Blandit turpis patria euismod at iaceo appellatio, demoveo esse. Tation utrum utrum abigo demoveo immitto aliquam sino aliquip. </span>
  </a>
 </li>
 <li>
  <a href="#">Tutorials
  <span>Blandit turpis patria euismod at iaceo appellatio, demoveo esse. Tation utrum utrum abigo demoveo immitto aliquam sino aliquip. </span>
  </a>
 </li>
</ul>

CSS

We will first style the vertical navigation list. What I like to do is add a light bevel look on each of the navigation links.
ul.sidenav {
 font-size: 1.2em;
 float: left;
 width: 200px;
 margin: 0;
 padding: 0;
 list-style: none;
 background: #005094;
 border-bottom: 1px solid #3373a9;
 border-top: 1px solid #003867;
}
ul.sidenav li a{
 display: block;
 color: #fff;
 text-decoration: none;
 width: 155px;
 padding: 10px 10px 10px 35px;
 background: url(sidenav_a.gif) no-repeat 5px 7px;
 border-top: 1px solid #3373a9;
 border-bottom: 1px solid #003867;
}
Then we will now add the hide/show effect when it’s hovered.
ul.sidenav li a:hover {
 background: #003867 url(sidenav_a.gif) no-repeat 5px 7px;
 border-top: 1px solid #1a4c76;
}
ul.sidenav li span{ display: none; }
ul.sidenav li a:hover span {
 display: block;
 font-size: 0.8em;
 padding: 10px 0;
}

Bevel Colors

How did I choose the right colors to achieve the bevel look?
  1. Open Photoshop
  2. Create a new document of any size, I just did a random size of 300×300
  3. Fill the background with your <ul> base background color.
  4. Using your marquee tool, set it to the ‘single row marquee tool’
  5. Create a new layer and fill it with white
  6. Duplicate this layer but this time fill it with black.
  7. Now lower the opacity on those layers: Black Layer: 30% / White Layer 20%
  8. Now using the Eyedropper tool, select the two colors.
Bevel Effect - Photoshop
Bevel Effect - Photoshop

Conclusion

In addition to adding teaser information to the navigation, this technique can be modified to add descriptions to any element of page. You could add teaser descriptions to profile names, question-and-answer type FAQ pages, navigation, or a multitude of other applications.
(Continue)..

(Continue)..

Inline Modal Window w/ CSS and jQuery

 Tags:

Please note: This tutorial requires intermediate knowledge of CSS and jQuery. For best results, please be sure to learn the proper foundations before attempting to take this tutorial. Learn one step at a time :-)
There are many elegant and easy to install modal window (Popup) plugins out there, but there are times where the script interferes with some of the logic processed on the page. I recently had a situation where I was not able to use plugins like fancybox and prettyPhoto so I had to create my own modal window that pulled inline html within the page. Here is how I approached this situation:
Inline Modal Window w/ CSS and jQuery

HTML

We begin by adding a <a> tag with the following attributes:
  • href - #?w=500 specifies the width of the popup
  • rel – Set a unique rel for this Popup
  • class="poplight" – Class needed to trigger popup
<a href="#?w=500" rel="popup_name" class="poplight">Learn More</a>
Next we set up the inline markup for the popup. This can be placed anywhere on the page, I set this towards the bottom of the content. Notice that the id of the popup matches the <a> tag’s rel attribute. This is what associates the link and popup together.
<div id="popup_name" class="popup_block">
    <h2>Turtle Power</h2>
    <p>I <3 Turtles.</p>
</div>

CSS

Take a look at the comments below for an explanation of the styles. Notice that we don’t specify the margin on the .popup_block in the CSS. Since the popups may vary in size, we will have jQuery calculate this for us in the next step.
#fade { /*--Transparent background layer--*/
 display: none; /*--hidden by default--*/
 background: #000;
 position: fixed; left: 0; top: 0;
 width: 100%; height: 100%;
 opacity: .80;
 z-index: 9999;
}
.popup_block{
 display: none; /*--hidden by default--*/
 background: #fff;
 padding: 20px;
 border: 20px solid #ddd;
 float: left;
 font-size: 1.2em;
 position: fixed;
 top: 50%; left: 50%;
 z-index: 99999;
 /*--CSS3 Box Shadows--*/
 -webkit-box-shadow: 0px 0px 20px #000;
 -moz-box-shadow: 0px 0px 20px #000;
 box-shadow: 0px 0px 20px #000;
 /*--CSS3 Rounded Corners--*/
 -webkit-border-radius: 10px;
 -moz-border-radius: 10px;
 border-radius: 10px;
}
img.btn_close {
 float: right;
 margin: -55px -55px 0 0;
}
/*--Making IE6 Understand Fixed Positioning--*/
*html #fade {
 position: absolute;
}
*html .popup_block {
 position: absolute;
}

Step 3. Setting up jQuery

For those who are not familiar with jQuery, do check out their site first and get an overview of how it works. I’ve shared a few tricks that I have picked up along the way, you can check those out as well.
Initial Step – Call the jQuery file
You can choose to download the file from the jQuery site, or you can use this one hosted on Google.
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
Directly after the line where you called your jQuery, start a new <script> tag and start your code by using the $(document).ready event. This allows your jQuery code to run the instant the DOM is ready to be manipulated. The code you will be writing in the next few steps will all take place within.
$(document).ready(function() {
 //Code goes here
});

Step 4. Activate Popup with jQuery

The following script contains comments explaining which jQuery actions are being performed.
//When you click on a link with class of poplight and the href starts with a # 
$('a.poplight[href^=#]').click(function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

    return false;
});

//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
    });
    return false;
});

Final Thought

For those jQuery masters, please let me know if there are ways to improve this code. I am all open ears and hungry to learn :-)
For those who have questions or concerns, feel free to let me know! If you would like to use images or flash videos in the popups, please use the elegant plugin solutions since this code is only meant for a light weight inline popup.
Inline Modal Window w/ CSS and jQuery
(Continue)..

(Continue)..

Avoiding Excess Margin on Repeating Columns


Tags:
Creating columns in CSS is not very hard to achieve but when working with a dynamic site and if the CMS does not allow you to easily modify each column accordingly, you end up with a set of excess margin. Below is a common example of what I’m talking about.
Uneven Columns with CSS
Normally you can just specify the last column to take away the excess margin, but what if you were working in a system where it didn’t allow you to easily customize each column in the html or the columns were being displayed dynamically?

The Solution

By wrapping the unordered list and hiding the excess margin, we are able to go around this issue.
Uneven Columns with CSS

HTML

Wrap the unordered list with another div and specify the container width. The trick is to add an overflow:hidden; to hide the excess 10px margin to the right.
<div class="container">
<ul class="col3">
 <li>
  <h2>Column 1</h2>
 </li>
 <li>
  <h2>Column 2</h2>
 </li>
 <li>
  <h2>Column 3</h2>
 </li>
</ul>
</div>

CSS

Now calculate the padding and margin as it fits within your column. If you were to calculate the max width of 970px for a three column layout:
(Max Width + Right Margin) / # of Columns – (L and R Padding + Right Margin) = Column Width
(970px + 10px) / 3 – (40px +10px) = 276px
.container {
 margin: 0 auto;
 width: 970px;
 overflow: hidden;
}
ul.col3 {
 width: 980px;
 margin: 20px 0;
 padding: 0;
 list-style: none;
 float: left;
}
ul.col3 li {
 float: left;
 background: #fff;
 width: 276px;
 padding: 10px 20px;
 margin: 5px 10px 5px 0;
}

Conclusion

This is just a ‘work-around’ trick I use when trying to avoid excess margins on repeating columns. It would be ideal to use the :first-child and :last-child pseudo-classes in these situations, but until its supported by all major browsers, I felt this was simple enough to use. If you have any better solutions or techniques, please let me know!
(Continue)..

(Continue)..

Table of Contents Style Layout with CSS


Tags:
For a recent project, I was designing a price guide that was basically very similar to a typical Table of Contents type of layout. I hope it can come in handy for some of you.

HTML

<ul class="tablel_content">
 <li>
  <strong>Chapter 1</strong>
  <em>4</em>
 </li>
 <li>
  <strong>Chapter 2</strong>
  <em>10</em>
 </li>
</ul>

CSS

We will be using a background image that would repeat the dotted lines across each list item. Using the background positioning we will keep it aligned with the rest of the text and use the padding to cover the areas where it should not overlap.
ul.tablel_content {
 width: 500px;
 margin: 0 auto;
 padding: 0;
 list-style: none;
 font-size: 1.7em;
}
ul.tablel_content li {
 margin: 0;
 padding: 10px 0;
 text-align:right;
 background: url(dotted.gif) repeat-x left 22px;
}
ul.tablel_content li strong, ul.tablel_content li em {
 float: left;
 background: #1d1d1d; /*--Combined Property with 'li em'--*/
 padding: 0 10px; /*--Combined Property with 'li em'--*/
}
ul.tablel_content li em {
 float: none;
}
(Continue)..

(Continue)..

Fixed Footer Backgrounds with CSS

 

Tags:
I’ve gotten a couple of emails asking me how to pull off this effect so I thought it may be helpful for others as well. When fixing a background image on the bottom of your page, the following technique seemed to be the easiest from my experience.

HTML

<div class="headwrap">
 <!--Content Goes Here-->
        <div class="container"></div>
 <!--End Content-->
</div>

CSS

We will first add the repeating footer image on our body tag and position it to the bottom as fixed.
body {
 margin: 0;
 padding: 0;
 background: #005094 url(footer_bg.jpg) fixed repeat-x left bottom;
 width: 100%;
 min-width:970px;/*--Fixes Background Bug--*/
}
Then we will add in our header background in a div.
.headwrap {
 background: url(body_bg.jpg) no-repeat center top;
 float: left;
 width: 100%;
}

Conclusion

I’m sure there are various ways of achieving this effect, if you have any other suggestions or have any questions please feel free to let me know.
(Continue)..

(Continue)..

Sexy Ordered Lists with CSS



Tags:

Recently I was working on a site where I had to style an ordered list and thought this may help some of you in future projects. The snag that some people tend to run into is that they are not sure how to separate the styles of the numbers and the actual content of the list.

It may feel easier to number each list item manually but then we end up defeating the purpose. In this tutorial I will show how to give an ordinary ordered list a face lift.

HTML

We will first create an ordered list and add two elements, the heading and a paragraph.
<ol class="steps">
 <li>
  <h2>heading</h2>
  <p>paragraph</p>
 </li>
 <li>
  <h2>heading</h2>
  <p>paragraph</p>
 </li>
</ol>

CSS

Start by styling the ordered list itself. Note that we will specify a font style to the list item first (this will be the styles for the numbers).
ol.steps {
 margin: 20px 0;
 background: url(ul_bg_repeat.gif) repeat-y; /*--Bg of the order numbers--*/
 padding: 0 0 0 35px; /*--Distance between the order numbers--*/
 border: 1px solid #111;
}
ol.steps li {
 margin: 0;
 padding: 15px 15px;
 color: #cbff78;
 font-size: 1.7em;
 font-weight: bold;
       /*--The bevel look is styled with various colors in the border properties below--*/
 border-top: 1px solid #000;
 border-bottom: 1px solid #353535;
 border-right: 1px solid #333;
 border-left: 1px solid #151515;
 background: #222;
}
When using border colors to create the bevel look, you will notice we will have an extra pixel at the top and bottom of your list.
You can fix this in two ways. First create a class for the top and bottom list items.
ol.steps li.first { border-top: 1px solid #353535; }
ol.steps li.last { border-bottom: none; }
Method 1 – Manual
Specify the above classes for the first and last list item manually in the HTML
<li class="first"><!--Content--></li>
<li><!--Content--></li>
<li class="last"><!--Content--></li>
Method 2 – jQuery
Use jQuery to add the classes on the first and last list item.
<script type="text/javascript">
 $(document).ready(function() {
  $("ol.steps li:first").addClass("first");
  $("ol.steps li:last").addClass("last");
 });
</script>
Now that we are done styling the list item, we will override the base font style with the heading and paragraph tags.
ol.steps li h2 {
 font-size: 0.9em;
 padding: 5px 0;
 margin-bottom: 10px;
 border-bottom: 1px dashed #333;
 color: #fff;
}
ol.steps li p {
 color: #ccc;
 font-size: 0.7em;
 font-weight: normal;
 line-height: 1.6em;
}

Conclusion

As you can see, ordered lists don’t have to be boring. If you have any other techniques to style ordered lists, please let me know!
(Continue)..

(Continue)..

Styling Code Snippets with CSS


Tags:

Although there are many useful plug-ins out there that dress up code snippets, I would like to share a technique playing with the background of the <pre> and <code> tag with CSS.


Common Problem with FireFox

When trying to add some padding to the <pre> tag, FireFox creates a cross-browser bug where it interferes with the spaces created by the space or tab bar. See below for an example.
CSS FireFox Code Bug
Solution
We can go around this issue by nesting the <code> tag within the <pre> tag and specifying a margin in <code>.

HTML

Start out by placing your code snippet in between the <pre> and <code> tag. Note that anything inside of the <pre> tag is preserved (spaces and line breaks).
<pre><code>.classname {
 /*--Code Goes Here--*/
 /*--Code Goes Here--*/
 /*--Code Goes Here--*/
 /*--Code Goes Here--*/
}
</code></pre>

CSS

pre {
 font-size: 12px;
 padding: 0;
 margin: 0;
 background: #f0f0f0;
 border-left: 1px solid #ccc;
 border-bottom: 1px solid #ccc;
 line-height: 20px; /*--Height of each line of code--*/
 background: url(pre_code_bg.gif) repeat-y left top; /*--Background of lined paper--*/
 width: 600px;
 overflow: auto; /*--If the Code exceeds the width, a scrolling is available--*/
 overflow-Y: hidden;  /*--Hides vertical scroll created by IE--*/
}
pre code {
 margin: 0 0 0 40px;  /*--Left Margin--*/
 padding: 18px 0;
 display: block;
}

Make <pre> Tags Print Friendly

To make <pre> tags print friendly and make the code wrap to the next line, Tyler at www.longren.org shared a great technique to tackle this issue. If you are new to print style sheets, check out my previous tutorial.
print.css
pre {
 overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
 white-space: pre-wrap; /* css-3 */
 white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
 white-space: -pre-wrap; /* Opera 4-6 */
 white-space: -o-pre-wrap; /* Opera 7 */ /*
 width: 99%; */
 word-wrap: break-word; /* Internet Explorer 5.5+ */
}

Conclusion

If you haven’t dressed up your code snippets yet, now is a good time. Feel free to take the background images of my samples as well. If you have any questions or know of any other techniques, please share them!
(Continue)..

(Continue)..

“Active” State in CSS Navigations


Tags: ,
I am sure you have been on a website where the navigation has an “active” state, basically showing you which page you are currently on. Take a look at my top navigation, you should see that the “Blog” link is in its active state. This technique is what you will be learning today.
Take a look at the demo below to get a preview of what you will be creating. Also if you would like to download the PSD that we will be working with, go right ahead.
Active Navigation with CSS

Foundation – HTML

Start by creating your navigation with an unordered list. Be sure to assign a unique class name to each of the list items.
<ul id="topnav">
 <li class="home"><a href="index.htm">Home</a></li>
 <li class="about"><a href="about.htm">About Us</a></li>
 <li class="services"><a href="services.htm">Services</a></li>
 <li class="portfolio"><a href="portfolio.htm">Portfolio</a></li>
 <li class="contact"><a href="contact.htm">Contact</a></li>
 <li class="blog"><a href="blog.htm">Blog</a></li>
</ul>

Styling – CSS

Strip down the unordered list to bare bones. This will prepare us for the text replacement technique for each of our navigation links.
ul#topnav {
 margin: 0; padding: 0;
 list-style: none;
 float: left;
 width: 960px;
}
ul#topnav li {
 float: left;
 margin: 0; padding: 0;
}
We will be using CSS Sprites, this will basically allow us to have three states (Default, Hover, & Active) for each navigation link.
Active Navigation with CSS
/*--CSS Sprites - Default State--*/
ul#topnav a {
 float: left;
 display: block;
 height: 58px; /*--Specify height of navigation--*/
 text-indent: -99999px; /*--Shoot the text off the page--*/
 background-position: left top;
}
/*--CSS Sprites - Hover State--*/
ul#topnav a:hover {
 background-position: left -58px;
}
/*--Assign an image and width to each link--*/
ul#topnav li.home a {
 background-image: url(home_a.jpg);
 width: 120px;
}
ul#topnav li.about a {
 background-image: url(about_a.jpg);
 width: 147px;
}
ul#topnav li.services a {
 background-image: url(services_a.jpg);
 width: 157px;
}
ul#topnav li.portfolio a {
 background-image: url(portfolio_a.jpg);
 width: 182px;
}
ul#topnav li.contact a {
 background-image: url(contact_a.jpg);
 width: 179px;
}
ul#topnav li.blog a {
 background-image: url(blog_a.jpg);
 width: 175px;
}

Setting the “Active” State

We will be adding this “active” state by assigning an ID to the <body> tag on each of our pages. By assigning an ID to each page, we can now specify different properties and values depending on which page it’s on.
So for example, the homepage file should have the <body> tag set like this:
Home Page HTML
...
<body id="home">
...
and the About Us page like:
About Page HTML
...
<body id="about">
...
and so on. Each page should now have its own unique ID on the <body> tag.
Using CSS Specificity to override the default and hover states, we associate each body ID with its matching list item class to set the active state.
The Logic in Plain English
If it’s on the “home” page (body id=”home”) , set the “home” link (li class=”home”) to “active” (background-position: left bottom;).
Now we will apply this logic to cater for all of the pages.
CSS
#home li.home a, /*--Home Page > Home Link--*/
#about li.about a, /*--About Page > About Link--*/
#services li.services a, /*--Services Page > Services Link--*/
#portfolio li.portfolio a, /*--Portfolio Page > Portfolio Link--*/
#contact li.contact a, /*--Contact Page > Contact Link--*/
#blog li.blog a /*--Blog Page > Blog Link--*/
{
 background-position: left bottom;
}
Below is a visual demonstration of how all of this is working together.
Active Navigation with CSS

Conclusion

If anyone has any questions, concerns, or comments please feel free to let me know!
(Continue)..

(Continue)..

Styling Post Headings That Stick Out

 

Tags:
Recently, I’ve noticed a trend in blog post headings where it sticks out of its base layout. I would like to share this technique for those who would like to give their post headings a new style. One tip to keep in mind when designing this is to make sure it fits your target audience screen resolution size.
Note that this technique may vary depending on your design. My goal is for you to grasp the main concept in this tutorial so you can experiment and apply it to your own projects.
Post Heading That Sticks Out

Step 1. Wireframe – HTML

Start by visualizing the wireframe of how each post item will be laid out.
<div class="post">
 <div class="postheader">
  <!--Post Header Elements Goes Here-->
 </div>
 <!--Post Content Goes Here-->
</div>

Step 2. Styling Wireframe – CSS

Each post entry will be wrapped within the .post class. Since we are using absolute positioning on the .postheader, be sure to add enough top padding on .post so the post content does not overlap with the heading.
Post Heading That Sticks Out
.post {
 margin: 0; padding: 110px 20px 20px;
 float: left;
 width: 560px;
 position: relative;
}
.post .postheader {
 background: url(postheader_bg.gif) repeat-x;
 float: left;
 width: 600px;
 position: absolute;
 left: 0; top: 0;
}

Step 3. Post Header Wireframe – HTML

Now we’ll look closer at how each element will be placed within the .postheader.
Post Heading That Sticks Out

<div class="postheader">
 <span class="date"><strong>Oct</strong>25 <small>2009</small></span>
 <h2><a href="#">Styling Blog Post Headers with CSS</a></h2>
 <a href="#" class="comments">25</a>
 <p>
  <span>Category: <a href="#">CSS</a> | Tags: <a href="#">Headings</a>, <a href="#">Tutorials</a></span>
  By <a href="#">Soh Tanaka</a>
 </p>
</div>

Step 4. Styling Post Header – CSS

Date Style
The part that sticks out of the layout is the date. Set the positioning to absolute and pull it back -50px to the left.
Post Heading That Sticks Out

.date {
 background: url(date_bg.gif) no-repeat;
 width: 46px; height: 57px;
 float: left;
 padding: 3px 5px 3px 0;
 text-align: center;
 font-size: 1.8em;
 position: absolute;
 left: -50px; top: 0;
}
.date strong, .date small {
 font-size: 0.5em;
 text-transform: uppercase;
 display: block;
}
Comments Style
Similar to how we styled the date, we will use absolute positioning to push the comments block -10px to the top and -10px to the right.
Post Heading That Sticks Out

a.comments {
 position: absolute;
 right: -10px; top: -10px;
 background: url(comment_bubble.gif) no-repeat;
 width: 34px; height: 39px;
 padding: 7px 0 0;
 text-align: center;
 color: #fff;
 font-size: 1.6em;
 text-decoration: none;
}
Level 2 Heading Style
Since the comments area is bleeding over on top of the heading, make sure you have enough padding on the right side so it does not overlap. Set height and line-height to match so it can be vertically aligned. For those browsers that support text shadows, we can add a nice touch of letter press style using the text-shadow property.
.post .postheader h2 {
 margin: 0; padding: 0 25px 0 10px;
 font: normal 2.2em Georgia, "Times New Roman", Times, serif;
 height: 62px; line-height: 62px;
 text-shadow: 1px 1px 1px #cfeb7f;
}
.post .postheader h2 a {
 text-decoration: none;
 color: #222;
 display: block;
}
Auxiliary Information Style
The aux information will be wrapped in a paragraph tag. To accommodate for the background image, be sure to add 60px padding to the left. For the category and tag information, wrap it in a span which will be floated to the right.
.post .postheader p{
 font-size: 0.9em;
 background: url(author_bg.gif) no-repeat 10px bottom;
 height: 27px; line-height: 27px;
 margin: 0; padding: 0 10px 0 60px;
 color: #fff;
}
.postheader p a {color: #fff;}
.postheader p span {float: right;}
Post Heading That Sticks Out
(Continue)..

(Continue)..

Horizontal Subnav with CSS

Tags: ,
Not too long ago I wrote a tutorial on how to create a drop down menu with CSS & jQuery, today I would like to go over how to create a simple navigation with a horizontal subnav.
In most cases we can achieve this effect purely with CSS, but since we have to attend to our red headed step child aka IE6, we will use a few lines of jQuery to cover all grounds.
Horizontal Subnavigation - CSS jQuery Tutorial

Wireframe – HTML

Nest a set of links wrapped within the <span> tag, this is how the sub navigation will be positioned.
<ul id="topnav">
    <li><a href="#">Link</a></li>
    <li>
        <a href="#">Link</a>
        <!--Subnav Starts Here-->
        <span>
            <a href="#">Subnav Link</a> |
            <a href="#">Subnav Link</a> |
            <a href="#">Subnav Link</a>
        </span>
        <!--Subnav Ends Here-->
    </li>
    <li><a href="#">Link</a></li>
</ul>

Styling – CSS


Horizontal Subnavigation - CSS jQuery Tutorial
Unlike a regular drop down menu where the subnav appears directly underneath the hovered/clicked list item, in this case all the subnav sets will start at the same location (left aligned – underneath the navigation).
ul#topnav {
 margin: 0; padding: 0;
 float: left;
 width: 970px;
 list-style: none;
 position: relative; /*--Set relative positioning on the unordered list itself - not on the list item--*/
 font-size: 1.2em;
 background: url(topnav_stretch.gif) repeat-x;
}
ul#topnav li {
 float: left;
 margin: 0; padding: 0;
 border-right: 1px solid #555; /*--Divider for each parent level links--*/
}
ul#topnav li a {
 padding: 10px 15px;
 display: block;
 color: #f0f0f0;
 text-decoration: none;
}
ul#topnav li:hover { background: #1376c9 url(topnav_active.gif) repeat-x; }
/*--Notice the hover color is on the list item itself, not on the link. This is so it can stay highlighted even when hovering over the subnav--*/
Now set the absolute positioning on the <span> tag 35px from the top. I added some rounded corners on the bottom for style (this will not work in IE).
ul#topnav li span {
 float: left;
 padding: 15px 0;
 position: absolute;
 left: 0; top:35px;
 display: none; /*--Hide by default--*/
 width: 970px;
 background: #1376c9;
 color: #fff;
 /*--Bottom right rounded corner--*/
 -moz-border-radius-bottomright: 5px;
 -khtml-border-radius-bottomright: 5px;
 -webkit-border-bottom-right-radius: 5px;
 /*--Bottom left rounded corner--*/
 -moz-border-radius-bottomleft: 5px;
 -khtml-border-radius-bottomleft: 5px;
 -webkit-border-bottom-left-radius: 5px;
}
ul#topnav li:hover span { display: block; } /*--Show subnav on hover--*/
ul#topnav li span a { display: inline; } /*--Since we declared a link style on the parent list link, we will correct it back to its original state--*/
ul#topnav li span a:hover {text-decoration: underline;}
For those who are not very familiar with how positioning works, check out the following tutorials:

IE6 Fix – jQuery

Since IE6 does not understand li:hover (basically it only understands a hover event on a <a> tag), use jQuery to go around the issue.
For those who are not familiar with jQuery, do check out their site first and get an overview of how it works. I’ve shared a few tricks that I have picked up along the way, you can check those out as well.
Initial Step – Call the jQuery file
You can choose to download the file from the jQuery site, or you can use this one hosted on Google.
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
The following script contains comments explaining which jQuery actions are being performed.
<script type="text/javascript">
$(document).ready(function() {

 $("ul#topnav li").hover(function() { //Hover over event on list item
  $(this).css({ 'background' : '#1376c9 url(topnav_active.gif) repeat-x'}); //Add background color and image on hovered list item
  $(this).find("span").show(); //Show the subnav
 } , function() { //on hover out...
  $(this).css({ 'background' : 'none'}); //Ditch the background
  $(this).find("span").hide(); //Hide the subnav
 });

});
</script>
Horizontal Subnavigation - CSS jQuery Tutorial
(Continue)..

(Continue)..

Popout Details on Hover w/ CSS

I recently saw a hover over trick that caught my eye and I thought it was a pretty clever way of showing more details on an element. I decided to give it a try and the solution was quite simple.

Popout Details on Hover w/ CSS

HTML

The columns are made up of unordered list items, within each list item is the thumbnail image and the details of the item wrapped in a class of "info".
<ul class="columns">
    <li>
     <a href="#"><img src="thumbnail.jpg" alt="" /></a>
        <div class="info">
            <h2>Title</h2>
            <p>Short Description</p>
        </div>
    </li>
</ul>
Popout Details on Hover w/ CSS

CSS

Start by styling the list items. Notice we add position: relative; to the list item, and on hover we raise the z-index to 99 so it lifts over the other elements.
/*--Column Styles--*/
ul.columns {
 width: 960px;
 list-style: none;
 margin: 0 auto; padding: 0;
}
ul.columns li {
 width: 220px;
 float: left; display: inline;
 margin: 10px; padding: 0;
 position: relative;
}
ul.columns li:hover {z-index: 99;}
We add a position: relative; to the image as well, so we can control the z-index value on hover. What we want to do here is to lower the opacity of the image by default to 30% then on hover, turn up the opacity to 100% and lift the image by increasing the z-index value to 999. This will allow the thumbnail to sit on top of the .info elements.
/*--Thumbnail Styles--*/
ul.columns li img {
 position: relative;
 filter: alpha(opacity=30);
 opacity: 0.3;
 -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"; /*--IE8 Specific--*/
}
ul.columns li:hover img{
 z-index: 999;
 filter: alpha(opacity=100);
 opacity: 1;
 -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
}
Use absolute positioning to shift the .info class -10px to the left and -10px to the top. Since .info is using an absolute positioning, we must have enough top padding so the content within does not overlap the thumbnail. To do this, the top padding is measured by adding 10px to the height of the thumbnail (200px in my demo). Some CSS3 was added for the rounded corners. We will hide .info by default, and show it on hover.
Popout Details on Hover w/ CSS
/*--Details Style--*/
ul.columns li .info {
 position: absolute;
 left: -10px; top: -10px;
 padding: 210px 10px 20px;
 width: 220px;
 display: none;
 background: #fff;
 font-size: 1.2em;
 -webkit-border-radius: 3px;
 -moz-border-radius: 3px;
 border-radius: 3px;
}
ul.columns li:hover .info {display: block;}

ul.columns li h2 {
 font-size: 1.2em;
 font-weight: normal;
 text-transform: uppercase;
 margin: 0; padding: 10px 0;
}
ul.columns li p {padding: 0; margin: 0; font-size: 0.9em;}

Final Thoughts

Go ahead and experiment with this technique! If you have any questions or concerns please don’t hesitate to let me know. For those concerned with this technique working on IE6, you can use some jQuery tricks to get around the hover issue.
Popout Details on Hover w/ CSS
(Continue)..

(Continue)..

Create an Image Rotator with Description (CSS/jQuery)

By: Soh Tanaka | May 4th, 2009 | An image rotator is one great way to display portfolio pieces, eCommerce product images, or even as an image gallery. Although there are many great plugins already, this tutorial will help you understand how the image rotator works and helps you create your own from scratch.

Creating an Image Rotator

View Demo of Image Rotator
Image Rotator - CSS jQuery

Step1. HTML – Image Rotator Wireframe

Start by building the html wireframe of the layout. As you can see in the image below, there will be two major sections (the main image section and the thumbnail list section). In addition to the sections for images, the third section, labeled “desc”, will contain the main_image description.
Image Rotator - CSS jQuery
main_image Section HTML
<div class="main_image">
    <img src="banner1.jpg" alt="" />
    <div class="desc">
        <a href="#" class="collapse">Close Me!</a>
        <div class="block">
            <h2>Title</h2>
            <small>Date</small>
            <p>Copy</p>
        </div>
    </div>
</div>
image_thumb Section HTML
Note – The thumbnail list section will be very similar in markup as the main image section, but each will all be encapsulated in its own list item.
<div class="image_thumb">
    <ul>
        <li>
            <a href="banner1.jpg"><img src="banner1_thumb.jpg" alt="Image Name" /></a>
            <div class="block">
                <h2>Title</h2>
                <small>Date</small>
                <p>Copy</p>
            </div>
        </li>
    </ul>
</div>

Step 2. CSS – Image Rotator Wireframe

Next, it’s time to style the image rotator’s HTML wireframe with CSS.
main_image section CSS
.main_image {
    width: 598px;
    height: 456px;
    float: left;
    background: #333;
    position: relative;
    overflow: hidden; /*--Overflow hidden allows the description to toggle/tuck away as it slides down--*/
    color: #fff;
}
.main_image h2 {
    font-size: 2em;
    font-weight: normal;
    margin: 0 0 5px;
    padding: 10px;
}
.main_image p {
    font-size: 1.2em;
    line-height: 1.6em;
    padding: 10px;
    margin: 0;
}
.block small { /*--We'll be using this same style on our thumbnail list--*/
    font-size: 1em;
    padding: 0 0 0 20px;
    background: url(icon_calendar.gif) no-repeat 0 center;
}
.main_image .block small {margin-left: 10px;}
.main_image .desc{
    position: absolute;
    bottom: 0;
    left: 0; /*--Stick the desc class to the bottom of our main image container--*/
    width: 100%;
    display: none; /*--Hide description by default, if js is enabled, we will show this--*/
}
.main_image .block{
    width: 100%;
    background: #111;
    border-top: 1px solid #000;
}
.main_image a.collapse { /*--This is our hide/show tab--*/
    background: url(btn_collapse.gif) no-repeat left top;
    height: 27px;
    width: 93px;
    text-indent: -99999px;
    position: absolute;
    top: -27px;
    right: 20px;
}
.main_image a.show {background-position: left bottom;}
image_thumb section CSS
.image_thumb {
    float: left;
    width: 299px;
    background: #f0f0f0;
    border-right: 1px solid #fff;
    border-top: 1px solid #ccc;
}
.image_thumb img {
    border: 1px solid #ccc;
    padding: 5px;
    background: #fff;
    float: left;
}
.image_thumb ul {
    margin: 0;
    padding: 0;
    list-style: none;
}
.image_thumb ul li{
    margin: 0;
    padding: 12px 10px;
    background: #f0f0f0 url(nav_a.gif) repeat-x;
    width: 279px;
    float: left;
    border-bottom: 1px solid #ccc;
    border-top: 1px solid #fff;
    border-right: 1px solid #ccc;
}
.image_thumb ul li.hover { /*--Hover State--*/
    background: #ddd;
    cursor: pointer;
}
.image_thumb ul li.active { /*--Active State--*/
    background: #fff;
    cursor: default;
}
html .image_thumb ul li h2 {
    font-size: 1.5em;
    margin: 5px 0;
    padding: 0;
}
.image_thumb ul li .block {
    float: left;
    margin-left: 10px;
    padding: 0;
    width: 170px;
}
.image_thumb ul li p{display: none;}/*--Hide the description on the list items--*/

Step3. jQuery – Image Rotation Effect

If you are new to jQuery or have not had much experience with it, first go over the basics.
Show Image Description and Set Transparency on Block
To degrade gracefully, the image banner description is set to be hidden at default with CSS (refer to the “.main_image .desc” class in the CSS). We will show the image description if JavaScript is enabled.
$(".main_image .desc").show(); //Show Banner
$(".main_image .block").animate({ opacity: 0.85 }, 1 ); //Set Opacity
Click and Hover Events for Image List
The following script will change the main_image when a list-item in the image_thumb is clicked. Each line also contains a comment explaining which jQuery actions are being performed.
$(".image_thumb ul li:first").addClass('active'); //Add the active class (highlights the very first list item by default)
$(".image_thumb ul li").click(function(){
    //Set Variables
    var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
    var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
    var imgDesc = $(this).find('.block').html();  //Get HTML of the "block" container
    var imgDescHeight = $(".main_image").find('.block').height(); //Find the height of the "block"

    if ($(this).is(".active")) {  //If the list item is active/selected, then...
        return false; // Don't click through - Prevents repetitive animations on active/selected list-item
    } else { //If not active then...
        //Animate the Description
        $(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() { //Pull the block down (negative bottom margin of its own height)
            $(".main_image .block").html(imgDesc).animate({ opacity: 0.85,  marginBottom: "0" }, 250 ); //swap the html of the block, then pull the block container back up and set opacity
            $(".main_image img").attr({ src: imgTitle , alt: imgAlt}); //Switch the main image (URL + alt tag)
        });
    }
    //Show active list-item
    $(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all list-items
    $(this).addClass('active');  //Add class of 'active' on the selected list
    return false;

}) .hover(function(){ //Hover effects on list-item
    $(this).addClass('hover'); //Add class "hover" on hover
    }, function() {
    $(this).removeClass('hover'); //Remove class "hover" on hover out
});
Toggle the Hide/Show Option
This is fairly simple. On each click, either show or hide the description.
$("a.collapse").click(function(){
    $(".main_banner .block").slideToggle(); //Toggle the description (slide up and down)
    $("a.collapse").toggleClass("show"); //Toggle the class name of "show" (the hide/show tab)
});
View Demo of Image Rotator
Image Rotator - CSS jQuery

Conclusion

Do keep in mind these jQuery driven image rotators do not degrade in the best fashion. As you can see, when you disable JavaScript, each thumbnail must be clicked on to get the larger image (which opens in the same window). But for those who have a user base with JavaScript enabled, you are in the clear and it can be used and customized to fit various scenarios.
Experiment and customize this to fit your needs. If you have any questions, concerns, suggestions, or comments, please do not hesitate to let me know.
Credits: Much appreciation to Glenn Jones for allowing me to use his beautiful illustrations for the example images.

About the Author:

Soh Tanaka is a Los Angeles based Web Designer and blogger, who recently launched a CSS Web Gallery called Design Bombs. For more front-end web development tutorials, check out his web design blog or you can follow him on twitter @SohTanaka
(Continue)..

(Continue)..

Simple Tabs w/ CSS & jQuery

I know there are quite a few tutorials out there that demonstrate how to create tabs with CSS & jQuery, but I decided to create my own as well. I’m not sure if the techniques are the same, but hopefully this tutorial will be easy to understand even for a beginner.
For those who are not familiar with jQuery, check out their site for a general overview, and you can also follow up with the various tutorials out there.

Easy Tabs Tutorial with CSS & jQuery

Step1. Wireframe – HTML & CSS

Use an unordered list for your tabs, and follow up with the “tab_container” container right below it. Make note that each list item (tabs) has an attribute of “href” that matches the ID of the “.tab_content” div. This will be very important once we have jQuery pull off the actions. Also keep in mind that I used generic names like “tab1″ so its easier to understand. In reality, you should be using keywords so it can semantic and also benefit you in SEO.
HTML
<ul class="tabs">
    <li><a href="#tab1">Gallery</a></li>
    <li><a href="#tab2">Submit</a></li>
</ul>

<div class="tab_container">
    <div id="tab1" class="tab_content">
        <!--Content-->
    </div>
    <div id="tab2" class="tab_content">
       <!--Content-->
    </div>
</div>
If you have tried to create tabs before with CSS, you probably have experienced some frustration with getting the borders on the tabs correctly aligned. Below is a common problem that most people will run into.
Easy Tabs Tutorial with CSS & jQuery
Here is a solution I came up with that took care of this annoying issue. Check out the image below and also take a look at the CSS and its supporting comments for a better understanding.
Easy Tabs Tutorial with CSS & jQuery
Tabs CSS
ul.tabs {
 margin: 0;
 padding: 0;
 float: left;
 list-style: none;
 height: 32px; /*--Set height of tabs--*/
 border-bottom: 1px solid #999;
 border-left: 1px solid #999;
 width: 100%;
}
ul.tabs li {
 float: left;
 margin: 0;
 padding: 0;
 height: 31px; /*--Subtract 1px from the height of the unordered list--*/
 line-height: 31px; /*--Vertically aligns the text within the tab--*/
 border: 1px solid #999;
 border-left: none;
 margin-bottom: -1px; /*--Pull the list item down 1px--*/
 overflow: hidden;
 position: relative;
 background: #e0e0e0;
}
ul.tabs li a {
 text-decoration: none;
 color: #000;
 display: block;
 font-size: 1.2em;
 padding: 0 20px;
 border: 1px solid #fff; /*--Gives the bevel look with a 1px white border inside the list item--*/
 outline: none;
}
ul.tabs li a:hover {
 background: #ccc;
}
html ul.tabs li.active, html ul.tabs li.active a:hover  { /*--Makes sure that the active tab does not listen to the hover properties--*/
 background: #fff;
 border-bottom: 1px solid #fff; /*--Makes the active tab look like it's connected with its content--*/
}
Tab Content CSS
.tab_container {
 border: 1px solid #999;
 border-top: none;
 overflow: hidden;
 clear: both;
 float: left; width: 100%;
 background: #fff;
}
.tab_content {
 padding: 20px;
 font-size: 1.2em;
}

Step 2. Activate the Tabs – jQuery

For those who are not familiar with jQuery, check out their site for a general overview.
The following script contains comments explaining which jQuery actions are being performed.
$(document).ready(function() {

 //When page loads...
 $(".tab_content").hide(); //Hide all content
 $("ul.tabs li:first").addClass("active").show(); //Activate first tab
 $(".tab_content:first").show(); //Show first tab content

 //On Click Event
 $("ul.tabs li").click(function() {

  $("ul.tabs li").removeClass("active"); //Remove any "active" class
  $(this).addClass("active"); //Add "active" class to selected tab
  $(".tab_content").hide(); //Hide all tab content

  var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
  $(activeTab).fadeIn(); //Fade in the active ID content
  return false;
 });

});
Easy Tabs Tutorial with CSS & jQuery
(Continue)..

(Continue)..