2016-08-08 63 views
0

我正在嘗試爲我的Google協作平臺頁面在HTML中創建一個選項卡式視圖。我正在尋找與此類似的行爲:http://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_pills_dynamic&stacked=h如何在HTML中創建選項卡式視圖?

將此代碼粘貼到Google協作平臺中時,它無法正常呈現。

enter image description here

有一個簡單的解釋,甚至更簡單的方法來創建此標籤的看法?如果重要,我打算在每個標籤中創建一個表格。

我搜索瞭解決方案,但我注意到「選項卡」可能是錯誤的關鍵字?我看到很多被稱爲選項卡的列表視圖項目。或者他們是關於嚮導航欄中添加選項卡,而不是在站點中的頁面內添加選項卡。

+0

你加引導到你的網頁? – stevenelberger

回答

1

這個效果非常好。剛放下你的表中,它說(也許你會想現在有去除

標籤

<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; 
    } 
} 
1

您共享的鏈接是Bootstrap源代碼示例。如果您試圖實現相同的功能並且可以靈活地使用Bootstrap,請確保已添加樣式和源代碼。

如果你試圖通過編寫你自己的風格來實現它,它非常簡單。這些可以只是自定義樣式列表。每個<li>必須具有css屬性{display:inline-block;float:left;}這將使列表項相鄰顯示。並根據樣式添加一些填充和邊距。

1

您使用引導框架獲得的這種類型的選項卡視圖。在你的代碼中,你忘記附加一些引導文件,如CSS & JS。在這裏我演示了它使用它。

<!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>

有關自舉go here更多細節,以及有關標籤視圖然後go here更多細節。

1

您使用HTML框工具,它具有一定的restrictions,一個是你:

[...]不能包含外部JavaScript文件,除了在ajax.googleapis.com託管的jQuery文件

而且Bootstrap不在Google Hosted Libraries中,更不用說HTML框非常有限了。

一些替代方案:

  1. 搜尋是否有適合您的需要(插入>更多小工具...>搜索小工具)的小工具。
  2. 創建您自己的小工具(Google Developers Gadgets API
  3. 創建Google Apps Script(你可以使用jQuery和Bootstrap這裏),deploy it as a web app,最後embed it in your Google Sites
相關問題