実現したいこと
アコーディオンメニューを表示させたい
問題
レスポンシブで767px以下はメニューバーをアコーディオンメニューにしているのですが、クリックして降りてきたul要素部分が下の画像に被ってしまい、表示が見えなくなります。
やったこと
ul要素にpositionを指定したり、メニュー部分をz-index:1にしたり、画像をz-index:-1にしたりしているのですが、どうしても被ってしまいます。
どうしたら表示されるでしょうか?
html
1 <header> 2 <div class="header-logo"> 3 <img src="/img/logo.png" alt=""> 4 </div> 5 <button><img src="/img/button.png" alt="" class="icon-img"></button> 6 <nav> 7 <ul> 8 <li><a href="#"><span class="first-child">card</span></a></li> 9 <li><a href="#">news</a></li> 10 <li><a href="#">price</a></li> 11 <li><a href="#">access</a></li> 12 <li><a href="#">contact</a></li> 13 </ul> 14 </nav> 15 </header> 16</div> 17 18 <div class="home-inner"> 19 <img src="/img/top.png" alt=""> 20 <div class="caption"> 21 <h1>〇〇〇</h1> 22 <p>〇〇〇</p> 23 <button type="submit"> 24 〇〇〇 25 </button> 26 </div> 27 </div>
sass
1$breakpoints: ( 2 "sp": "screen and (max-width: 767px)", 3 "tab": "screen and (max-width: #{$layout-width-inner - 1px})", 4 "pc": "screen and (min-width: #{$layout-width-inner})", 5); 6 7// メディアクエリー 8@mixin mq($breakpoint: sp) { 9 10 @media #{map-get($breakpoints, $breakpoint)} { 11 12 @content; 13 } 14} 15 16 17body { 18 font-family: Yu Gothic; 19 font-weight: bold; 20 max-width: 1366px; 21 margin: 0 auto; 22} 23.container-wrapper { 24 width: 100%; 25 z-index: 1; 26 27header { 28width:100%; 29max-width: 1366px; 30height: 100px; 31background: #3F51B5; 32overflow:hidden; 33opacity: 1; 34 35@include mq('sp') { 36height: 80px; 37} 38} 39 40.header-logo { 41position: relative; 42top: 31px; 43bottom: 30px; 44margin-left: 140px; 45margin-right: 0; 46width: 200px; 47height: 39px; 48opacity: 1; 49 50@include mq('tab') { 51 width: 150px; 52 53} 54@include mq('sp') { 55 top: 21px 56} 57 58} 59button { 60 position: relative; 61background-color: #3F51B5; 62border: 1px solid #3F51B5; 63height: 100%; 64top: -25px; 65 float: right; 66 display: none; 67@include mq('sp') { 68 display: inline-block; 69 } 70 } 71 72.icon-img{ 73 74 width: 30px; 75 top: 0px; 76 position: relative; 77 float: right; 78 margin-right: 20px; 79 z-index: 1; 80 top: -10px; 81 82 @include mq('sp') { 83 display: inline-block; 84 } 85} 86 87 88 89 90 91nav { 92position: relative; 93width: 344px; 94height: 26px; 95opacity: 1; 96float: right; 97margin-right: 140px; 98z-index: 1; 99 100@include mq('tab') { 101 margin:0 10px; 102} 103 104@include mq('sp') { 105 bottom: 10px; 106} 107 108} 109ul { 110letter-spacing: 0; 111opacity: 1; 112display: flex; 113list-style: none; 114margin: 0; 115padding: 0; 116font-weight: normal; 117font-size: 16px; 118z-index: 2; 119 120} 121 122nav ul { 123 @include mq('sp') { 124 display: none; 125 position: absolute; 126 z-index: 2; 127 background-color: #3F51B5; 128 right: -72px; 129 top: 50px; 130 131 } 132} 133 134 135li a{ 136 margin-right: 24px; 137 text-transform: capitalize; 138 color: #FFFFFF; 139 text-decoration: none; 140 background:#3F51B5; 141 z-index: 1; 142 143 144 @include mq('tab') { 145 margin-right: 12px 146 } 147} 148.first-child{ 149 text-decoration: underline red; 150 margin-top: 0.5px; 151} 152 153 154} 155 156.home-inner { 157 height: 600px; 158 position: relative; 159 160 img { 161 background-size: cover; 162 width:100%; 163 max-width: 100%; 164 height: auto; 165 z-index: -2; 166 position: relative; 167 } 168 169
jQuery
1window.addEventListener('DOMContentLoaded', function(){ 2$("button").click(function(){ 3 $("nav ul").slideToggle(200); 4}); 5}); 6
あなたの回答
tips
プレビュー