Thứ Ba, 22 tháng 3, 2011

Sticky SideNav Layout with CSS

Sticky SideNav Layout with CSS

Tags: ,
I recently wrote an article for DesignM.ag on how to create a fixed navigation layout with CSS. You can check out the article here!
Today I would like to go over how to create a fixed sidenav layout for your blog or website.
Having a fixed sidenav comes in handy when dealing with blog style websites where the content is extremely tall and there is a need for good amount of scrolling. The fixed navigation allows the user to cruise through the content without scrolling back up to the top to navigate through the rest of the site…Read More
Fixed Navigation with CSS

Related Posts

Guest Post – Creating an Image Rotator

Guest Post – Creating an Image Rotator

Tags: , ,
This is my second article over at designm.ag. 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…

Related Posts

Simple Page Peel Effect with jQuery & CSS

Simple Page Peel Effect with jQuery & CSS

Tags: ,
You have probably seen these forms of advertisings where you can peel a corner of a website and see a message underneath. It seems most are flash driven, but I decided to try it out using some simple lines of jQuery.
Page Peel Effect with jQuery and CSS

1. HTML – Page Peel Wireframe

The “pageflip” div will act as the container, mainly used to establish the relative positioning. Then nest the image and the span class of “msg_block” wrapped in an <a> tag. Note – If you don’t have any conflicting absolute/relative positioning properties, you technically don’t need the “pageflip” container at all.
<div id="pageflip">
 <a href="#">
  <img src="page_flip.png" alt="" />
  <span class="msg_block">Subscribe via RSS</span>
 </a>
</div>

2. CSS – Page Peel Styles

Set the image property to a smaller size (50px by 50px) by default and set the absolute positioning to be in the top right corner. The image will be used similar to the “masking” technique in Photoshop or Flash, where it will be placed on top of the hidden message, so only a portion of the message will be shown. Check out the image below for a visual:
Page Peel Effect with jQuery and CSS
The actual message behind the “peeling” effect, is all within the “msg_block” class. By default, it will start at 50px by 50px, positioned on the top right corner of the page. The text-indent will shoot the text off of the page for anyone with CSS enabled.
#pageflip {
 position: relative;
}
#pageflip img {
 width: 50px; height: 52px;
 z-index: 99;
 position: absolute;
 right: 0; top: 0;
 -ms-interpolation-mode: bicubic;
}
#pageflip .msg_block {
 width: 50px; height: 50px;
 position: absolute;
 z-index: 50;
 right: 0; top: 0;
 background: url(subscribe.png) no-repeat right top;
 text-indent: -9999px;
}
Note that the “msg_block” height is off by 2px compared to the image property – this is taking in consideration of the drop shadow that the image has.

3. jQuery – Animating Page Peel

All we are doing here is expanding the image and msg_block on hover, then retracting to its default size on hover out.
$("#pageflip").hover(function() { //On hover...
 $("#pageflip img , .msg_block").stop()
  .animate({ //Animate and expand the image and the msg_block (Width + height)
   width: '307px',
   height: '319px'
  }, 500);
 } , function() {
 $("#pageflip img").stop() //On hover out, go back to original size 50x52
  .animate({
   width: '50px',
   height: '52px'
  }, 220);
 $(".msg_block").stop() //On hover out, go back to original size 50x50
  .animate({
   width: '50px',
   height: '50px'
  }, 200); //Note this one retracts a bit faster (to prevent glitching in IE)
});

Conclusion

The concept is very simple and may come in handy one day. If you have any questions or know of other techniques, please don’t hesitate to let me know~
Page Peel Effect with jQuery and CSS

Related Posts

Facebook Style Footer Admin Panel Part 1

Facebook Style Footer Admin Panel Part 1

Tags: ,
The popularity of social media has been booming in the past few years and Facebook definitely has climbed high to the top of the social network rankings. Facebook has many Ajax driven features and applications that are very impressive, and one of the things I particularly like is the footer admin panel, where it neatly organizes frequently used links and applications.
This week I would like to cover part 1 of how to recreate the Facebook footer admin panel with CSS and jQuery.
Final Demo

