| You are here : : Home > Free Resources > CSS Tutorials > Sliding Menu Buttons |
Free Web Design Resources
Other Web Design Resources
| Browser Support | » | ![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| Language | » | CSS3, HTML4 & jQuery | |||
| Difficulty | » | Intermediate | |||
| Estimated Completion Time | » | 15 minutes. | |||
<head> tags. 1 2 3 4 5
<head>
<script type="text/javascript" src="jquery-1.5.2.min.js" ></script>
</head>
src attribute to the script tag.src attribute to "http://code.jquery.com/jquery-latest.js";
1 2 3 4 5 6 7
<head>
<script type="text/javascript"
src="http://code.jquery.com/jquery-latest.js">
</script>
</head>
<div> tags.<div> tags and assign class="button" to each of them.
<div> tags.
<div> tag and assign class="button" to it.
To assign colors to the buttons we will add another class "color_name" on the <div> tag. button should come first and then the class color_name.
1 2 3 4 5 6 7 8
<div class="container">
<div class="button green"> Menu Option </div>
<div class="button ornage"> Menu Option </div>
<div class="button violet"> Menu Option </div>
<div class="button pink"> Menu Option </div>
</div> <!-- #container -->
class="button color_name" Stylesheet code. class="button", and then create the class="color_name"classes using space, and use them as single class selector.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
<style type="text/css"> .button { padding: 11px 21px 13px; display: inline; border: 2px solid #FFF; color: #fff; cursor: pointer; font-weight: bold; text-shadow: 1px 1px #666; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; box-shadow:inset 0px -4px 21px 0px #f0f0f0; -moz-box-shadow:inset 0px -4px 21px 0px #f0f0f0; -webkit-box-shadow:inset 0px -4px 21px 0px #f0f0f0; box-shadow:0px 2px 21px 0px #3f3f3f; -moz-box-shadow:0px 2px 21px 0px #3f3f3f; -webkit-box-shadow: 0px 2px 21px 0px #3f3f3f; } .button:active { position: relative; top: 6px; text-shadow: 2px 2px #666; padding: 10px 21px 10px; box-shadow:inset 0px 4px 21px 5px #e5e5e5; -moz-box-shadow:inset 0px 4px 21px 5px #e5e5e5; -webkit-box-shadow:inset 0px 4px 21px 5px #e5e5e5; box-shadow: 0px 0px 21px 0px #3f3f3f; -moz-box-shadow: 0px 0px 21px 0px #3f3f3f; -webkit-box-shadow: 0px 0px 21px 0px #3f3f3f; } .blue { background-color: #56c6d9; } .green { background-color: #99dc30; } .orange { background-color: #ffd22e; } .violet { background-color: #c5b8f6; } .pink { background-color: #fe2192; } </style>
<div> tag. The links inside the slider are kept in seperate anchor <a> tags.class="slider" to every slider we create to animate it later with jQuery.class="gradient_name" to each slider to apply color on it to make it single class <div class="gradient_name slider"> . <div class="slider"> and the <div class="button color_name"> in a same <div> element so that the slider is positioned right below the respective button.<div class="column"> and put the <div class="button color_name"> and <div class="slider"> inside it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
<div id="container">
<div class="column">
<div class="button green">Menu option -»</div>
<div class="green_grad slider">
<a href="#">Green Option one</a>
<a href="#">Green Option two</a>
</div> <!-- .slider -->
</div> <!-- .column -->
<div class="column">
<div class="button orange">Menu option -»</div>
<div class="orange_grad slider">
<a href="#">Orange Option one</a>
<a href="#">Orange Option two</a>
<a href="#">Orange Option three</a>
</div> <!-- .slider -->
</div> <!-- .column -->
<div class="column">
<div class="button violet">Menu option -»</div>
<div class="violet_grad slider">
<a href="#">Violet Option one</a>
<a href="#">Violet Option two</a>
<a href="#">Violet Option three</a>
<a href="#">Violet Option four</a>
</div> <!-- .slider -->
</div> <!-- .column -->
<div class="column">
<div class="button pink">Menu option -»</div>
<div class="pink_grad slider">
<a href="#">Pink Option one</a>
<a href="#">Pink Option two</a>
<a href="#">Pink Option three</a>
<a href="#">Pink Option four</a>
<a href="#">Pink Option five</a>
</div> <!-- .slider -->
</div> <!-- .column -->
</div> <!-- #container -->
class="slider" for the sliderclass="gradient_name" for the sliderclass="column" for the container that holds both the button and the slider.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
<style type="text/css"> .green_grad { background: url(images/green.png) repeat-x; /* for all browsers */ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#99DC30', endColorstr='#99DC30'); /* Internet Explorer 6,7 and 8 */ -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#99DC30', endColorstr='#99DC30')"; /* Internet Explorer 8 only */ background: -webkit-gradient(linear, left top, left bottom, from(rgba(153,220,48,0.1)), to(rgba(153,220,48,1))); /* for webkit browsers */ background: -moz-linear-gradient(top, rgba(153,220,48,0.1), rgba(153,220,48,1)); /* for firefox 3.6+ */ background: -o-linear-gradient(rgba(153,220,48,0.1),rgba(153,220,48,1)); /* For Opera Browsers */ } .orange_grad { background: url(images/orange.png) repeat-x; /* For all browsers*/ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFD230', endColorstr='#FFD230'); /* Internet Explorer 6,7 and 8 */ -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFD230', endColorstr='#FFD230')"; /*Internet Explorer 8 only*/ background: -webkit-gradient(linear, left top, left bottom, from(rgba(255,210,48,0.1)), to(rgba(255,210,48,1))); /* for webkit browsers */ background: -moz-linear-gradient(top, rgba(255,210,48,0.1), rgba(255,210,48,1)); /* for firefox 3.6+ */ background: -o-linear-gradient(top,rgba(255,210,48,0.1),rgba(255,210,48,1)); /* For Opera Browsers */ } .violet_grad { background: url(images/violet.png) repeat-x; /* For all browsers */ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#C5B8F6', endColorstr='#C5B8F6'); /* Internet Explorer 6,7 and 8*/ -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#C5B8F6', endColorstr='#C5B8F6')"; /* Internet Explorer 8 only*/ background: -webkit-gradient(linear, left top, left bottom, from(rgba(197,184,246,0.1)), to(rgba(197,184,246,1))); /* for webkit browsers */ background: -moz-linear-gradient(top, rgba(197,184,246,0.1), rgba(197,184,246,1)); /* for firefox 3.6+ */ background: -o-linear-gradient(top,rgba(197,184,246,0.1),rgba(197,184,246,1)); /* For Opera Browsers */ } .pink_grad { background: url(images/pink.png) repeat-x; /* For all browsers */ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FE2192', endColorstr='#FE2192'); /*Internet Explorer 6,7 and 8*/ -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#FE2192', endColorstr='#FE2192')"; /* Internet Explorer 8 only */ background: -webkit-gradient(linear, left top, left bottom, from(rgba(254,33,146,0.1)), to(rgba(254,33,146,1))); /* for webkit browsers */ background: -moz-linear-gradient(top, rgba(254,33,146,0.1), rgba(254,33,146,1)); /* for firefox 3.6+ */ background: -o-linear-gradient(top,rgba(254,33,146,0.1),rgba(254,33,146,1)); /* For Opera Browsers */ } .slider { background-color:#fff; width:172px; height:200px; line-height:30px; text-align:center; color: #555; position: absolute; top: -234px; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter: alpha(opacity=0); opacity:0.0; } .slider a { display: block; color: #000; font-weight: bold; } .slider a:hover { background: #f1f1f1; } .column { float: left; margin-left: 12px; position: relative; margin-top:21px; } </style>
opacity.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<script type="text/javascript"> $(document).ready(function(){ $(".button" ).toggle(function(){ var clas = $(this).attr("class" ); $("."+clas.replace('button ','')+"_grad" ).animate({opacity:'1',top:'50px'}, 500 ) }, function(){ var clas = $(this).attr("class" ); $("."+clas.replace('button ','')+"_grad" ).animate({opacity:'0',top:'-300px'}, 500 ); }); }); </script>
$(document).ready(function(){
$(".button" ).toggle(function(){
<div> elements with class="button".$("selector").toggle(function(){first statement},function(){second statement});
var clas = $(this).attr("class" );
"class". "button green". <div class="button green">. button class for the Button Effect and green class for the green background color.clas.
$("."+clas.replace('button ','')+"_grad" ).animate({opacity:'1',top:'50px'},500)
}
clas, with "blank" clas will be assigned "button green" using statement on Line 6."button green" to "green_grad".Join us on Facebook to keep updated with all the latest tutorials and web design freebies from EntheosWeb!