Flexboxレイアウトの簡潔なガイド-パート1


皆さんこんにちは!👋 前回はグリッドボックスレイアウトについて書いたので、Flexboxレイアウトについて書きます.

目次

  • Introduction to Flexbox

  • Flex Container
  • Flex Container Properties
  • Flexbox入門

    To flex or not to flex, that is the question! I think that Flexbox is really useful when you want to build a responsive website. Flexbox gives you the power to lay out elements the way you want and easily align elements on your web pages and components. It is really easy to center things when you use Flexbox, I will show you how soon. Moreover, Flexbox allow you change the widths and heights of the Flex Items so that it fits the available spaces, this is why it is good for responsive design. Flexbox deals with directional flow of the Flex Items, whether it be row or column direction, so it can be said that Flexbox is a one-dimensional layout.

    The below image shows the main concept of how Flexbox lay out it's Flex Items base on the flow direction. Note: the main and cross axis switch when you change the flow direction.

    (クレジット:メインとクロス軸のイメージ-css-tricks )
    (ストーリータイム:私がインタビューをしていたとき、私は古いウェブサイトのための反応的なデザインに取り組みました)、そして、このウェブサイトはFlexboxの前に構築されました.😫 しかし、今私自身のプロジェクトでは、Flexboxはとても簡単になります.)

    フレックスコンテナ

    Anyway, to begin using Flexbox, just slap display: flex on your container element, this element will now be known as the Flex Container, and all the immediate children of this element will be known as Flex Items.

    There are many Flex Container CSS properties that will allow you to move the Flex Items about, lets take a look at them.

    As always, I will show some examples with the properties but you really do learn best when you try it out yourself. Lets start with some basic set up, a Flex Container with defined size, and display: flex on it. You will notice that, each of the Flex Items loses it's block property and are now lined up in a row next to each other.

    
    .flex-container {
      width: 400px;
      height: 400px;
      outline: 1px solid black;
      display: flex;
    }
    
    .flex-item {
      width: 60px;
      height: 50px;
      outline: 1px solid black;
    }
    
    

    フレックスコンテナプロパティ

    The properties I will talk about are flex-direction , flex-wrap , justify-content , align-items , align-content and gap .

    There is a bit of a pattern when you start using Flexbox, so don't worry if you can't remember them, you can always look them up or just test them using the DevTool.

    • flex-direction determines which direction you want the Flex Items to flow, row (default), row-reverse, column or column-reverse.
    Example of changing the flex-direction
  • flex-wrap 場合は、フレックスアイテムをラップしたい場合は、これ以上の部屋は、デフォルトではラップされていません.オプションはラップ、ラップ、ラップは逆です.これは、Flex項目のサイズに応じてラップが設定されていない場合、縮小またはオーバーフローします.
  • 変更例flex-wrap
  • justify-content あなたがフレックス項目を移動し、メイン軸(水平方向の場合は、行は、垂直方向の場合は、列の列)に整列することができます.最初にそれを整列させることができますflex-start またはflex-end . またはあなたがそれを中心にしたい場合は、使用することができますcenter . また、スペースを使用することができますspace-evenly , space-around , and space-between .
  • 変更例justify-content
  • align-items フレックス項目を移動し、クロス軸(垂直方向の方向が行、水平方向の場合は水平方向)にそれらを整列することができます.最初にそれを整列させることができますflex-start またはflex-end . またはあなたがそれを中心にしたい場合は、使用することができますcenter . また、stretch そして、クロス軸の残りのスペースの全てを取り上げる.
  • 変更例align-items and justify-content
  • align-content 追加のスペースがある場合は、フレックスコンテナーの行を移動し、フレックスコンテナーの行または列を整列することができます.(これはよく使いませんので、よく説明できません)😩.
  • 変更例align-content
  • gap グリッドボックスのように行ギャップと列のギャップを設定します.
  • 概要


    これで、Flexboxを使い始める方法を知っています.あなたは、応答コンポーネントとページをデザインすることができますjustify-content , align-items and align-content . また、Flex項目のフロー方向とラップ動作を定義することもできますflex-direction and flex-wrap . ちょうど2つの軸が「メイン」と呼ばれているのを思い出してください.
    (ボーナス:フレックスアイテム自体は、ちょうどFlat Containerであることができます)を置いてくださいdisplay: flex それに、すべてのFlexコンテナプロパティを使用できます.
    それは今日のすべて、私は私のポストを短くし、消化を維持したい.次回は、フレックスアイテムのプロパティとどのように彼らと一緒に遊ぶことができる話をします.いつものように、この有用な、または混乱または単に一般的なフィードバックを見つける場合はコメントを残してください😀. 他のリソースを好むならW3School ここで、インタラクティブな例やMDN Docs flexboxのより詳細な説明については.