Step 1. Wireframe and Tooltip Bubbles – HTML & CSS

Lay out the wireframe of the admin panel using an unordered list for the foundation. The last two list items (Alert Panel & Chat Panel) will have sub-panels nested within them. Since these two panels will float to the right, the order in the markup will be reversed.
Tooltip foundation
Notice that there is a <small> tag nested within the <a> tag, this is how we will achieve our tooltip bubble on the navigation.

HTML

<div id="footpanel">
    <ul id="mainpanel">
        <li><a href="#" class="home">Inspiration <small>Design Bombs</small></a></li>
        <li><a href="#" class="profile">View Profile <small>View Profile</small></a></li>
        <li><a href="#" class="editprofile">Edit Profile <small>Edit Profile</small></a></li>
        <li><a href="#" class="contacts">Contacts <small>Contacts</small></a></li>
        <li><a href="#" class="messages">Messages (10) <small>Messages</small></a></li>
        <li><a href="#" class="playlist">Play List <small>Play List</small></a></li>
        <li><a href="#" class="videos">Videos <small>Videos</small></a></li>
        <li id="alertpanel"><a href="#" class="alerts">Alerts</a></li>
        <li id="chatpanel"><a href="#" class="chat">Friends (<strong>18</strong>)</a></li>
    </ul>
</div>

CSS

First start by fixing the panel to the bottom of the viewport.
#footpanel {
 position: fixed;
 bottom: 0; left: 0;
 z-index: 9999; /*--Keeps the panel on top of all other elements--*/
 background: #e3e2e2;
 border: 1px solid #c3c3c3;
 border-bottom: none;
 width: 94%;
 margin: 0 3%;
}
As you may already know, IE6 does not understand fixed positioning. I stumbled across a tutorial that fixed this problem*.
*html #footpanel { /*--IE6 Hack - Fixed Positioning to the Bottom--*/
 margin-top: -1px; /*--Prevents IE6 from having an infinity scroll bar - due to 1px border on #footpanel--*/
 position: absolute;
 top:expression(eval(document.compatMode &&document.compatMode=='CSS1Compat') ?documentElement.scrollTop+(documentElement.clientHeight-this.clientHeight) : document.body.scrollTop +(document.body.clientHeight-this.clientHeight));
}
*Note: Due to heavy loading on the browser, an alternative solution would be to either use an position: absolute; or if the situation/client allows it use display: none; for those with IE6.
Style the unordered list which will be the foundation of this panel.
#footpanel ul {
 padding: 0; margin: 0;
 float: left;
 width: 100%;
 list-style: none;
 border-top: 1px solid #fff; /*--Gives the bevel feel on the panel--*/
 font-size: 1.1em;
}
#footpanel ul li{
 padding: 0; margin: 0;
 float: left;
 position: relative;
}
#footpanel ul li a{
 padding: 5px;
 float: left;
 text-indent: -9999px; /*--For text replacement - Shove text off of the page--*/
 height: 16px; width: 16px;
 text-decoration: none;
 color: #333;
 position: relative;
}
html #footpanel ul li a:hover{ background-color: #fff; }
html #footpanel ul li a.active { /*--Active state when sub-panel is open--*/
 background-color: #fff;
 height: 17px;
 margin-top: -2px; /*--Push it up 2px to attach the active button to sub-panel--*/
 border: 1px solid #555;
 border-top: none;
 z-index: 200; /*--Keeps the active link on top of the sub-panel--*/
 position: relative;
}
Tooltip Demo
Declare the text replacement for each link.
You can download these great icons by Pinvoke here.
#footpanel a.home{
 background: url(home.png) no-repeat 15px center;
 width: 50px;
 padding-left: 40px;
 border-right: 1px solid #bbb;
 text-indent: 0; /*--Reset text indent since there will be a combination of both text and image--*/
}
a.profile{ background: url(user.png) no-repeat center center;  }
a.editprofile{ background: url(wrench_screwdriver.png) no-repeat center center; }
a.contacts{ background: url(address_book.png) no-repeat center center; }
a.messages{ background: url(mail.png) no-repeat center center; }
a.playlist{ background: url(document_music_playlist.png) no-repeat center center; }
a.videos{ background: url(film.png) no-repeat center center; }
a.alerts{ background: url(newspaper.png) no-repeat center center; }
#footpanel a.chat{
 background: url(balloon.png) no-repeat 15px center;
 width: 126px;
 border-left: 1px solid #bbb;
 border-right: 1px solid #bbb;
 padding-left: 40px;
 text-indent: 0; /*--Reset text indent since there will be a combination of both text and image--*/
}
#footpanel li#chatpanel, #footpanel li#alertpanel { float: right; }  /*--Right align the chat and alert panels--*/
Tooltip Demo
Style the tooltip bubble, by default the <small> tag will be hidden with a display:none;. On hover over, allow the tooltip to appear with a display:block;
#footpanel a small {
 text-align: center;
 width: 70px;
 background: url(pop_arrow.gif) no-repeat center bottom;
 padding: 5px 5px 11px;
 display: none; /*--Hide by default--*/
 color: #fff;
 font-size: 1em;
 text-indent: 0;
}
#footpanel a:hover small{
 display: block; /*--Show on hover--*/
 position: absolute;
 top: -35px; /*--Position tooltip 35px above the list item--*/
 left: 50%;
 margin-left: -40px; /*--Center the tooltip--*/
 z-index: 9999;
}

