Usually more popular Making tabs using jquery, but actually quite the css we are able to create tabs that are not less good.
In this article we will briefly describe how to create tabs with css only, without the help of jquery or other javascript.
HTML structure
For the first we make the first of its HTML structure
<main>Can be seen in the script above, to make the title of the tab we use input tags and labels, in this example we create 4 tabs, with each tab in the given ID
<h4><a href="http://tipsandtriksblogspot.blogspot.com">Tutorial Web Design.com</a></h4>
<h2>CSS Tabs</h2>
<input id="tab1" type="radio" name="tabs" checked>
<label for="tab1">Home</label>
<input id="tab2" type="radio" name="tabs">
<label for="tab2">About</label>
<input id="tab3" type="radio" name="tabs">
<label for="tab3">Contact</label>
<input id="tab4" type="radio" name="tabs">
<label for="tab4">Social Media</label>
<section id="content1">
<h3>Selamat Datang TWDers</h3>
<p>Content....</p>
</section>
<section id="content2">
<h3>About TWD</h3>
<p>Content....</p>
</section>
<section id="content3">
<h3>Contact TWD</h3>
<p>Content....</p>
</section>
<section id="content4">
<h3>Social Media</h3>
<p>Content...</p>
</section>
</main>
tab1, tab2, tab3, tab4
As for the content of each tab is made with a tag that each section has an ID
content1, conten2, content3, content4.
Styling with CSS
Once we create the html structure of the tab, this would not be shaped tabs, should be given in the design or style by using css, css code like this was the one we use
@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,700);CSS code for the Tab
body {
background: #5B264E;
font-family: "Open Sans", "Arial";
}
a{
text-decoration: none;
color: #000;
}
a:hover{
color: #B7977B;
}
main {
background: #FFF;
width: 500px;
margin: 50px auto;
padding: 10px 30px 80px;
box-shadow: 0 3px 5px rgba(0,0,0,0.2);
}
p {
font-size: 13px;
}
/* Important code */
input, section {
clear: both;
padding-top: 10px;
display: none;
}
label {
font-weight: bold;
font-size: 14px;
display: block;
float: left;
padding: 10px 30px;
border-top: 2px solid transparent;
border-right: 1px solid transparent;
border-left: 1px solid transparent;
border-bottom: 1px solid #DDD;
}
label:hover {
cursor: pointer;
text-decoration: underline;
}
#tab1:checked ~ #content1, #tab2:checked ~ #content2, #tab3:checked ~ #content3, #tab4:checked ~ #content4 {
display: block;
}
input:checked + label {
border-top-color: #B7977B;
border-right-color: #DDD;
border-left-color: #DDD;
border-bottom-color: transparent;
text-decoration: none;
}
The most important thing to be noticed in the above code is the code that we mark with / * Important Code * / to the end.
Where was the change that code into a form input tag tab, why use radio type input? because the tab usually only have one part that is active while the other is closed, the only input to the radio type that allows for such selected.
So logic sederhanya this: section tags will be hidden when loaded, when one ID tab is active (one radio input is selected), then the content of the ID will be displayed, using the command display: block
Hopefully Useful To You...

Post a Comment