0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【フロントエンド1000本ノック】0045_flex-growを使い、特定のアイテムだけが余白をすべて埋めるように伸びるレイアウトを作成せよ。

Posted at

この記事は人間が書きました

はじめに

こんにちは、赤神です!
この記事は、「1000本ノック」という取り組みの中のフロントエンドのための課題の1つです。

「1000本ノックとは」
https://qiita.com/sora_akagami/items/c8da4296dea3823376ca

flex-grow とは

flex-grow は、Flexコンテナ内に余白がある場合に、Flexアイテムがどのくらいの割合でその余白を分け合うかを決めるプロパティです。このプロパティは子要素(Flexアイテム)に指定します。

値は数値で、デフォルトは 0 (伸びない)です。
いくつか例を見てみましょう。

  • 例1:3つのアイテムのうち、1つだけに flex-grow: 1; を指定
    • →そのアイテムが全ての余白を独り占めにして伸びます。
  • 例2:3つのアイテムのうち、2つに flex-grow: 1; を指定
    • →2つのアイテムが余白を半分ずつ分け合って均等に伸びます。
  • 例3:1つ目に flex-grow: 2;、2つ目に flex-grow: 1; を指定
    • →1つ目のアイテムが、2つ目のアイテムの2倍の割合で余白を分け合って伸びます。

作成したコード

index.html
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>フロントエンド1000本ノック 0045</title>
</head>
<body>
    <main>
      <h1>flex-grow プロパティ</h1>

      <div style="display: flex;  width: 600px; height: 200px; border: 1px solid #ccc;">

        <div style="width: 100px; background-color: azure;">1</div>
        <div style="width: 100px; flex-grow: 1; background-color: bisque;">2</div>
        <div style="width: 100px; background-color: burlywood;">3</div>

      </div>

    </main>
    <footer>
      <p>Copyright 2025</p>
      <p>フロントエンド1000本ノック</p>
    </footer>

</body>
</html>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?