What’s Next?

Part 2 of this tutorial will go over how to style the sub-panels and how to activate them using jQuery. If anyone had any questions or comments regarding the tooltip technique, please let me know!

Related Posts

Facebook Style Footer Admin Panel Part 2

Facebook Style Footer Admin Panel Part 2

Tags: ,
This is Part 2 of the Facebook Style Footer Admin Panel, if you haven’t checked out Part 1 this is the perfect time to check it out.

Step 2. Styling the Chat Panel & Alert Panel – HTML & CSS

Just like developing a drop-down menu, have a nested sub-panel within the list item. Look at the image below to get an overview of how this is layed out.
Collapsible Subpanel Demo
HTML
<li id="alertpanel">
    <a href="#" class="alerts">Alerts</a>
    <div class="subpanel">
        <h3><span> &ndash; </span>Notifications</h3>
        <ul>
            <li class="view"><a href="#">View All</a></li>
            <li>
                <a href="#" class="delete">X</a>
                <p><!--Content--></p>
            </li>
            <li>
                <a href="#" class="delete">X</a>
                <p><!--Content--></p>
            </li>
        </ul>
    </div>
</li>
<li id="chatpanel">
    <a href="#" class="chat">Friends (<strong>18</strong>) </a>
    <div class="subpanel">
        <h3><span> &ndash; </span>Friends Online</h3>
        <ul>
            <li><span>Family Members</span></li>
            <li><a href="#"><img src="chat-thumb.gif" alt="" /> Your Friend</a></li>
            <li><a href="#"><img src="chat-thumb.gif" alt="" /> Your Friend</a></li>
        </ul>
    </div>
