bodyの幅を指定していないのになぜか幅が極端に狭くなっており、bodyに指定していたmarginやpaddingがウインドウを最大化しているとき以外では、縮小するとレイアウトが崩れてしまいます。bodyのpadding,marginとcontainerのpadding,marginを保つ方法を教えてください。
模写サイト http://demo.themegraphy.com/write-ja/
<!DOCTYPE html> <html lang="ja"> <head> </head> <body> <!-- header --> <div class="container"> <header> <div class="header-flex"> <div class="header-left"> <h1><a href="#" class="black">Write</a></h1> <p class="black">書くためのテーマ</p> </div> <div class="header-center"> <nav class="header-nav"> <ul class="globalnav"> <li class="dropdown-btn"> <a href="#" class="black">ホーム<i class="fas fa-angle-down"></i></a> <!-- <ul class="dropdown"> <li><a href="#"> →カスタマイズ</a></li> </ul> --> </li> <li> <a href="#" class="black">ページ<i class="fas fa-angle-down"></i></a> <!-- <ul> <li><a href="#">アイキャッチ画像無しのページ</a></li> <li><a href="#">ページ(全幅テンプレート)</a></li> </ul> --> </li> <li><a href="#" class="black">タイポグラフィー</a></li> <li><a href="#" class="black">お問い合わせ</a></li> </ul> </nav> </div> <div class="header-right"> <div class="icon-search-container" data-ic-class="search-trigger"> <img src="img/search-icon.png" alt=""> <input type="text" class="search-input" data-ic-class="search-input" placeholder="検索..."> </div> </div> </div> </header> </div> <!-- top --> <div class="container"> <div class="top"> <div class="top-img"> <img src="img/cropped-nicole-honeywill-730102-unsplash.jpg" alt=""> </div> </div> </div> </body> </html> * { box-sizing: border-box; } h1, h2, h3, h4, h5, p, ul, li{ padding: 0; margin: 0; } li{ list-style: none; } a{ text-decoration: none; } body{ font-family: Georgia, '游明朝', 'YuMincho', 'Hiragino Mincho ProN', 'Meiryo', serif; line-height: 1.8; margin: 60px 40px; padding: 0 60px; } .black{ color: #111; } .container{ width: 1035px; margin: 0 auto; } .header-flex{ display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 3.5rem; } .header-left p{ font-size: .9rem; } .header-nav ul{ display: flex; } .header-nav ul li{ padding-right: 1.5rem; } .header-nav ul li a{ font-size: .9rem; } .header-nav ul li a:hover{ color: #c49029; } .menu { position: relative; width: 100%; height: 50px; max-width: 1000px; margin: 0 auto; } .menu > li { float: left; width: 25%; /* グローバルナビ4つの場合 */ height: 50px; line-height: 50px; background: rgb(29, 33, 19); } .menu > li a { display: block; color: #fff; } .menu > li a:hover { color: #999; } ul.menu__second-level { visibility: hidden; opacity: 0; z-index: 1; } ul.menu__third-level { visibility: hidden; opacity: 0; } ul.menu__fourth-level { visibility: hidden; opacity: 0; } .menu > li:hover { background: #072A24; -webkit-transition: all .5s; transition: all .5s; } .menu__second-level li { border-top: 1px solid #111; } .menu__third-level li { border-top: 1px solid #111; } .menu__second-level li a:hover { background: #111; } .menu__third-level li a:hover { background: #2a1f1f; } .menu__fourth-level li a:hover { background: #1d0f0f; } /* 下矢印 */ .init-bottom:after { content: ''; display: inline-block; width: 6px; height: 6px; margin: 0 0 0 15px; border-right: 1px solid #fff; border-bottom: 1px solid #fff; -webkit-transform: rotate(45deg); -ms-transform: rotate(45deg); transform: rotate(45deg); } /* floatクリア */ .menu:before, .menu:after { content: " "; display: table; } .menu:after { clear: both; } .menu { *zoom: 1; } .menu > li.menu__single { position: relative; } li.menu__single ul.menu__second-level { position: absolute; top: 40px; width: 100%; background: #072A24; -webkit-transition: all .2s ease; transition: all .2s ease; } li.menu__single:hover ul.menu__second-level { top: 50px; visibility: visible; opacity: 1; } /* 検索ボタンcss */ .icon-search-container { display: inline-block; height: 20px; width: 20px; position: relative; transition: width 0.2s ease-out; backface-visibility: hidden; line-height: 15px; } .icon-search-container.active { width: 285px; border: 1px solid #000; } .icon-search-container.active .fa-times-circle { opacity: 1; } .icon-search-container.active .search-input { width: 200px; } .icon-search-container .fa-search { color: #2980b9; font-size: 30px; position: absolute; top: 7px; left: 8px; cursor: pointer; } .icon-search-container .fa-times-circle { opacity: 0; color: #d9d9d9; font-size: 20px; position: absolute; top: 12px; right: 8px; transition: opacity 0.2s ease-out; cursor: pointer; } .icon-search-container .search-input { position: absolute; cursor: default; left: 45px; top: 6px; width: 0; padding: 5px; border: none; outline: none; font-size: 18px; line-height: 20px; background-color: rgba(255, 255, 255, 0); transition: width 0.2s ease-out; } .top{ margin-bottom: 4rem; } .top-img{ width: 1035px; }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。