CSSフレックスプロパティ
例
内容に関係なく、すべてのフレキシブルアイテムを同じ長さにします。
#main div {
-ms-flex: 1; /* IE 10 */
flex: 1;
}
ヒント:以下の「自分で試してみてください」の例をさらに示します。
定義と使用法
プロパティは、次のflex
略記プロパティです。
プロパティは、フレキシブルアイテムのflex
フレキシブル長を設定します。
注:要素がフレキシブルアイテムでない場合、flex
プロパティは効果がありません。
デフォルト値: | 01自動 |
---|---|
遺伝性の: | いいえ |
アニメート可能: | はい、個々のプロパティを参照してください。アニメート可能について読む |
バージョン: | CSS3 |
JavaScript構文: | オブジェクト.style.flex = "1" |
ブラウザのサポート
表の数字は、プロパティを完全にサポートする最初のブラウザバージョンを示しています。
数字の後に-webkit-、-ms-、または-moz-が続く場合は、プレフィックスを使用して機能した最初のバージョンを指定します。
Property | |||||
---|---|---|---|---|---|
flex | 29.0 21.0 -webkit- |
11.0 10.0 -ms- |
28.0 18.0 -moz- |
9.0 6.1 -webkit- |
17.0 |
CSS構文
flex: flex-grow flex-shrink flex-basis|auto|initial|inherit;
プロパティ値
Value | Description |
---|---|
flex-grow | A number specifying how much the item will grow relative to the rest of the flexible items |
flex-shrink | A number specifying how much the item will shrink relative to the rest of the flexible items |
flex-basis | The length of the item. Legal values: "auto", "inherit", or a number followed by "%", "px", "em" or any other length unit |
auto | Same as 1 1 auto. |
initial | Same as 0 1 auto. Read about initial |
none | Same as 0 0 auto. |
inherit | Inherits this property from its parent element. Read about inherit |
その他の例
例
メディアクエリflex
と一緒に使用して、さまざまな画面サイズ/デバイス用にさまざまなレイアウトを作成します。
.flex-container {
display: flex;
flex-wrap: wrap;
}
.flex-item-left {
flex: 50%;
}
.flex-item-right {
flex: 50%;
}
/* Responsive layout - makes a one column layout (100%) instead of a two-column
layout (50%) */
@media (max-width: 800px) {
.flex-item-right,
.flex-item-left {
flex: 100%;
}
}
関連ページ
CSSチュートリアル:CSSフレキシブルボックス
CSSリファレンス:flex-basisプロパティ
CSSリファレンス:flex-directionプロパティ
CSSリファレンス:flex-flowプロパティ
CSSリファレンス:flex-growプロパティ
CSSリファレンス:flex-shrinkプロパティ
CSSリファレンス:flex-wrapプロパティ
HTML DOMリファレンス:flexプロパティ