Introduction
This article will show you how to create your own
tabbed content step by step. Tabs are used to improve the utilization of space
and to provide some stylish effects in a website. jQuery tabs are very popular
and create some fancy look for web pages.
Description
Tabs are generally used to break content into
multiple sections that can be swapped to save space, much like an accordion. By
default a tab widget will swap between tabbed sections onClick but the events
can be changed to onHover through an option. For my new looks I created a
container which has the ability to switch content through tabs, but with an
animation.
Step 1: First
we have to create a Web Application.
- Go to Visual Studio 2010.
- New--> And select the Web Application.
- Give whatever name you want to.
- Click OK.
Step 2: Secondly
you have to add a new page to the website.
- Go to the Solution Explorer.
- Right-click on the project name.
- Select add new item.
- Add new web page and give it a name.
- Click OK.
Step 3 : In
this step we are adding one image to the "Image" folder of the project.
Step 4 : In
this step add the tabbedContent.css file to your Styles folder.
Right-click on the sagscroller.css file->copy and
paste to the <Head> section of your page. The reference path looks like:
<link rel="stylesheet" type="text/css" href="Styles/tabbedContent.css" />
Step 5: In
this step we will see how to add style sheet code. Whenever we write style sheet
code you have to be careful that it is written inside the <style></style> tags
and you have to place it inside the head section.
<style type="text/css">
.tabbed_content
{
background-color: #663366;
width: 620px;
}
.tabs
{
height: 62px;
position: relative;
}
.tabs .moving_bg
{
background-color: #FF9933;
background-image: url(../images/arrow_down_green.gif);
background-position: bottom left;
background-repeat: no-repeat;
left: 0;
padding: 15px;
padding-bottom: 29px;
position: absolute;
width: 125px;
z-index: 190;
}
.tabs .tab_item
{
display: block;
float: left;
padding: 15px;
width: 125px;
color: #ffffff;
text-align: center;
z-index: 200;
position: relative;
cursor: pointer;
}
.tabbed_content .slide_content
{
overflow: hidden;
background-color: #9999CC;
padding: 20px 0 20px 20px;
position: relative;
width: 600px;
top: 0px;
left: -1px;
}
.tabslider
{
width: 5000px;
}
.tabslider ul
{
float: left;
width: 579px;
padding: 0px;
margin-right: 40px;
margin-left: 0px;
margin-top: 0px;
margin-bottom: 0px;
}
.tabslider ul a
{
color: #330000;
text-decoration: none;
}
.tabslider ul a:hover
{
color: #CC9933;
}
.tabslider ul li
{
padding-bottom: 7px;
}
</style>
Step 6: In
this step we write the script reference to the aspx page; let us see from where
you have to write the script code.
Right-click on both files respectively -> copy and
paste it inside <Head> section of your page; see step 7.
Step 7: Let
us see the script code which you have to add inside the <script></script> tags
and that will be placed either in <head> section or the <body> section as you
prefer.
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="Scripts/jquery.js"></script>
Step 8: In
this step you will see the body code of the Default2.aspx page
which is given below.
<body>
<form id="form1" runat="server">
<div class='tabbed_content'>
<div class='tabs'>
<div class='moving_bg'>
</div>
<span class='tab_item'>C#
corner </span><span class='tab_item'>Latest
Articles </span>
<span class='tab_item'>Latest
Blogs </span><span class='tab_item'>Latest
News </span>
</div>
<div class='slide_content'>
<div class='tabslider'>
<ul>
<li><a href='http://www.c-sharpcorner.com'>Home </a></li>
<li><a href='http://www.c-sharpcorner.com/Resources/AboutUs.aspx'>About
Us </a></li>
<li><a href='http://www.c-sharpcorner.com/Authors/'>Authors </a></li>
</ul>
<ul>
<li><a href='http://www.c-sharpcorner.com/UploadFile/sapnabeniwal/animated-tab-menu-using-jquery/'>
Animated Tab Menu Using jQuery </a></li>
<li><a href='http://www.c-sharpcorner.com/UploadFile/6cde20/concept-of-view-in-sql-server/'>
Concept of View in SQL Server</a></li>
<li><a href='http://www.gayadesign.com/general/new-looks-coming-your-way/%27%3EImplodeImplode()
and Explode() Function in PHP </a></li>
</ul>
<ul>
<li><a href='http://www.c-sharpcorner.com/Blogs/8506/export-windows-live-mail-to-outlook.aspx'>
Export Windows Live Mail to Outlook </a></li>
<li><a href='http://www.c-sharpcorner.com/Blogs/8274/insert-data-in-grid-view-without-using-database.aspx'>
Insert data in Grid View without using database </a></li>
<li><a href='http://www.c-sharpcorner.com/Blogs/8521/html-table.aspx'>HTML
TABLE </a>
</li>
</ul>
<ul>
<li><a href='http://www.c-sharpcorner.com/News/1379/discountAsp-Net-joins-microsoft-visual-studio-industry-progr.aspx'>
DiscountASP.NET Joins Microsoft Visual Studio
Industry Program</a></li>
<li><a href='http://www.c-sharpcorner.com/News/1368/microsoft-dynamic-nav-web-client.aspx'>
Microsoft Dynamic NAV Web Client </a></li>
<li><a href='http://www.c-sharpcorner.com/News/1370/microsoft-released-windows-8-consumer-preview.aspx'>
Microsoft Released Windows 8 Consumer Preview</a></li>
</ul>
</div>
</div>
</div>
</form>
</body>
Step 9: In
this step we will see the complete code of the Default2.aspx page which is given
below.
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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 runat="server">
<title> Animated
Tab Using jQuery and CSS </title>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="Scripts/tabbedContent.js"></script>
<link rel="stylesheet" type="text/css" href="Styles/tabbedContent.css" />
<style type="text/css">
.tabbed_content
{
background-color: #663366;
width: 620px;
}
.tabs
{
height: 62px;
position: relative;
}
.tabs .moving_bg
{
background-color: #FF9933;
background-image: url(../images/arrow_down_green.gif);
background-position: bottom left;
background-repeat: no-repeat;
left: 0;
padding: 15px;
padding-bottom: 29px;
position: absolute;
width: 125px;
z-index: 190;
}
.tabs .tab_item
{
display: block;
float: left;
padding: 15px;
width: 125px;
color: #ffffff;
text-align: center;
z-index: 200;
position: relative;
cursor: pointer;
}
.tabbed_content .slide_content
{
overflow: hidden;
background-color: #9999CC;
padding: 20px 0 20px 20px;
position: relative;
width: 600px;
top: 0px;
left: -1px;
}
.tabslider
{
width: 5000px;
}
.tabslider ul
{
float: left;
width: 579px;
padding: 0px;
margin-right: 40px;
margin-left: 0px;
margin-top: 0px;
margin-bottom: 0px;
}
.tabslider ul a
{
color: #330000;
text-decoration: none;
}
.tabslider ul a:hover
{
color: #CC9933;
}
.tabslider ul li
{
padding-bottom: 7px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class='tabbed_content'>
<div class='tabs'>
<div class='moving_bg'>
</div>
<span class='tab_item'>C#
corner </span><span class='tab_item'>Latest
Articles </span>
<span class='tab_item'>Latest
Blogs </span><span class='tab_item'>Latest
News </span>
</div>
<div class='slide_content'>
<div class='tabslider'>
<ul>
<li><a href='http://www.c-sharpcorner.com'>Home </a></li>
<li><a href='http://www.c-sharpcorner.com/Resources/AboutUs.aspx'>About
Us </a></li>
<li><a href='http://www.c-sharpcorner.com/Authors/'>Authors </a></li>
</ul>
<ul>
<li><a href='http://www.c-sharpcorner.com/UploadFile/sapnabeniwal/animated-tab-menu-using-jquery/'>
Animated Tab Menu Using jQuery </a></li>
<li><a href='http://www.c-sharpcorner.com/UploadFile/6cde20/concept-of-view-in-sql-server/'>
Concept of View in SQL Server</a></li>
<li><a href='http://www.gayadesign.com/general/new-looks-coming-your-way/%27%3EImplodeImplode()
and Explode() Function in PHP </a></li>
</ul>
<ul>
<li><a href='http://www.c-sharpcorner.com/Blogs/8506/export-windows-live-mail-to-outlook.aspx'>
Export Windows Live Mail to Outlook </a></li>
<li><a href='http://www.c-sharpcorner.com/Blogs/8274/insert-data-in-grid-view-without-using-database.aspx'>
Insert data in Grid View without using database </a></li>
<li><a href='http://www.c-sharpcorner.com/Blogs/8521/html-table.aspx'>HTML
TABLE </a>
</li>
</ul>
<ul>
<li><a href='http://www.c-sharpcorner.com/News/1379/discountAsp-Net-joins-microsoft-visual-studio-industry-progr.aspx'>
DiscountASP.NET Joins Microsoft Visual Studio
Industry Program</a></li>
<li><a href='http://www.c-sharpcorner.com/News/1368/microsoft-dynamic-nav-web-client.aspx'>
Microsoft Dynamic NAV Web Client </a></li>
<li><a href='http://www.c-sharpcorner.com/News/1370/microsoft-released-windows-8-consumer-preview.aspx'>
Microsoft Released Windows 8 Consumer Preview</a></li>
</ul>
</div>
</div>
</div>
</form>
</body>
</html>
Step 10: In
this step we are going to run the Default2.aspx page by pressing F5.
Step 11: In
this step we are going to run the Default2.aspx page by pressing F5.
Now see how to switch content through tabs.
MouseHover on next tab.
See the MouseHover effect.
Check the link click on Home Button.
Resources