webstuffshare.com

Updated techique and demo click here. In this implementation, we’re going to discuss how to make tabbed menu only by using CSS on your Safari or Chrome browser. The tabbed menu will have 4 tabs each with different contents. If a tabbed is selected, its content will ease-in and be displayed while the content of previous tab appeared will ease-out and be hidden.

To make transition above, we simply need CSS only and Safari or Chrome (Webkit-based) browser (which provides the webkit-transition property). Take a look at the following explanation from webkit official website:

“The simplest kind of animation that we’ve added support for is called a transition. Normally when the value of a CSS property changes, the rendered result is instantly updated, with the element in question changing immediately from the old property value to the new property value. Transitions describe how to instead execute an animation from the old state to the new state over time.”

Now, let’s talk about how we can trigger the transition. Here we use Pseudo Selector focus which means that if we focused on an input element, a transition will run. So, we will use this input element on the tabs. Check this script out:

<div class="menu">
		<div class="one">
			<input class="one-menu" value="Latest" readonly="readonly" />
			<div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </div>
		</div>
		<div class="two">
			<input class="two-menu" value="Today" readonly="readonly" />
			<div class="content"><img src="images/image.png" style="float: left; margin-right: 1em;" />Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </div>
		</div>
		<div class="three">
			<input class="three-menu" value="This Week" readonly="readonly" />
			<div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </div>
		</div>
		<div class="four">
			<input class="four-menu" value="This Month" readonly="readonly" />
			<div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
		</div>
	</div>


Each menu will be classified into a div. For the menu tab we define it into an element named input while the content we define into a div with class “content”. In order to avoid cursor blink while we choose the menu (input element), we add a readonly attribute inside.

	body {
		background: url('images/background.png') top left repeat-x;
		text-align: center;
		line-height: 1.5em;
		font-size: 13px;
	}
 
	#container {
		margin-top: 5%;
		margin-left: auto;
		margin-right: auto;
	}
 
	.menu {
		margin-left: auto;
		margin-right: auto;
		position:relative;
		width: 390px;
		height: 300px;
		background: url('images/transparent.png');
		text-align: left;
		color: #fff;
		overflow:hidden;
		-webkit-border-radius: 5px;
	}
 
	.one, .two, .three, .four {
		width: 250px;
		float: left;
		position: absolute;
	}
 
	.one-menu, .two-menu, .three-menu, .four-menu {
		position: absolute; 
		display: inline;
		width: 100px;
		height: 30px;
		margin:0;
		padding: 0;
		background: url('images/background-menu.jpg');
		text-align: center;
	}
 
	.two {
		margin-left: 7.5em;
	}
 
	.three {
		margin-left: 15em;
	}
 
	.four {
		margin-left: 22.5em;
	}
 
	.content {
		-webkit-transition: all .5s ease-in-out;
		opacity: 0;
		margin-top: 3.5em;
		width: 370px;
		padding: 0 10px;
	}
 
	input {
		border: 0;
		cursor: pointer;
		background: none;
		color: #daf2fa;
		text-shadow: 0px 1px 0px #041217;
		font-size: 15px;
	}
 
	.one-menu:focus, .two-menu:focus, .three-menu:focus, .four-menu:focus {
		background: none;
		outline: none;
		cursor: pointer;
	}	
 
		.one-menu:focus + div.content { 
			opacity: 1;
		}
 
		.two-menu:focus + div.content { 
			opacity: 1;
			margin-left: -7.5em;
		}
 
		.three-menu:focus + div.content { 
			opacity: 1;
			margin-left: -15em;
		}
 
		.four-menu:focus + div.content { 
			opacity: 1;
			margin-left: -22em;
		}
 
	.title {
		font-size: 25px;
		font-weight: bold;
		margin-bottom: 1em;
		text-shadow: 0px 1px 0px #93bdcb;
	}


First, we put the menus (inputs) into horizontal menu list, and then we hide their content by changing the opacity property into 0. Then we add webkit property transition so as to make an automatic transition if there’s either position or opacity change.

The important thing from this menu are :

.one-menu:focus + div.content { 
	opacity: 1;
}
 
.two-menu:focus + div.content { 
	opacity: 1;
	margin-left: -7.5em;
}
 
.three-menu:focus + div.content { 
	opacity: 1;
	margin-left: -15em;
}
 
.four-menu:focus + div.content { 
	opacity: 1;
	margin-left: -22em;
}

We will show the content of chosen tab by changing the opacity into 1. Since we have injected the content with webkit transition, the opacity change will happen softly. OK, so far we have finished the tab. But there’s still an unsolved problem; I still don’t know how to make the default content for the menu(s) that haven’t been chosen. If you got an idea how to crack this problem, it will be lovely to discuss it on the following comment box. Thanks!

You can get regular useful updates about web-stuff by subscribing webstuffshare RSS feed. If you like this post, your sharing and feedback would be very appreciated ;)

 

Tags :   CSS    Free Stuff    Menu  

Share :           Pure CSS Tab Menu on Webkit-based Browser (via @hdytsgt)



webstuffshare RSS



  Similar Stuffs  

  10 Shouts to “Pure CSS Tab Menu on Webkit-based Browser”  

    Hidayat Sagita


    Hidayat Sagita


    Hidayat Sagita


    Pred


    Hidayat Sagita



  Shout Something  

  Follow Webstuffshare  
RSS
  FREE Subscribe  

Get Free Webstuffshare Daily Updates.

  Hot Stuffs  
  Recent Shouts