前提
headerのnavをhoverしてメニューを表示させる機構で、表示が上手くいきません。
実現したいこと
hoverして、2階層目のメニューを表示させたい。
該当のソースコード
HTML
1ソースコード 2<header class="header"> 3 <div class="header__inner"> 4 <h1> 5 <a href="index.html"> 6 <img src="img/header__logo.png" alt="ロゴ" class="header__logo"> 7 </a> 8 </h1> 9 <div class="header__btn"><span></span><span></span><span></span></div> 10 <nav class="nav"> 11 <div class="nav__list--scroll"> 12 <ul class="nav__list"> 13 <li><a href="1-2.html#">HOME</a></li> 14 <li class="has-child"><a href="1-2.html#">コース</a> 15 <ul> 16 <li><a href="1-2.html#">コース紹介</a></li> 17 <li><a href="1-2.html#">タイトル</a></li> 18 <li><a href="1-2.html#"><タイトル/a></li> 19 <li><a href="1-2.html#">タイトル</a></li> 20 </ul> 21 </li> 22 </ul> 23 </div> 24 </nav> 25 </div> 26 </header> 27```CSS 28/* ===ヘッダーのデザイン=== */ 29.header { 30 background-color: var(--white-color); 31 width: 100%; 32 position: fixed; 33 height: 5rem; 34 z-index: 900; 35 display: flex; 36 align-items: center; 37} 38 39.header__inner { 40 position: fixed; 41 padding: 6px 16px; 42 width: 100%; 43 height: 5rem; 44 margin: 0 auto; 45 display: flex; 46 align-items: center; 47 z-index: 900; 48} 49 50/* ヘッダーのロゴ */ 51.header__logo { 52 width: 20rem; 53} 54 55/* ===ヘッダー終了=== */ 56 57/* ===ハンバーガーボタン開始=== */ 58.header__btn { 59 position: fixed; 60 position: absolute; 61 z-index: 9999; 62 right: 0; 63 cursor: pointer; 64 width: 50px; 65 height: 50px; 66} 67 68/*×に変化*/ 69.header__btn span { 70 display: inline-block; 71 transition: all .4s; 72 position: absolute; 73 left: 16px; 74 height: 3px; 75 border-radius: 2px; 76 background-color: var(--text-color); 77 width: 45%; 78} 79 80.header__btn span:nth-of-type(1) { 81 top: 15px; 82} 83 84.header__btn span:nth-of-type(2) { 85 top: 23px; 86} 87 88.header__btn span:nth-of-type(3) { 89 top: 31px; 90} 91 92.header__btn.active span:nth-of-type(1) { 93 top: 18px; 94 left: 18px; 95 transform: translateY(6px) rotate(-45deg); 96 width: 30%; 97} 98 99.header__btn.active span:nth-of-type(2) { 100 opacity: 0; 101} 102 103.header__btn.active span:nth-of-type(3) { 104 top: 30px; 105 left: 18px; 106 transform: translateY(-6px) rotate(45deg); 107 width: 30%; 108} 109 110/* ===ハンバーガーボタン終了=== */ 111 112/* ===ナビゲーション開始=== */ 113.nav { 114 position: fixed; 115 z-index: 999; 116 top: 0; 117 right: -120%; 118 width: 100%; 119 height: 100vh; 120 background-color: var(--bg-color); 121 transition: all 0.6s; 122} 123 124/*アクティブクラスがついたら位置を0に*/ 125.nav.panelactive { 126 right: 0; 127} 128 129/*ナビゲーションの縦スクロール*/ 130.nav.panelactive, 131.nav__list--scroll { 132 position: fixed; 133 z-index: 999; 134 width: 100%; 135 height: 100vh; 136 overflow: auto; 137 -webkit-overflow-scrolling: touch; 138} 139 140.nav__list { 141 position: absolute; 142 z-index: 999; 143 top: 50%; 144 left: 50%; 145 transform: translate(-50%, -50%); 146 width: 80%; 147} 148 149.nav__list li.has-child ul { 150 position: relative; 151 left: 0; 152 top: 0; 153 width: 100%; 154 visibility: visible; 155 opacity: 1; 156 display: none; 157} 158 159.nav__list a { 160 text-decoration: none; 161 display: block; 162 font-size: 1.6rem; 163 font-weight: bold; 164 text-align: center; 165 color: var(--text-color); 166 padding: 2rem 3.5rem; 167 transition: all .3s; 168} 169 170 171.nav__list li ul li { 172 border-bottom: solid; 173 margin: 0 auto; 174 width: 70%; 175} 176 177.nav__list li ul li:last-child { 178 border-bottom: none; 179} 180 181.nav__list li ul li a{ 182 padding: .8rem; 183} 184 185/*下の階層のulや矢印の基点にするためliにrelativeを指定*/ 186.nav__list li { 187 position: relative; 188} 189 190 191/* 矢印の設定*/ 192.nav__list li.has-child::before { 193 content: ''; 194 position: absolute; 195 left: 15px; 196 top: 30px; 197 width: 6px; 198 height: 6px; 199 border-top: 2px solid var(--text-color); 200 border-right: 2px solid var(--text-color); 201 transform: rotate(135deg); 202} 203 204.nav__list li.has-child.active::before { 205 content: ''; 206 position: absolute; 207 transform: rotate(-45deg); 208 top: 30px 209} 210 211/* ===ナビゲーション終了=== */ 212/* ===PCのデザイン=== */ 213@media screen and (min-width:1025px){ 214 /* header */ 215 .header { 216 height: 8rem; 217 z-index: 0; 218 } 219 220 .header__inner { 221 position: fixed; 222 height: 8rem; 223 display: flex; 224 align-items: center; 225 justify-content: space-between; 226 } 227 228 .header__logo { 229 width: 30rem; 230 } 231 232 .header__btn { 233 display: none; 234 } 235 236 .nav { 237 position: static ; 238 z-index: auto; 239 height: 8rem; 240 background-color: transparent; 241 overflow-y: scroll; 242 -ms-overflow-style: none; /* IE, Edge 対応 */ 243 scrollbar-width: none; /* Firefox 対応 */ 244 z-index: 0; 245 } 246 247 .nav::-webkit-scrollbar { 248 display: none; 249 } 250 251 .nav__list { 252 position: static; 253 transform: none; 254 display: flex; 255 justify-content: flex-end; 256 } 257 258 .nav__list li a { 259 position: static; 260 padding: 0 1.6rem; 261 } 262 263 .nav__list--scroll { 264 position: static; 265 height: 8rem; 266 display: flex; 267 align-items: center; 268 justify-content: flex-end; 269 } 270 271 .nav__list li.has-child::before { 272 left: 1px; 273 top: 10px; 274 } 275 276 .nav__list li { 277 position: relative; 278 } 279 280 .nav__list li.has-child ul{ 281 /*絶対配置で位置を指定*/ 282 position: absolute; 283 left:0; 284 top:80px; 285 z-index: 4; 286 /*形状を指定*/ 287 background:blue; 288 width:180px; 289 /*はじめは非表示*/ 290 visibility: hidden; 291 opacity: 1; 292 /*アニメーション設定*/ 293 transition: all .3s; 294 padding: 0; 295 display: block; 296 color:red; 297 } 298 299 .nav__list li.has-child a:hover > ul, 300.nav__list li.has-child ul li a:hover > ul, 301.nav__list li.has-child a:active > ul, 302.nav__list li.has-child ul li a:active > ul{ 303 visibility: visible; 304 opacity: 1; 305 display: block; 306 color: red; 307} 308 309} 310 311### 補足情報 312https://coco-factory.jp/ugokuweb/move01-cat/globalnavigation/ 313を参考に制作しました。 314 315ここにより詳細な情報を記載してください。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/08/14 08:36