Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <header class="header">
  <button class="menu-button">
    <span class="material-symbols-outlined icon">menu</span>
  </button>
  <img
    class="logo"
    src="https://assets.codepen.io/221808/uni-logo.svg"
    width="30"
    height="30"
    alt="UNI"
  />
</header>
<div class="container">
  <nav>
    <button>
      <span class="material-symbols-outlined">local_fire_department</span>急上昇
    </button>
    <button>
      <span class="material-symbols-outlined">music_note</span>音楽
    </button>
    <button>
      <span class="material-symbols-outlined">cruelty_free</span>動物
    </button>
    <button>
      <span class="material-symbols-outlined">sports_esports</span>ゲーム
    </button>
    <button>
      <span class="material-symbols-outlined icon">find_in_page</span>検索
    </button>
    <button>
      <span class="material-symbols-outlined icon">favorite</span>お気に入り
    </button>
    <button>
      <span class="material-symbols-outlined">history</span>
      履歴
    </button>
    <button>
      <span class="material-symbols-outlined icon">settings</span>
      設定
    </button>
    <button>
      <span class="material-symbols-outlined">help</span>
      ヘルプ
    </button>
  </nav>
  <main>
    <div class="inner">
      <div class="photo-list">
        <img
          src="https://assets.codepen.io/221808/a-grid-image-1.jpg"
          width="400"
          height="300"
          alt=""
        />
        <img
          src="https://assets.codepen.io/221808/a-grid-image-2.jpg"
          width="400"
          height="300"
          alt=""
        />
        <img
          src="https://assets.codepen.io/221808/a-grid-image-3.jpg"
          width="400"
          height="300"
          alt=""
        />
        <img
          src="https://assets.codepen.io/221808/a-grid-image-4.jpg"
          width="400"
          height="300"
          alt=""
        />
        <img
          src="https://assets.codepen.io/221808/a-grid-image-5.jpg"
          width="400"
          height="300"
          alt=""
        />
        <img
          src="https://assets.codepen.io/221808/a-grid-image-6.jpg"
          width="400"
          height="300"
          alt=""
        />
        <img
          src="https://assets.codepen.io/221808/a-grid-image-7.jpg"
          width="400"
          height="300"
          alt=""
        />
        <img
          src="https://assets.codepen.io/221808/a-grid-image-8.jpg"
          width="400"
          height="300"
          alt=""
        />
        <img
          src="https://assets.codepen.io/221808/a-grid-image-9.jpg"
          width="400"
          height="300"
          alt=""
        />
      </div>
    </div>
  </main>
</div>

              
            
!

CSS

              
                :root {
  --nav-width: 200px;
}

.container {
  display: grid;
  /* デフォルト状態の列サイズ */
  grid-template-columns: 40px 1fr;
  /* アニメーションの設定 */
  transition: 300ms all;
  gap: 12px;
}

.container.open {
  /* ナビゲーションが開いた状態での列サイズ  */
  grid-template-columns: var(--nav-width) 1fr;
}

nav button {
  width: var(--nav-width);
}

/* その他のスタイル */
body {
  font-family: "游ゴシック Medium", YuGothic, YuGothicM,
    "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  font-size: 16px;
  padding: 12px;
  color: #030303;
}

.header {
  display: grid;
  justify-content: space-between;
  grid-template-areas: "menu logo .";
}

.header .menu-button {
  font-family: inherit;
  line-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-left: 4px;
  padding: 0;
  cursor: pointer;
  border: none;
  border-radius: 50%;
  background-color: transparent;
  grid-area: menu;
}

.header .logo {
  grid-area: logo;
}

.menu-button:is(:hover, :active) {
  background-color: #0000001a;
}

nav {
  padding-top: 12px;
}

nav .logo {
  margin-left: 10px;
}

nav button {
  font-size: 16px;
  display: flex;
  align-items: center;
  height: 40px;
  padding-left: 12px;
  cursor: pointer;
  transition: 300ms all;
  color: #333;
  border: none;
  outline: none;
  background-color: transparent;
  appearance: none;
  gap: 24px;
}

nav button:hover {
  background-color: #0000001a;
}

nav button .icon {
  font-size: 24px;
}

nav button:hover .icon {
  transition: 300ms all;
}

main {
  background: #ffffff;
}

main .photo-list {
  display: grid;
  align-items: start;
  margin-top: 12px;
  padding-right: 16px;
  padding-left: 16px;
  gap: 16px;
  grid-auto-rows: 260px;
  grid-template-columns: repeat(3, minmax(100px, 1fr));
}

main .photo-list img {
  width: 100%;
  height: 100%;
  border-radius: 4px;
  object-fit: cover;
}

              
            
!

JS

              
                // メニューボタンをクリックするたびに、.containerのCSSに.openを着脱するための処理です
const container = document.querySelector(".container");

document.querySelector(".menu-button").addEventListener("click", () => {
  container.classList.toggle("open");
});

              
            
!
999px

Console