Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a tabbed view in HTML?

When clicking on tab A, show content for tab A. Click on tab B, show content for tab B, and so on.

What's the most simple and compatible way of constructing a HTML snippet?

I don't mean to use any libraries here, so none of jQuery or any other libraries.

like image 626
omg Avatar asked Jun 22 '09 14:06

omg


People also ask

How do I create a tab in HTML?

The tab character can be inserted by holding the Alt and pressing 0 and 9 together.

How do I make an active tab in HTML?

Approach: In the body tag create some tabs under the div tag with a Custom-Data-Attribute that holds the id of the content. Create another div tag to store the content of the tab with a specific id. Specify data attributes for each content tag to display only one tab content at a time.

What does \t do in HTML?

The \t metacharacter matches horizontal tabs (tabulators).

Is there a tab element in HTML?

Unlike with HTML space, there is no particular HTML tab character you could use. You could technically use the 	 entity as the tab is character 9 in the ASCII. Unfortunately, HTML parsers will simply collapse it into a single space due to the whitespace collapse principle. There used to be a special tab element.


2 Answers

If you want to roll your own tab control, you could do something like this:

<html>
  <head>
    <script type="text/javascript">

      function activateTab(pageId) {
          var tabCtrl = document.getElementById('tabCtrl');
          var pageToActivate = document.getElementById(pageId);
          for (var i = 0; i < tabCtrl.childNodes.length; i++) {
              var node = tabCtrl.childNodes[i];
              if (node.nodeType == 1) { /* Element */
                  node.style.display = (node == pageToActivate) ? 'block' : 'none';
              }
          }
      }

    </script>
  </head>
  <body>
    <ul>
      <li>
        <a href="javascript:activateTab('page1')">Tab 1</a>
      </li>
      <li>
        <a href="javascript:activateTab('page2')">Tab 2</a>
      </li>
      ...
    </ul>
    <div id="tabCtrl">
      <div id="page1" style="display: block;">Page 1</div>
      <div id="page2" style="display: none;">Page 2</div>
      ...
    </div>
  </body>
</html>
like image 111
Jacob Avatar answered Oct 03 '22 09:10

Jacob


Here is a list of different types of tabs plus tutorials on how to build them

like image 26
Lark Avatar answered Oct 03 '22 09:10

Lark