【Sample】Size variableness, tab layout for smartphone【Check Box】

Demo

 Enter to Demo


HTML

 Read jQuery 1.x snippet in <head> from Google Hosted Libraries.


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>

<div id="tab">
<ul id="tab-head">
<li id="tab-h1"><a href="#tab-b1">menu1</a></li>
<li id="tab-h2"><a href="#tab-b2">menu2</a></li>
<li id="tab-h3"><a href="#tab-b3">menu3</a></li>
<li id="tab-h4"><a href="#tab-b4">menu4</a></li>
<!--tab-head--></ul>
<div id="tab-body">
<div id="tab-b1">content1</div>
<div id="tab-b2">content2</div>
<div id="tab-b3">content3</div>
<div id="tab-b4">content4</div>
<!--tab-body--></div>
<!--tab--></div>
CSS

.sample-demo #tab {
	margin: 0 10px;
}
.sample-demo #tab-head {
	width: 400px;
	overflow: hidden;
}
.sample-demo #tab-head li {
	float: left;
}
.sample-demo #tab-head li a {
	display: block;
	width: 98px;
	height: 25px;
	text-align: center;
}
.sample-demo #tab-body {
	width: 100%;/*The width sets it here. It becomes variable if You will have 100%.*/
	min-width: 400px;
	position: relative;
	top: -1px;
	z-index: -1;
}
.sample-demo #tab-b1,#tab-b2,#tab-b3,#tab-b4 {
	height: 300px;
	padding: 10px;
	background: #fff;
	border: 1px solid #ccc;
}
.sample-demo #tab-b2,
.sample-demo #tab-b3,
.sample-demo #tab-b4 {
	display: none;
}
.sample-demo .tab1 {
	background: #eee;
	border-top: 1px solid #ccc;
	border-right: 1px solid #ccc;
	border-left: 1px solid #ccc;
}
.sample-demo .tab2 {
	background: #fff;
	border-bottom: 1px solid #fff;
}
JavaScript

$(function(){
$("#tab-head li").addClass("tab1");
$("#tab-head li a").eq(0).addClass("tab2");
$("#tab-head li a").click(function() {
$("#tab-body div").hide();
$($(this).attr("href")).fadeIn();/*Control it with an animation*/
//$($(this).attr("href")).css('display','block');/*Control it by CSS*/
$("#tab-head li a").removeClass("tab2");
$(this).addClass("tab2");
return false;
});
});
Back to the previous page