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本ノック】0043_align-itemsの5つの値(stretch, flex-start, flex-end, center, baseline)の違いが分かるサンプルを作成せよ。

Posted at

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

はじめに

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

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

align-items とは

justify-content が主軸(横方向)の配置を決めるのに対し、align-items は交差軸(横方向)の配置を決めます。(flex-directioncolumn の場合は逆)

高さの違うアイテムが、コンテナの中でどのように整列するかをイメージしてください。

  • stretch(デフォルト):アイテムの高さがしてされていない場合、コンテナの高さに合わせて引き伸ばされる。
  • flex-start:コンテナの上端に揃えられる
  • flex-end:コンテナの下端に揃えられる
  • center:コンテナの中央に揃えられる
  • baseline:アイテムの中のテキストのベースライン(下線)に揃えられる

作成したコード

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本ノック 0043</title>
</head>
<body>
    <main>
      <h1>align-items プロパティ</h1>

      <section>
        <h2>align-items: stretch</h2>
        <div style="display: flex; align-items: stretch; height: 200px; border: 1px solid #ccc;">
    
          <div style="width: 100px; background-color: azure;">1</div>
          <div style="width: 100px; background-color: bisque;">2</div>
          <div style="width: 100px; background-color: burlywood;">3</div>
          
        </div>
      </section>

      <section>
        <h2>align-items: flex-start</h2>
        <div style="display: flex; align-items: flex-start; height: 200px; border: 1px solid #ccc;">
    
          <div style="width: 100px; height: 60px; background-color: azure;">1</div>
          <div style="width: 100px; height: 100px; background-color: bisque;">2</div>
          <div style="width: 100px; height: 80px; background-color: burlywood;">3</div>
          
        </div>
      </section>

      <section>
        <h2>align-items: flex-end</h2>
        <div style="display: flex; align-items: flex-end; height: 200px; border: 1px solid #ccc;">
    
          <div style="width: 100px; height: 60px; background-color: azure;">1</div>
          <div style="width: 100px; height: 100px; background-color: bisque;">2</div>
          <div style="width: 100px; height: 80px; background-color: burlywood;">3</div>
          
        </div>
      </section>

      <section>
        <h2>align-items: center</h2>
        <div style="display: flex; align-items: center; height: 200px; border: 1px solid #ccc;">
    
          <div style="width: 100px; height: 60px; background-color: azure;">1</div>
          <div style="width: 100px; height: 100px; background-color: bisque;">2</div>
          <div style="width: 100px; height: 80px; background-color: burlywood;">3</div>
          
        </div>
      </section>

      <section>
        <h2>align-items: baseline</h2>
        <div style="display: flex; align-items: baseline; height: 200px; border: 1px solid #ccc;">
    
          <div style="width: 100px; height: 60px; background-color: azure;">1</div>
          <div style="width: 100px; height: 100px; background-color: bisque;">2</div>
          <div style="width: 100px; height: 80px; background-color: burlywood;">3</div>
          
        </div>
      </section>

      
    </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?