</li>
CSS
Since we declared a list item link style already (with the text replament technique), override the properties so we can use regular links in the sub-panels.
#footpanel ul li div a { /*--Reset link style for sub-panel links--*/
 text-indent: 0;
 width: auto;
 height: auto;
 padding: 0;
 float: none;
 color: #00629a;
 position: static;
}
#footpanel ul li div a:hover { text-decoration: underline; } /*--Reset hover style for sub-panel links--*/
Style the sub-panel container with an absolute positioning that will sit at the top of the main footer panel (27px from the bottom of the footer panel). Then create the headings using an <h3>.
#footpanel .subpanel {
 position: absolute;
 left: 0; bottom: 27px;
 display: none; /*--Hide by default--*/
 width: 198px;
 border: 1px solid #555;
 background: #fff;
 overflow: hidden;
}
#footpanel h3 {
 background: #526ea6;
 padding: 5px 10px;
 color: #fff;
 font-size: 1.1em;
 cursor: pointer;
}
#footpanel h3 span { /*--Right aligned "-" icon--*/
 font-size: 1.5em;
 float: right;
 line-height: 0.6em;
 font-weight: normal;
}
The following section is the area that will be scrollable. Use an overflow: auto; to allow the scroll to appear when the content exceeeds the <ul> height.
#footpanel .subpanel ul{
 padding: 0; margin: 0;
 background: #fff;
 width: 100%;
 overflow: auto;
 padding-bottom: 2px;
}
#footpanel .subpanel li{
 float: none; /*--Reset float--*/
 display: block;
 padding: 0; margin: 0;
 overflow: hidden;
 clear: both;
 background: #fff;
 position: static;  /*--Reset relative positioning--*/
 font-size: 0.9em;
}

Chat Panel

Chat Panel Details
#chatpanel .subpanel li { background: url(dash.gif) repeat-x left center; }
#chatpanel .subpanel li span {
 padding: 5px;
 background: #fff;
 color: #777;
 float: left;
}
#chatpanel .subpanel li a img {
 float: left;
 margin: 0 5px;
}
#chatpanel .subpanel li a{
 padding: 3px 0; margin: 0;
 line-height: 22px;
 height: 22px;
 background: #fff;
 display: block;
}
#chatpanel .subpanel li a:hover {
 background: #3b5998;
 color: #fff;
 text-decoration: none;
}

Alert Panel

Alert Panel Details
#alertpanel .subpanel { right: 0; left: auto; /*--Reset left positioning and make it right positioned--*/ }
#alertpanel .subpanel li {
 border-top: 1px solid #f0f0f0;
 display: block;
}
#alertpanel .subpanel li p {padding: 5px 10px;}
#alertpanel .subpanel li a.delete{
 background: url(delete_x.gif) no-repeat;
 float: right;
 width: 13px; height: 14px;
 margin: 5px;
 text-indent: -9999px;
 visibility: hidden; /*--Hides by default but still takes up space (not completely gone like display:none;)--*/
}
#alertpanel .subpanel li a.delete:hover { background-position: left bottom; }
#footpanel #alertpanel li.view {
 text-align: right;
 padding: 5px 10px 5px 0;
}

Step 3. Activating the Subpanel – jQuery

Adjust the Subpanel Height
The tricky part about the collapsible sub-panel is to make sure the content does not stretch beyond the height of the viewport when active.
Adjust Panel height
To make sure the height does not exceed past the viewport, use the following function to calculate and resize the sub-panel according to the viewport size.
Adjust Panel height
The following script contains comments explaining which jQuery actions are being performed.

jQuery

//Adjust panel height
$.fn.adjustPanel = function(){
    $(this).find("ul, .subpanel").css({ 'height' : 'auto'}); //Reset sub-panel and ul height

    var windowHeight = $(window).height(); //Get the height of the browser viewport
    var panelsub = $(this).find(".subpanel").height(); //Get the height of sub-panel
    var panelAdjust = windowHeight - 100; //Viewport height - 100px (Sets max height of sub-panel)
    var ulAdjust =  panelAdjust - 25; //Calculate ul size after adjusting sub-panel

    if ( panelsub > panelAdjust ) {  //If sub-panel is taller than max height...
        $(this).find(".subpanel").css({ 'height' : panelAdjust }); //Adjust sub-panel to max height
        $(this).find("ul").css({ 'height' : panelAdjust}); ////Adjust subpanel ul to new size
    }
    else if { //If sub-panel is smaller than max height...
        $(this).find("ul").css({ 'height' : 'auto'}); //Set sub-panel ul to auto (default size)
    }
};

