元々あるソースをいじってコードを組んでいたのですが、
スマホ表示の時にナビメニューを縦並びにしたとき、ナビのリストが中央に寄らなくなってしまいました。
このようになってしまいます
どうすれば中央に寄るようになるのでしょうか?
下記はコードペンURLです
試した事
ナビにwidth:100%;
li にwidth 指定
下記がちゃんと中央にきているコードペンURLです
<header id="header"> <nav id="navi"> <div class="container flex"> <h1 class="site-title"> <img src="/img/ETELLIA-logo-white.png" alt="ロゴ" class="logo"> </h1><!-- /.site-title --> <div class="inner"> <div class="list-nav-box"> <ul class="list-nav"> <li><a href="#"> ホーム </a> </li> <li><a href="#about"> Aについて </a> </li> <li><a href="#medical"> A案内 </a> </li> <li><a href="#first-time"> 初めての方へ </a> </li> <li><a href="#news"> テキスト </a> </li> <li><a href="#access"> アクセス </a> </li> </ul><!-- /.list-nav --> </div><!-- /.list-nav-box --> <a href="#contact" class="contact"> WEB予約はこちら </a> </div><!-- /.inner --> </div><!-- /.container --> </nav> <!-- /#navi --> <div class="hamburger js-hamburger"> <span></span> <span></span> <span></span> </div> <!-- /.hamburger --> <div id="burger-musk"></div> </header> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
a { text-decoration: none; } img { max-width: 100%; vertical-align: bottom; } li { list-style: none; } /* ハンバーガ―メニュー */ .hamburger { display: none; } #navi .logo { width:76px; height:55px; object-fit: contain; } .section-title span.en { font-size: 2rem; display: block; text-align: center; } .section-title span.ja { font-size: 1rem; display: block; text-align: center; } /*ドロップシャドウ*/ .drop-shadow { box-shadow: 0px 4px 4px 0px #00000040; } .container { max-width: 1920px; margin: 0 auto; padding:0 14%; width: 100%; } /*------------------------------------------- header -------------------------------------------*/ /* #header{ position:relative; z-index:10; } */ /*------------------------------------------- navi -------------------------------------------*/ #navi { position: fixed; background:#3990E3; width: 100%; height: 70px; } /* ハンバーガーメニューがクリックされた際に、jQueryで#naviにactiveクラスを追加して、 メニューを表示させる。 */ #navi.active { opacity: 1; } /* #navi .site-title{ position:absolute; left:210px; z-index:-5; } */ #navi .container{ height:70px; } .flex { display: flex; align-items: center; justify-content:space-between; } #navi .site-title img{ max-width:none; } #navi .inner{ white-space:nowrap; } #navi .list-nav-box{ display: inline-block; } #navi .list-nav { display: flex; } #navi .list-nav li{ margin-right:50px; } #navi .list-nav li a { display:block; color: #fff; font-weight: bold; font-size:1.2rem; width:100%; text-align:center; } #navi .list-nav li a:hover { opacity: .7; } #navi .contact { display:inline-block; width:190px; padding:5px 30px; background-color: #D3BC9F; border-radius: 20px; color:#fff; font-weight:bold; } .sp-contact{ display:none; } /*レスポンシブ-スマホ*/ @media(max-width:768px) { /*------------------------------------------- Menu -------------------------------------------*/ #navi{ display:none; } #navi.open { display:block; opacity: 1; } #navi { width: 100%; height: 100vh; background: rgb(57, 144, 227,.7); padding: 25px; position: fixed; top: 0; left:0; bottom: 0; opacity: 0; transition: 0.5s; z-index: 20; } #navi .inner{ display:block; width:100%; } #navi .container{ height:auto; } #navi .site-title{ display:none; } #navi .contact{ display:none; } #navi .list-nav { flex-direction: column; width:100%; } #navi ul.nav-menu { margin-bottom: 30px; } #navi ul li { padding: 10px 0; margin-bottom:22px; } #navi .logo{ display:none; } .sp-contact{ display:block; } .sp-contact img{ width:70px; height:55px; } /*------------------------------------------- Menu -------------------------------------------*/ .flex { display: flex; align-items: center; }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/06/04 17:31