お世話になります。
flexboxでHTMLのテンプレートを作成中なのですが、
スマホ時768px以下に表示されるMENUボタンを開閉後、
そのままブラウザ画面を広げるとPC時の横並びメニューが出ません。
ブラウザの更新ボタンを押すと表示されるのですが、
スマホ時のdisplay:none;が効いたままのようです。
メニューの「#navi」要素にそれぞれ、
・スマホ時「display:none !important;」
・PC時「display:block !important;」
を付けると、今度はスマホ時にMENUボタンを押してもjQueryの.slideToggleが効かない状態です。
グーグルで調べてみたのですが、類似の設定が見当たりませんでした。。
何か良い方法はございますでしょうか?
よろしくお願いいたします。
/* HTML */ <!doctype html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1"> <title>サンプルテスト1</title> <link rel="stylesheet" media="all" href="style.css" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <script> $(function(){ // アイコンをクリック $("button").click(function(){ // #naviメニューを開閉する $("#navi").slideToggle(); }); }); </script> </head> <body> <div class="container"> <div class="row"> <div class="col span-12"> <header class="header"> <h1>LOGO</h1> <nav> <button><img src="button.png" width="20" height="17" alt="Button"><br><span class="menu">MENU</span></button> <div id="navi"> <ul> <li><a href="">ホーム</a></li> <li><a href="">店舗について</a></li> <li><a href="">サブページ</a></li> <li><a href="">サブページ</a></li> <li><a href="">お問い合わせ</a></li> </ul> </div> </nav> </header> </div> </div> </div> </body> </html>
/* CSS */ /* 全体の設定 –––––––––––––––––––––––––––––––––––––––––––––––––– */ html { box-sizing: border-box; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; font-size: 62.5%; } body { font-family: "MS ゴシック",sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.6; margin:0; padding:0; } /* グリッド –––––––––––––––––––––––––––––––––––––––––––––––––– */ .container { margin: 0 auto; max-width: 1200px; padding: 0 2.0rem; position: relative; } /* ブロックを縦に表示 */ .row { display: flex; flex-direction: column; /* 縦並び */ padding: 0; width: 100%; } .col { display: block; flex: 1 1 auto; margin-left: 0; max-width: 100%; width: 100%; } /* 768px以上のブロック表示 –––––––––––––––––––––––––––––––––––––––––––––––––– */ @media screen and ( min-width : 768px ) { .row { display: flex; flex-direction: row; /* 横並び */ padding: 0; } .col { margin-left: 4%; } .col:first-child { margin-left: 0; } .row .col.span-12 { flex: 0 0 100%; max-width: 100%; } } /*ヘッダー -------------------------------------*/ .header { display: flex; flex-direction: row; padding: 2rem 0 0 0; } .header h1 { margin-right: auto; } nav ul { display: flex; flex-direction: row; list-style: none; } .header li { padding-top: 1rem; flex: 0 0 auto; list-style: none; } nav li a { text-decoration: none; text-align: center; } nav a:hover { background-color: #f7f7f7; } nav a { padding: 1rem 2rem; } /* PC時はMENUボタンを非表示 */ button { display: none; } /* PC時はメニューを表示 */ #navi { display: block; } /*768px以下のヘッダー表示 –––––––––––––––––––––––––––––––––––––––––––––––––– */ @media screen and (max-width: 768px){ .header { flex-direction: column; text-align: center; } nav ul { flex-direction: column; } .header h1 { margin-right: 0; } .header li { padding-top: 0; } /* スマホ時はMENUボタンを表示 */ button { display: block; } /* スマホ時はメニューを非表示 */ #navi { display: none; } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/29 06:54
2018/06/01 05:45
2018/06/01 08:55 編集
2018/08/06 10:26