//Execute function on load
$("#chatpanel").adjustPanel(); //Run the adjustPanel function on #chatpanel
$("#alertpanel").adjustPanel(); //Run the adjustPanel function on #alertpanel

//Each time the viewport is adjusted/resized, execute the function
$(window).resize(function () {
    $("#chatpanel").adjustPanel();
    $("#alertpanel").adjustPanel();
});

Add the Toggle Function

Since both of the chat and alert panels are collapsible, we must treat this like the logic of an accordion (when one opens, the other closes). We also need to allow the panels to collapse when clicking out of the sub-panels.
The following script contains comments explaining which jQuery actions are being performed.
//Click event on Chat Panel and Alert Panel 
$("#chatpanel a:first, #alertpanel a:first").click(function() { //If clicked on the first link of #chatpanel and #alertpanel...
    if($(this).next(".subpanel").is(':visible')){ //If subpanel is already active...
        $(this).next(".subpanel").hide(); //Hide active subpanel
        $("#footpanel li a").removeClass('active'); //Remove active class on the subpanel trigger
    }
    else { //if subpanel is not active...
        $(".subpanel").hide(); //Hide all subpanels
        $(this).next(".subpanel").toggle(); //Toggle the subpanel to make active
        $("#footpanel li a").removeClass('active'); //Remove active class on all subpanel trigger
        $(this).toggleClass('active'); //Toggle the active class on the subpanel trigger
    }
    return false; //Prevent browser jump to link anchor
});

//Click event outside of subpanel
$(document).click(function() { //Click anywhere and...
    $(".subpanel").hide(); //hide subpanel
    $("#footpanel li a").removeClass('active'); //remove active class on subpanel trigger
});
$('.subpanel ul').click(function(e) {
    e.stopPropagation(); //Prevents the subpanel ul from closing on click
});

//Show/Hide delete icons on Alert Panel
$("#alertpanel li").hover(function() {
    $(this).find("a.delete").css({'visibility': 'visible'}); //Show delete icon on hover
},function() {
    $(this).find("a.delete").css({'visibility': 'hidden'}); //Hide delete icon on hover out
});
Final Demo

Conclusion

The footer panel can be useful for admin driven applications and much more. There are many useful techniques that we covered today like the fixed footer, CSS tooltips, height calculation function, and multiple toggle function, that can be used in various ways for your future projects.
If you have any questions, concerns, or suggestions, please do not hesitate to let me know!

Automatic Image Slider w/ CSS & jQuery

Automatic Image Slider w/ CSS & jQuery

Tags: ,
With the release of the iPad and its lack of support for flash, it has stirred up a lot of debates regarding the future of flash. With this in mind, I believe it is wise to build simple widgets like the image slider using HTML/CSS/Javascript, and leave more interactive applications for flash if needed. The html based image slider will have its benefits with SEO and will also degrade gracefully for those w/out js.
Automatic Image Slider CSS jQuery

The Wireframe – HTML

Start with having a wrapping container div called main_view, and two sections nested inside called image_reel and paging. The image_reel will contain the sliding images, and paging contains the paging controls. Take a look at the image below for a visual.
Automatic Image Slider CSS jQuery
<div class="main_view">
    <div class="window">
        <div class="image_reel">
            <a href="#"><img src="reel_1.jpg" alt="" /></a>
            <a href="#"><img src="reel_2.jpg" alt="" /></a>
            <a href="#"><img src="reel_3.jpg" alt="" /></a>
            <a href="#"><img src="reel_4.jpg" alt="" /></a>
        </div>
    </div>
    <div class="paging">
        <a href="#" rel="1">1</a>
        <a href="#" rel="2">2</a>
        <a href="#" rel="3">3</a>
        <a href="#" rel="4">4</a>
    </div>
</div>

Styling – CSS

