Tabs are generally used to break content into multiple sections that can be swapped to save space. The tabs effect displays a single content area with multiple panels (sections), each associated with a header (or tab) in a list.
- This effect is created only with CSS and HTML, without JavaScript.

Code (click to select):
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Example Tabs with CSS</title>
<style type="text/css">
/* Tabs effect with CSS - http://coursesweb.net/css/ */
.tabs {
  position: relative;
  width: 80%;
  min-height: 350px;
  margin: 1.2em auto 1em auto;
}
.tabs .tab {
  display: inline-block;
  margin: 0 -1px;
}
.tabs .tab label {
  position: relative;
  margin: 0;
  background: #dadada;
  border: 1px solid #ccc;
  border-bottom: none;
  -moz-border-radius:.5em;
  -webkit-border-radius:.5em;
  -khtml-border-radius:.5em;
  border-radius:.5em;
  padding: .5em .6em;
  font-weight: 700;
  cursor: pointer;
}
.tabs .tab [type=radio] {
  display: none;
}
.tabs .tab [type=radio]:checked ~ label {
  background: #d8fbda;
  border-bottom: 1px solid white;
  text-decoration: underline;
}
.tabs .tab [type=radio]:checked ~ label ~ .content {
  display: block;
}
.tabs .tab .content {
  display:none;
  position: absolute;
  top: 1.7em;
  left: 0;
  right: 0;
  background: #fdfdee;
  border: 1px solid #ccc;
  padding: .3em .8em;
}
/* END Tabs effect */
</style>
</head>
<body>

<div class="tabs">
  <div class="tab">
    <input type="radio" id="tab-1" name="tab-group-1" checked />
    <label for="tab-1">Tab-1</label>
    <div class="content">
      <p>Content in Tab 1.<br/>
      Link: <a href="http://coursesweb.net/" title="Web Programming and Development">CoursesWeb.net</a></p>
    </div>
  </div>
  
  <div class="tab">
    <input type="radio" id="tab-2" name="tab-group-1" />
    <label for="tab-2">Tab-2</label>
    <div class="content">
      <p>Text and link in Tab 2.<br/>
      Free <a href="http://coursesweb.net/css/" title="CSS Course">CSS Course</a>.</p>
    </div>
  </div>
  
   <div class="tab">
     <input type="radio" id="tab-3" name="tab-group-1" />
     <label for="tab-3">Tab-3</label>
     <div class="content">
      <p>Content in Tab 3.<br/>
      Play <a href="http://coursesweb.net/games/" title="Flash Games"><img src="http://coursesweb.net/imgs/thumb5_image.jpg" alt="Flash Games" width="183" height="123" /></a></p>
    </div>
  </div>
  
  <div class="tab">
     <input type="radio" id="tab-4" name="tab-group-1" />
     <label for="tab-4">Tab-4</label>
     <div class="content">
      <div>Content in Tab 4.<br/><h4>Tabs effect with CSS</h4></div>
    </div>
  </div>
  
   <div class="tab">
     <input type="radio" id="tab-5" name="tab-group-1" />
     <label for="tab-5">Tab-5</label>
     <div class="content">
      <p>Other piece of HTML, images, text, etc., in Tab 5.<br/>Other line...</p>
    </div>
  </div> 
</div>
</body>
</html>
Demo:

Content in Tab 1.
Link: CoursesWeb.net

Text and link in Tab 2.
Free CSS Course.

Content in Tab 3.
Play Flash Games

Content in Tab 4.

Tabs effect with CSS

Other piece of HTML, images, text, etc., in Tab 5.
Other line...

- The technique is simple, the content is positioned "absolute" and it is initialy hidden. There are used radio type buttons with label tag associated to each button. The radio buttons are hidden, but when the associated label is clicked, that radio is checked, event that can be detected in css (with: " .tab [type=radio]:checked "), and the content from that tab (label element) it is displayed (with: " .tab [type=radio]:checked ~ label ~ .content { display: block; } ").

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which attribute is used in <a> tag for the address of the link?
src href rel
<a href="http://coursesweb.net/" title="CoursesWeb.net">CoursesWeb.net</a>
Which CSS property sets the type of the text font?
font-family text-decoration font-size
h2 {
  font-family:"Calibri",sans-serif;
}
What instruction selects all the <div> tags with class="cls"?
querySelector("div.cls") getElementsByTagName("div") querySelectorAll("div.cls")
var elm_list = document.querySelectorAll("div.cls");
var nr_elms = elm_list.length;       // number of selected items
alert(nr_elms);
Indicate the function that can be used to get the sum of values in an array.
array_sum() array_diff() array_shift()
$arr = array(1, 2, 3, 4);
$arr_sum = array_sum($arr);
echo $arr_sum;       // 10
Tabs effect with CSS

Last accessed pages

  1. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (47991)
  2. Sweet Home Decoration (49)
  3. Barbie Games (654)
  4. Butterfly Kyodai (7232)
  5. PHP-MySQL free course, online tutorials PHP MySQL code (35690)

Top accessed pages

  1. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (47991)
  2. Read Excel file data in PHP - PhpExcelReader (36111)
  3. PHP-MySQL free course, online tutorials PHP MySQL code (35690)
  4. Get Attribute (ID, Class, Name, Title, Src) with jQuery (32182)
  5. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (29461)