PCレイアウト時にもナビゲーションを隠し、ハンバーガーメニューを付け、全画面で表現をする機会が増えてきました。サイトに合わせた構成をいくつか覚えておきましょう。
https://twitter.com/pulpxstyle/status/1321272801211211776
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>cssでclickイベントを設定する</title> <link rel="stylesheet" href="css/style.css"> </head> <body> <header> <h1>サイトタイトル</h1> <input type="checkbox" id="click"> <label for="click" id="ham-bar"><span></span></label> <nav class="g-nav"> <ul> <li><a href="#">ABOUT<span>私たちについて</span></a></li> <li><a href="#">SERVICE<span>サービス紹介</span></a></li> <li><a href="#">COMPANY<span>会社概要</span></a></li> <li><a href="#">RECRUIT<span>採用情報</span></a></li> <li><a href="#">NEWS<span>お知らせ</span></a></li> <li><a href="#">CONTACT<span>お問い合わせ</span></a></li> </ul> </nav> </header> <main class="main-content"> <h2>メインコンテンツ</h2> </main> </body> </html>
@charset "utf-8"; html{box-sizing:border-box;-webkit-text-size-adjust:100%}*,:after,:before{background-repeat:no-repeat;box-sizing:inherit}:after,:before{text-decoration:inherit;vertical-align:inherit}*{padding:0;margin:0}audio:not([controls]){display:none;height:0}hr{overflow:visible}article,aside,details,figcaption,figure,footer,header,main,menu,nav,section,summary{display:block}summary{display:list-item}small{font-size:80%}[hidden],template{display:none}abbr[title]{border-bottom:1px dotted;text-decoration:none}a{background-color:transparent;-webkit-text-decoration-skip:objects}a:active,a:hover{outline-width:0}code,kbd,pre,samp{font-family:monospace,monospace}b,strong{font-weight:bolder}dfn{font-style:italic}mark{background-color:#ff0;color:#000}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}input{border-radius:0}[role=button],[type=button],[type=reset],[type=submit],button{cursor:pointer}[disabled]{cursor:default}[type=number]{width:auto}[type=search]{-webkit-appearance:textfield}[type=search]::-webkit-search-cancel-button,[type=search]::-webkit-search-decoration{-webkit-appearance:none}textarea{overflow:auto;resize:vertical}button,input,optgroup,select,textarea{font:inherit}optgroup{font-weight:700}button{overflow:visible}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:0;padding:0}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button:-moz-focusring{outline:1px dotted ButtonText}[type=reset],[type=submit],button,html [type=button]{-webkit-appearance:button}button,select{text-transform:none}button,input,select,textarea{background-color:transparent;border-style:none;color:inherit}select{-moz-appearance:none;-webkit-appearance:none}select::-ms-expand{display:none}select::-ms-value{color:currentColor}legend{border:0;color:inherit;display:table;max-width:100%;white-space:normal}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}img{border-style:none;vertical-align: bottom}progress{vertical-align:baseline}svg:not(:root){overflow:hidden}audio,canvas,progress,video{display:inline-block}@media screen{[hidden~=screen]{display:inherit}[hidden~=screen]:not(:active):not(:focus):not(:target){position:absolute!important;clip:rect(0 0 0 0)!important}}[aria-busy=true]{cursor:progress}[aria-controls]{cursor:pointer}[aria-disabled]{cursor:default}::-moz-selection{background-color:#b3d4fc;color:#000;text-shadow:none}::selection{background-color:#b3d4fc;color:#000;text-shadow:none}ul,ol{list-style:none;}a{text-decoration:none;}.wrapper{overflow:hidden;}body{overflow-y:scroll;} header{ width: 100%; height: 100px; background-color: beige; position: fixed; top: 0; left: 0; } h1{ text-align: center; font-size: 40PX; line-height: 100PX; } .main-content{ width: 100%; height: 300vh; } h2{ text-align: center; padding-top: 300px; } /* ハンバーガー部分 */ #ham-bar{ display: block; width: 100px; height: 100px; background-color: #dfdfdf; position: absolute; top: 0; right: 30px; z-index: 200; cursor: pointer; } #ham-bar>span{ display: block; width: 60px; height: 2px; background-color: #222; position: absolute; top: 0; right: 0; bottom: 25px; left: 0; margin: auto; transition: 0.2s; } #ham-bar>span::after{ display: block; content: ""; width: 60px; height: 2px; background-color: #222; position: absolute; top: 50px; right: 0; bottom: 0; left: 0; margin: auto; transition: 0.2s; } #click:checked+#ham-bar>span{ bottom: 0; transform: rotate(45deg); } #click:checked+#ham-bar>span::after{ top: 0; transform: rotate(-90deg); } /* ナビゲーション */ .g-nav{ width: 100%; height: 100vh; background-color: #377174; position: fixed; top: 0; left: 0; z-index: 100; transform: translateX(0); transition: 0.2s; } #click:checked~.g-nav{ transform: translateX(0); } .g-nav>ul{ padding: 10vh 20%; display: flex; flex-wrap: wrap; } .g-nav li{ width: 50%; margin-bottom: 30px; } .g-nav a{ display: block; color: #FFF; font-size: 20px; } .g-nav a>span{ display: block; font-size: 28px; font-weight: bold; } .g-nav a:hover>span{ text-decoration-line: underline;/* 線の種類 */ text-decoration-thickness: 5px;/* 線の太さ */ text-decoration-color: coral;/* 線の色 */ text-underline-offset: 5px;/* 文字と線の間隔 */ }