2017-09-28 16 views
0

私は新しいウェブサイトで練習しています。このウェブサイトには水平バーがあります。 (テキストは私がラベルを付ける場所です)。HTML水平タブ。あなたがそれを表示するタブをクリックするとそれを作る方法

私の質問です。タブをクリックするとどうすればいいですか?そのタブに移動し、タブに書き込まれているものを表示します。

私が試し続けていることはすべて動作しません。私はクラスが必要ですか?

私を助けてくれてありがとう!

マイコード:

<!DOCTYPE html> 
 

 
<html lang="en"> 
 

 
<head> </head> 
 

 
<title>Title - Title</title> 
 

 
<body> 
 

 
<body style="background-color:pink;"> 
 

 
<style> 
 
ul { 
 
list-style-type: none; 
 
margin: 0; 
 
padding: 0; 
 
overflow: hidden; 
 
background-color: #333; 
 
} 
 

 
li { 
 
float: left; 
 
} 
 

 
li a { 
 
display: block; 
 
color: white; 
 
text-align: center; 
 
padding: 14px 16px; 
 
text-decoration: none; 
 
} 
 

 
li a:hover { 
 
background-color: #111; 
 
} 
 
</style> 
 

 
<ul> 
 
<li><a class="active" href="#text">text</a></li> 
 
<li><a href="#text">text</a></li> 
 
<li><a href="#text">text</a></li> 
 
<li><a href="#text">text</a></li> 
 
<li><a href="#text">text</a></li> \t \t \t \t \t 
 
<li><a href="#text">text</a></li> \t \t \t \t \t 
 
</ul> 
 

 
</body> 
 
</html>

+0

あなたはタブとしてページ上のすべてのコンテンツをロードするか、内容のページをスクロールするアンカータグを使用することができます場合は、jqueryのが必要になります。それを行う前に、最初に解決する必要があるいくつかの問題があるので、HTMLバリデーターを通してコードを実行することをお勧めします。 – Syfer

+0

あなたは何を意味するのですか?私は何も見ません。 –

+0

1. Bodyタグを3か所に開いて1回閉じました。 2.スタイルタグは頭部または別個のファイルでなければなりません。 – Syfer

答えて

0

$(function(){ 
 
\t $(document).on('click', '.open-panel', function(e){ 
 
    \t $('.panel-item').each(function(){ 
 
     \t $(this).removeClass('active'); 
 
     }); 
 
\t  var $this = $(this); 
 
     setTimeout(function(){ 
 
      var panel = $this.data('panel'); 
 
      $('#' + panel).addClass('active'); 
 
     }, 500); 
 
    }); 
 
});
ul { 
 
list-style-type: none; 
 
margin: 0; 
 
padding: 0; 
 
overflow: hidden; 
 
background-color: #333; 
 
} 
 

 
li { 
 
float: left; 
 
} 
 

 
li a { 
 
display: block; 
 
color: white; 
 
text-align: center; 
 
padding: 14px 16px; 
 
text-decoration: none; 
 
} 
 

 
li a:hover { 
 
background-color: #111; 
 
} 
 

 
.panel-item { 
 
    position: relative; 
 
    max-height:0; 
 
    transition: max-height ease-in-out .4s; 
 
    -webkit-transition: max-height ease-in-out .4s; 
 
    -moz-transition: max-height ease-in-out .4s; 
 
    -o-transition: max-height ease-in-out .4s; 
 
    -ms-transition: max-height ease-in-out .4s; 
 
    overflow: hidden; 
 
} 
 

 
.panel-item.active{ 
 
    max-height: 400px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<ul> 
 
<li><a href="#text" class="open-panel" data-panel="text">text</a></li> 
 
<li><a href="#text1" class="open-panel" data-panel="text1">text</a></li> 
 
<li><a href="#text2" class="open-panel" data-panel="text2">text</a></li> 
 
<li><a href="#text3" class="open-panel" data-panel="text3">text</a></li> \t \t \t \t \t 
 
<li><a href="#text4" class="open-panel" data-panel="text4">text</a></li> \t \t \t \t \t 
 
</ul> 
 

 
<div class="panel-container"> 
 
    <div id="text" class="panel-item"> 
 
     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
 
    </div> 
 
    <div id="text1" class="panel-item"> 
 
     Why do we use it? 
 
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). 
 
    </div> 
 
    <div id="text2" class="panel-item"> 
 
     Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. 
 

 
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham. 
 

 

 
    </div> 
 
    <div id="text3" class="panel-item"> 
 
     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
 
    </div> 
 
     <div id="text4" class="panel-item"> 
 
     There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc. 
 

 

 
    </div> 
 
</div>

0

私はそれを完了しました。 Click it.

このバージョンでは、JavaScriptを使用していません。私はそれが簡単な解決策だと思う。

キーコード:

.tab1, .tab2, .tab3, .tab4 { 
position: absolute; 
display: none; 
} 
.tab1:target, .tab2:target, .tab3:target, .tab4:target { 
display:block; 
} 
関連する問題