ReliableGuy
ReliableGuy

Reputation: 30

How to create tabbed view in HTML?

I'm trying to create a tabbed view in HTML for my Google Sites page. I'm looking for behavior similar to this: http://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_pills_dynamic&stacked=h

When pasting this code in Google Sites into an HTML Box and it doesn't render properly.

enter image description here

Is there an easy explanation and perhaps even an easier way to create this tabbed view? If it matters, I plan to create a table in each tab.

I've searched up solutions but I'm noticing "tabs" might be the wrong keyword? I'm seeing a lot of list view items that are being called tabs. Or they are about adding a tab to the navigation bar, not within a page in Sites.

Upvotes: 0

Views: 2501

Answers (4)

Andy at Focallocal
Andy at Focallocal

Reputation: 176

this works really nicely. just drop your table in where it says (and probably you'll want to remove the

tags there now

<div id="selector">

</div>
<div class="tabs">
    <!-- Radio button and lable for #tab-content1 -->
    <input type="radio" name="tabs" id="tab1" checked >
    <label for="tab1">
       <i class="fa fa-rocket" aria-hidden="true"></i>
<span>Projects</span>
    </label>
    <!-- Radio button and lable for #tab-content2 -->
    <input type="radio" name="tabs" id="tab2">
    <label for="tab2">
        <i class="fa fa-users" aria-hidden="true"></i><span>Flash-Mobs</span>
    </label>
    <!-- Radio button and lable for #tab-content3 -->
    <input type="radio" name="tabs" id="tab3">
    <label for="tab3">
       <i class="fa fa-heartbeat" aria-hidden="true"></i><span>Movement</span>
    </label>
    <div id="tab-content1" class="tab-content">
        <h3>Positive Action Projects</h3>
        <p><!-- Tab content here --></p>
    </div> <!-- #tab-content1 -->
    <div id="tab-content2" class="tab-content">
        <h3>Internatonal Positive Action Days</h3>
        <p><!-- Tab content here --></p>
    </div> <!-- #tab-content2 -->
    <div id="tab-content3" class="tab-content">
     <h3>Grow the Movement</h3>
        <p><!-- Tab content here --></p>
    </div> <!-- #tab-content2 -->
    </div>

CSS

    .tabs {
    max-width: 90%;
    float: none;
    list-style: none;
    padding: 0;
    margin: 75px auto;
    border-bottom: 4px solid #ccc;
}
.tabs:after {
    content: '';
    display: table;
    clear: both;
}
.tabs input[type=radio] {
    display:none;
}
.tabs label {
    display: block;
    float: left;
    width: 33.3333%;
    color: #ccc;
    font-size: 30px;
    font-weight: normal;
    text-decoration: none;
    text-align: center;
    line-height: 2;
    cursor: pointer;
    box-shadow: inset 0 4px #ccc;
    border-bottom: 4px solid #ccc;
    -webkit-transition: all 0.5s; /* Safari 3.1 to 6.0 */
    transition: all 0.5s;
}
.tabs label span {
    display: none;
}
.tabs label i {
    padding: 5px;
    margin-right: 0;
}
.tabs label:hover {
    color: #3498db;
    box-shadow: inset 0 4px #3498db;
    border-bottom: 4px solid #3498db;
}
.tab-content {
    display: none;
    width: 100%;
    float: left;
    padding: 15px;
    box-sizing: border-box;
    background-color:#ffffff;
}

.tab-content * {
    -webkit-animation: scale 0.7s ease-in-out;
    -moz-animation: scale 0.7s ease-in-out;
    animation: scale 0.7s ease-in-out;
}
@keyframes scale {
  0% {
    transform: scale(0.9);
    opacity: 0;
    }
  50% {
    transform: scale(1.01);
    opacity: 0.5;
    }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.tabs [id^="tab"]:checked + label {
    background: #FFF;
    box-shadow: inset 0 4px #3498db;
    border-bottom: 4px solid #3498db;
    color: #3498db;
}
#tab1:checked ~ #tab-content1,
#tab2:checked ~ #tab-content2,
#tab3:checked ~ #tab-content3 {
    display: block;
}

@media (min-width: 768px) {
    .tabs i {
        padding: 5px;
        margin-right: 10px;
    }
    .tabs label span {
        display: inline-block;
    }
    .tabs {
    max-width: 750px;
    margin: 50px auto;
    }
}

Upvotes: 1

user3075569
user3075569

Reputation:

You're using HTML Box tool, at it has some restrictions, one is you:

[...] can not include external javascript files, except jQuery files hosted at ajax.googleapis.com

And Bootstrap is not in the Google Hosted Libraries, not to mention the HTML box pretty limited.

Some alternatives:

  1. Search if there is a gadget that suit your needs (Insert > More gadgets... > Search gadgets).
  2. Create your own gadget (Google Developers Gadgets API)
  3. Create a Google Apps Script (you can use jQuery and Bootstrap here), deploy it as a web app, and finally embed it in your Google Sites.

Upvotes: 1

Himanshu Vaghela
Himanshu Vaghela

Reputation: 1119

That type of tab view you get using bootstrap framework. In your code you forget to attach some bootstrap's file like CSS & JS. Here I make demo of it used it.

<!DOCTYPE html>
<html lang="en">

<head>
  <title>Bootstrap Tab Menu</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body>

  <div class="container">
    <h2>Dynamic Pills</h2>
    <ul class="nav nav-pills">
      <li class="active"><a data-toggle="pill" href="#home">Home</a>
      </li>
      <li><a data-toggle="pill" href="#menu1">Menu 1</a>
      </li>
      <li><a data-toggle="pill" href="#menu2">Menu 2</a>
      </li>
      <li><a data-toggle="pill" href="#menu3">Menu 3</a>
      </li>
    </ul>

    <div class="tab-content">
      <div id="home" class="tab-pane fade in active">
        <h3>HOME</h3>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
      </div>
      <div id="menu1" class="tab-pane fade">
        <h3>Menu 1</h3>
        <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
      </div>
      <div id="menu2" class="tab-pane fade">
        <h3>Menu 2</h3>
        <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.</p>
      </div>
      <div id="menu3" class="tab-pane fade">
        <h3>Menu 3</h3>
        <p>Eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
      </div>
    </div>
  </div>

</body>

</html>

For more details about bootstrap go here and for more details about tab view then go here.

Upvotes: 1

Pavithra Olety
Pavithra Olety

Reputation: 88

The link you have shared is the example from Bootstrap source. If you are trying to achieve the same and have the flexibility to use Bootstrap, make sure you have added the styles and the source code.

In case you are trying to achieve by writing your own styles its pretty simple. These can be nothing but custom styled lists. Every <li> has to have the css property {display:inline-block;float:left;} This will make the list items to appear one next to the other. And also add some padding and margin as per the style.

Upvotes: 1

Related Questions