前提・実現したいこと
エンジニア・コーダーの先輩方初めまして。
独学でHTML,CSS,JavaScript,jQueryを学習し、現在、ポートフォリオ用のウェブサイトを作成しています。
使用している言語はHTML,CSS,jQueryで、多少動きがあり、且つ、シンプルな構成のサイトを目指しています。
レスポンシブなデザインにするにあたり、想定通りに実装できないのでご教授いただきたく質問する次第です。
発生している問題・エラーメッセージ
問題点としては以下の2点です。
・ハンバーガーメニューは動いているが、中身の要素が中央揃えに出来ない。
・iPadのみメニューが消える。
具体的には...
768pxをブレイクポイントとし、PC表示ではメニューが横並びになり、スマホ等ではハンバーガーメニューになるというコードを書いたのですが、デベロッパーツールで確認するとなぜか**"iPad"**で表示した場合、メニューが全く表示されず消えてしまいます。
また、768px以下ではハンバーガーメニューでメニューの中身を中央揃えにしたいのですが、微妙にズレが生じてしまいます。
自分なりに書籍やブログ等を調べて問題解決に勤しみましたが、これ以上時間を無駄にするわけにはいかないので、解決策を探しております。
ご指摘いただけると幸いです。
該当のソースコード
HTML
1 2</head> 3<body> 4 <header> 5 <div class="container header-container"> 6 <div class="sns-icons"> 7 <div class="instagram-btn"> 8 <a href="https://www.instagram.com/xxy0/" target="_blank"><i class="fab fa-instagram"></i></a> 9 </div> 10 <div class="facebook-btn"> 11 <a href="https://www.facebook.com/profile.php?id=100021649801829" target="_blank"><i class="fab fa-facebook-f"></i></a> 12 </div> 13 <div class="twitter-btn"> 14 <a href="https://twitter.com/Phycodurus3" target="_blank"><i class="fab fa-twitter"></i></a> 15 </div> 16 </div> 17 <div class="header-inner"> 18 <h1 class="header-logo"> 19 <a href="./index.html"><img alt="logo" src="img/Reverie.png" srcset="img/Reverie.png 1x,img/Reverie@2x.png 2x"></a> 20 </h1> 21 </div> 22 23 24 <!-- menu --> 25 <div class="nav-container"> 26 <input id="my-parts-checkbox" class="my-parts-hidden icon-hamburger" type="checkbox"> 27 <label id="my-parts-icon" for="my-parts-checkbox"><span></span></label> 28 <!-- </div> --> 29 <!-- <div class="nav-container"> --> 30 <nav class="menu-container"> 31 <ul class="menu"> 32 <li class="menu-item"><a href="about/index.html">About</a></li> 33 <li class="menu-item"><a href="works/index.html">Works</a></li> 34 <li class="menu-item"><a href="contact/index.html">Contact</a></li> 35 </ul> 36 </nav> 37 </div> 38 </div> 39 </header>
CSS
1/* menu */ 2.icon-hamburger { 3 background: #fff; 4 border: 1px solid #ccc; 5 cursor: pointer; 6 height: 50px; 7 position: relative; 8 width: 50px; 9 display: none; 10 margin-bottom: 0.4em; 11} 12 13.icon-hamburger span { 14 background: #cccccc; 15 display: block; 16 height: 16%; 17 left: 50%; 18 margin: -8% 0 0 -42%; 19 position: absolute; 20 top: 50%; 21 width: 84%; 22} 23 24.icon-hamburger span::before, 25.icon-hamburger span::after { 26 background: #cccccc; 27 content: ""; 28 display: block; 29 height: 100%; 30 left: 50%; 31 margin: -8% 0 0 -50%; 32 position: absolute; 33 top: 50%; 34 width: 100%; 35} 36 37.icon-hamburger span::before { 38 margin-top: -38%; 39} 40 41.icon-hamburger span::after { 42 margin-top: 19%; 43} 44 45@media screen and (max-width: 768px) { 46 .icon-hamburger { 47 display: inline-block; 48 } 49} 50/* 追加 */ 51.my-parts-hidden { 52 display: none; 53} 54 55#my-parts-icon { 56 cursor: pointer; 57 display: inline-block; 58 height: 35px; 59 position: relative; 60 width: 35px; 61 float: right; 62} 63 64@media screen and (min-width: 768px) { 65 #my-parts-icon { 66 display: none; 67 } 68} 69 70#my-parts-icon span { 71 background: #333; 72 border-radius: 4px; 73 display: block; 74 height: 16%; 75 left: 50%; 76 margin: -8% 0 0 -42%; 77 position: absolute; 78 top: 50%; 79 transition: all 0.3s ease-in-out; 80 width: 84%; 81} 82 83#my-parts-icon span::before, 84#my-parts-icon span::after { 85 -webkit-transform: rotate(0); 86 background: #333; 87 border-radius: 4px; 88 content: ""; 89 display: block; 90 height: 100%; 91 left: 50%; 92 margin: -8% 0 0 -50%; 93 position: absolute; 94 top: 50%; 95 transform: rotate(0); 96 transition: all 0.3s ease-in-out; 97 width: 100%; 98} 99 100#my-parts-icon span::before { 101 margin-top: -38%; 102} 103 104#my-parts-icon span::after { 105 margin-top: 19%; 106} 107 108#my-parts-checkbox:checked ~ #my-parts-icon span { 109 background: rgba(51, 51, 51, 0); 110} 111 112#my-parts-checkbox:checked ~ #my-parts-icon span::before, 113#my-parts-checkbox:checked ~ #my-parts-icon span::after { 114 content: ""; 115 display: block; 116 height: 100%; 117 left: 50%; 118 margin: -8% 0 0 -42%; 119 position: absolute; 120 top: 50%; 121 width: 100%; 122} 123 124#my-parts-checkbox:checked ~ #my-parts-icon span::before { 125 -webkit-transform: rotate(-45deg); 126 transform: rotate(-45deg); 127} 128 129#my-parts-checkbox:checked ~ #my-parts-icon span::after { 130 -webkit-transform: rotate(45deg); 131 transform: rotate(45deg); 132} 133 134.menu-container { 135 margin: 0; 136} 137 138.menu-container ul { 139 float: right; 140} 141 142.menu-container .menu { 143 /* border: 1px solid #ccc; */ 144 display: flex; 145 justify-content: space-between; 146 list-style: none; 147 margin: 0; 148 padding: 0; 149} 150 151.menu-container .menu .menu-item { 152 flex: 1; 153} 154 155@media screen and (max-width: 48em) { 156 /* .menu-container .menu .menu-item { 157 padding-bottom: 15px; 158 max-width: 50%; 159 margin: 0 auto; 160 } */ 161 .menu-container { 162 /* background: orange; */ 163 width: 300px; 164 position: relative; 165 display: table-cell; 166 vertical-align: middle; 167 /* height: 200px; */ 168 } 169 .menu-container .menu .menu-item { 170 width: 220px; 171 display: block; 172 vertical-align: middle; 173 padding-bottom: 15px; 174 margin: 0 auto; 175 } 176} 177.menu-container .menu .menu-item a { 178 background: #fff; 179 /* border-right: 1px solid #ccc; */ 180 color: #333; 181 display: block; 182 /* padding: 0 20px 0 0; */ 183 text-align: right; 184 text-decoration: none; 185 padding-left: 50px; 186} 187 188@media screen and (max-width: 768px) { 189 .menu-container .menu { 190 text-align: center; 191 } 192} 193 194.menu-container .menu .menu-item a:hover { 195 /* background: #ccc; */ 196 /* color: #ffffff; */ 197 text-decoration: underline; 198 opacity: 0.5; 199} 200 201.menu-container .menu .menu-item:last-child a { 202 border-right: none; 203} 204 205@media screen and (max-width: 768px) { 206 .menu-container .menu { 207 display: none; 208 width: 100%; 209 } 210 .menu-container .menu .menu-item a { 211 /* border-bottom: 1px solid #ccc; */ 212 border-right: none; 213 } 214 .menu-container .menu .menu-item:last-child a { 215 border-bottom: none; 216 } 217} 218 219
jQuery
1$(function() { 2 3 jQuery('.icon-hamburger').on('click', function() { 4 if(jQuery('.menu-container .menu').css('display') === 'block') { 5 jQuery('.menu-container .menu').slideUp('1500'); 6 }else { 7 jQuery('.menu-container .menu').slideDown('1500'); 8 } 9}); 10 11 $('#back-to-top a').click(function() { 12 $('html,body').animate({scrollTop:0},500,'linear'); 13 return false; 14 }); 15 16 17}); 18
試したこと
色々と状況を見ながら試してみましたがこれ以上は現在の私のスキルでは解決不可と判断しました。
補足情報(ツールのバージョンなど)
エディタは最新のAtom、ブラウザは最新のchrome、jQueryも最新バージョンです。
玄人の方が見ればわかると思うのですが、綺麗なコードではありません。それ故間違い等も見つけにくいかと思いますが、何卒よろしくお願い致します。
回答4件
あなたの回答
tips
プレビュー