Take a look at the comments below for an explanation of the styles.
/*--Main Container--*/
.main_view {
 float: left;
 position: relative;
}
/*--Window/Masking Styles--*/
.window {
 height:286px; width: 790px;
 overflow: hidden; /*--Hides anything outside of the set width/height--*/
 position: relative;
}
.image_reel {
 position: absolute;
 top: 0; left: 0;
}
.image_reel img {float: left;}

/*--Paging Styles--*/
.paging {
 position: absolute;
 bottom: 40px; right: -7px;
 width: 178px; height:47px;
 z-index: 100; /*--Assures the paging stays on the top layer--*/
 text-align: center;
 line-height: 40px;
 background: url(paging_bg2.png) no-repeat;
 display: none; /*--Hidden by default, will be later shown with jQuery--*/
}
.paging a {
 padding: 5px;
 text-decoration: none;
 color: #fff;
}
.paging a.active {
 font-weight: bold;
 background: #920000;
 border: 1px solid #610000;
 -moz-border-radius: 3px;
 -khtml-border-radius: 3px;
 -webkit-border-radius: 3px;
}
.paging a:hover {font-weight: bold;}

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. Bringing it to Life – jQuery

The following script contains comments explaining which jQuery actions are being performed.
Setting up the Image Slider
Start by showing the paging and activating the first link. Then we will calculate and adjust the width of the image_reel according to how many slides there are.
//Show the paging and activate its first link
$(".paging").show();
$(".paging a:first").addClass("active");

//Get size of the image, how many images there are, then determin the size of the image reel.
var imageWidth = $(".window").width();
var imageSum = $(".image_reel img").size();
var imageReelWidth = imageWidth * imageSum;

//Adjust the image reel to its new size
$(".image_reel").css({'width' : imageReelWidth});
Setting up the Slider Function and Timer
We first create the function for the slide event by itself (rotate). Then create another function (rotateSwitch) that will rotate and repeat that slide event (rotate).
//Paging  and Slider Function
rotate = function(){
    var triggerID = $active.attr("rel") - 1; //Get number of times to slide
    var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

    $(".paging a").removeClass('active'); //Remove all active class
    $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

    //Slider Animation
    $(".image_reel").animate({
        left: -image_reelPosition
    }, 500 );

}; 

//Rotation  and Timing Event
rotateSwitch = function(){
    play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
        $active = $('.paging a.active').next(); //Move to the next paging
        if ( $active.length === 0) { //If paging reaches the end...
            $active = $('.paging a:first'); //go back to first
        }
        rotate(); //Trigger the paging and slider function
    }, 7000); //Timer speed in milliseconds (7 seconds)
};

rotateSwitch(); //Run function on launch
Take a look at this tutorial for an explanation of how the timer (setInterval) works.
Hover and Click Events
In case the user wants to view the slide for a longer period of time, we will allow the slider to stop when it is hovered. Another thing to consider is we should reset the timer each time the paging is clicked. This will prevent unexpected slide switches and allow for a smoother experience.
//On Hover
$(".image_reel a").hover(function() {
    clearInterval(play); //Stop the rotation
}, function() {
    rotateSwitch(); //Resume rotation timer
}); 

//On Click
$(".paging a").click(function() {
    $active = $(this); //Activate the clicked paging
    //Reset Timer
    clearInterval(play); //Stop the rotation
    rotate(); //Trigger rotation immediately
    rotateSwitch(); // Resume rotation timer
    return false; //Prevent browser jump to link anchor
});
Automatic Image Slider CSS jQuery

Inspiration

Below are some sites that use similar techniques, check them out for inspiration!
Automatic Image Slider CSS jQuery
Automatic Image Slider CSS jQuery
Automatic Image Slider CSS jQuery
Automatic Image Slider CSS jQuery
Automatic Image Slider CSS jQuery

Related Articles

Related Posts

Simple Tabs w/ CSS & jQuery

Simple Tabs w/ CSS & jQuery

Tags: ,
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

Conclusion

So there you have it, a nice and simple tab function with CSS and jQuery. If you have any questions, comments, or suggestions, please feel free to let me know!