First, what is Flex?
Flex is a form of layout introduced in CSS3 that gives you a very flexible and efficient way to control the arrangement and alignment of elements, which most people call elastic layouts.
Second, how to use Flex?
Any container can be specified as a flex layout
1{2 display:flex; 3 }
Iii. Basic terminology of Flex
- The element that uses the flex layout is called the Flex container (Flex container), and its child element is the Flex element (Flex Item).
- The Flex container contains two perpendicular axes, the main axis and the secondary axis (cross axis).
- The flex element is arranged along the spindle from the start of the spindle (main start) to the end of the spindle (main end) .
- If the Flex container contains multiple lines of flex elements, the Flex line (Flex lines) is arranged along the secondary axis from the start of the secondary axis (cross start) to the secondary axis end point (cross end) .
- The spindle space occupied by a single flex element is called the spindle length (main size), and the occupied secondary axis space is called the secondary axis length (cross size).
Four, there are six properties set on the parent container to control how the child elements are displayed:
Properties |
meaning |
flex-direction |
Spindle direction |
flex-wrap |
Line break Style |
flex-flow |
Abbreviated form of the first two |
justify-content |
Spindle Alignment |
align-items |
Alignment of the secondary axis of a single line |
align-content |
Sub-axis alignment for multiple rows |
Five, Flex-direction, set the alignment direction of the spindle, There are four values:
row
(default): The spindle is in the horizontal direction, starting at the left.
row-reverse
: The spindle is in the horizontal direction, starting at the right end.
column
: The spindle is in the vertical direction and the starting point is in the upper edge.
column-reverse
: The spindle is in the vertical direction and the starting point is in the lower edge.
1 <! DOCTYPE html>2 3 4 5 <meta charset= "UTF-8" >6 <meta name= "viewport" content= "Width=device-width, initial-scale=1.0" >7 <meta http-equiv= "x-ua-compatible" content= "Ie=edge" >8 <title>flex Layout-by ghostwu</title>9 <style>Ten #box{ One Display:Flex; A flex-direction:Row; -} - #box Div{ the width:100px; - Height:100px; - background:#09f; - margin:10px; +} - </style> + A at <body> - <div id= "box" > - <div>1</div> - <div>2</div> - <div>3</div> - <div>4</div> in <div>5</div> - <div>6</div> to <div>7</div> + <div>8</div> - <div>9</div> the <div>10</div> * <div>11</div> $ <div>12</div>Panax Notoginseng <div>13</div> - <div>14</div> the </div> + </body> A the
Flex-direction is set to row:
Flex-direction set to Row-reverse:
Flex-direction is set to column, below I only intercepted the first 5 Div, after the interception, the picture occupies too much position, affects the experience.
Flex-direction set to Column-reverse:
Six, Flex-wrap: Define child elements more than one line, how to wrap, common property values:
- NoWrap (default): The default is no line break.
- Wrap: Wrap, second line below first line, left to right
- Wrap-reverse: newline, second line above first row, left to right
1{2 display: flex; 3 flex-direction: row; 4 flex-wrap: nowrap; 5 }
Flex-wrap:nowrap;
Flex-wrap:wrap;
Flex-wrap:wrap-reverse;
Seven, Flex-flow: is the shorthand form of flex-direction and Flex-wrap, the default is row nowrap
1 #box{2 Display:Flex;3 /*Flex-flow:row nowrap;*/4 /*Flex-flow:row Wrap;*/5 /*Flex-flow:row Wrap-reverse;*/6 /*Flex-flow:row-reverse Wrap-reverse;*/7 Flex-flow:Column Wrap;8}
Viii. justify-content: Sub-elements in the spindle alignment
flex-start
(default): Align Left
flex-end
: Align Right
center
: Center
space-between
: Justified, the interval between items is equal.
space-around
: The intervals on each side of the item are equal.
1 #box{2 Display:Flex;3 Flex-flow:Row Wrap;4 /*Justify-content:flex-start;*/5 /*Justify-content:flex-end;*/6 /*Justify-content:center;*/7 /*Justify-content:space-between;*/8 justify-content:Space-around;9}
Here mainly to clarify the difference between Space-between and Space-around Justify-content:space-between;
Justify-content:space-around;
CSS3 Flexible Box Model Flex Quick Start and get started 1