左図上のように内容が表示されません
宜しくお願い致します。
javascript
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 <meta charset="utf-8"> 5 <title>Tab Menu Sample</title> 6 <style> 7 body { 8 padding: 0; 9 margin: 0; 10 font-family: Verdana, sans-serif; 11 } 12 .container { 13 padding: 0; 14 margin: 30px auto; 15 width: 500px; 16 background: #dce0e0; 17 } 18 ul.menu { 19 list-style: none; 20 padding: 0; 21 margin: 0; 22 font-size: 0; 23 } 24 ul.menu li { 25 display: inline-block; 26 } 27 ul.menu li a { 28 display: inline-block; 29 font-size: 14px; 30 width: 80px; 31 height: 20px; 32 line-height: 20px; 33 text-align: center; 34 text-decoration: none; 35 padding: 7px; 36 color: #333; 37 } 38 ul.menu li a.active { 39 background: #353d3e; 40 color: #fff; 41 } 42 ul.menu li a:not(.active):hover { 43 opacity: 0.5; 44 transition: .8s; 45 } 46 .content { 47 font-size: 14px; 48 padding: 7px 10px; 49 line-height: 1.4; 50 background: #353d3e; 51 color: #fff; 52 min-height: 150px; 53 display: none; 54 } 55 .content.active { 56 display: block; 57 } 58 </style> 59</head> 60<body> 61 <div class="container"> 62 <ul class="menu"> 63 <li><a href="#" data-id="about" class="active menu_item">About</a></li> 64 <li><a href="#" data-id="service" class="menu_item">Service</a></li> 65 <li><a href="#" data-id="contact" class="menu_item">Contact</a></li> 66 </ul> 67 <div class="content active" id="about"> 68 about about about about about about about about about about about about about about about about about about about about about about about about about about about about about about about about about about about about about about about 69 </div> 70 <div class="content" id="service"> 71 service service service service service service service service service service service service service service service service service service service service service service service service service service 72 </div> 73 <div class="content" id="contact"> 74 contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact contact 75 </div> 76 </div> 77 <script> 78 (function() { 79 'use strict'; 80 81 var menuItems = document.getElementsByClassName('menu_item'); 82 var contents = document.getElementsByClassName('content'); 83 84 var i; 85 86 for (i = 0; i < menuItems.length; i++) { 87 menuItems[i].addEventListener('click', function(e) { 88 e.preventDefault(); 89 90 var i; 91 92 for (i = 0; i < menuItems.length; i++) { 93 menuItems[i].className = 'menu_item'; 94 } 95 96 this.className = 'menu_item active'; 97 98 for (i = 0; i < contents.length; i++) { 99 contents[i].className = 'content'; 100 } 101 102 document.getElementByID(this.dataset.id).className = 'content active' ; 103 }); 104 } 105 106 })(); 107 </script> 108</body> 109</html> 110
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/05 17:45
2017/04/05 17:49
2017/04/05 17:56
2017/04/05 17:57
2017/04/05 18:30