place-content
åºçº¿
广æ³å¯ç¨
èª 2020å¹´1æ èµ·ï¼æ¤ç¹æ§å·²å¨ä¸»æµæµè§å¨ä¸å¾å°æ¯æï¼å¯å¨å¤§å¤æ°è®¾å¤åæµè§å¨çæ¬ä¸æ£å¸¸ä½¿ç¨ã
place-content 屿§æ¯align-content å justify-contentçç®åã使ç¨è¿ä¸¤ä¸ªå±æ§çå¼å¯ä»¥ç¨äºä»»ä½çå¸å±æ
åµã
å°è¯ä¸ä¸
place-content: end space-between;
place-content: space-around start;
place-content: start space-evenly;
place-content: end center;
place-content: end;
<section class="default-example" id="default-example">
<div class="example-container">
<div class="transition-all" id="example-element">
<div>One</div>
<div>Two</div>
<div>Three</div>
</div>
</div>
</section>
#example-element {
border: 1px solid #c5c5c5;
display: grid;
grid-template-columns: 60px 60px;
grid-auto-rows: 40px;
height: 180px;
width: 220px;
}
#example-element > div {
background-color: rgba(0, 0, 255, 0.2);
border: 3px solid blue;
}
è¯æ³
/* Positional alignment */
/* align-content does not take left and right values */
place-content: center start;
place-content: start center;
place-content: end left;
place-content: flex-start center;
place-content: flex-end center;
/* Baseline alignment */
/* justify-content does not take baseline values */
place-content: baseline center;
place-content: first baseline space-evenly;
place-content: last baseline right;
/* Distributed alignment */
place-content: space-between space-evenly;
place-content: space-around space-evenly;
place-content: space-evenly stretch;
place-content: stretch space-evenly;
/* Global values */
place-content: inherit;
place-content: initial;
place-content: unset;
第ä¸ä¸ªå¼ä¸º align-content 屿§ï¼ç¬¬äºä¸ªå¼ä¸º justify-content .
è¦åï¼å¦ææ²¡æè®¾ç½®ç¬¬äºä¸ªå¼ï¼é£ä¹ç¬¬äºä¸ªçå¼ä¸ç¬¬ä¸ä¸ªç¸çï¼æ¤åææ¯ç¬¬ä¸ä¸ªå¼å¯¹ä¸¤ä¸ªå±æ§é½æ¯ææçãå¦æè®¾ç½®çè¿ä¸ªå¼å¯¹ä¸¤ä¸ªå±æ§é½æ æï¼é£ä¹æ´ä¸ªè®¾ç½®çå¼å°±æ¯æ æçã
åèå¼
start-
ææçåå ç´ å å å¨ç¶å ç´ ä¸åéç轴线ä¸çèµ·ç¹å¯¹é½ã
end-
ææçåå ç´ å å å¨ç¶å ç´ ä¸åéç轴线ä¸çç»ç¹å¯¹é½
flex-start-
ææçåå ç´ å å å¨ç¶å ç´ ç主轴æäº¤åè½´ä¸èµ·ç¹å¯¹é½ï¼ä¸»è¦åå³äº flex-direction ç设置ã ä» éç¨äº flex å¸å±çåå ç´ .ã妿ç¶å ç´ æ²¡æè®¾ç½®ä¸º flexï¼
flex-startå°è¢«è§ä¸ºstart flex-end-
ææçåå ç´ å å å¨ç¶å ç´ ç主轴æäº¤åè½´ä¸ç»ç¹å¯¹é½ï¼ä¸»è¦åå³äº flex-direction ç设置ã ä» éç¨äº flex å¸å±çåå ç´ ã妿ç¶å ç´ æ²¡æè®¾ç½®ä¸º flexï¼
flex-endå°è¢«è§ä¸ºend center-
ææçåå ç´ å å å¨ç¶å ç´ çä¸é´å¯¹é½
left-
The items are packed flush to each other toward the left edge of the alignment container. If the propertyâs axis is not parallel with the inline axis, this value behaves like
start. right-
The items are packed flush to each other toward the right edge of the alignment container in the appropriate axis. If the propertyâs axis is not parallel with the inline axis, this value behaves like
start. space-between-
The items are evenly distributed within the alignment container. The spacing between each pair of adjacent items is the same. The first item is flush with the main-start edge, and the last item is flush with the main-end edge.
baseline first baselinelast baseline-
Specifies participation in first- or last-baseline alignment: aligns the alignment baseline of the boxâs first or last baseline set with the corresponding baseline in the shared first or last baseline set of all the boxes in its baseline-sharing group. The fallback alignment for
first baselineisstart, the one forlast baselineisend. space-around-
The items are evenly distributed within the alignment container. The spacing between each pair of adjacent items is the same. The empty space before the first and after the last item equals half of the space between each pair of adjacent items.
space-evenly-
The items are evenly distributed within the alignment container. The spacing between each pair of adjacent items, the main-start edge and the first item, and the main-end edge and the last item, are all exactly the same.
stretch-
If the combined size of the items is less than the size of the alignment container, any
auto-sized items have their size increased equally (not proportionally), while still respecting the constraints imposed bymax-height/max-width(or equivalent functionality), so that the combined size exactly fills the alignment container
å½¢å¼è¯æ³
place-content =
<'align-content'> <'justify-content'>?
<align-content> =
normal |
<baseline-position> |
<content-distribution> |
<overflow-position>? <content-position>
<justify-content> =
normal |
<content-distribution> |
<overflow-position>? [ <content-position> | left | right ]
<baseline-position> =
[ first | last ]? &&
baseline
<content-distribution> =
space-between |
space-around |
space-evenly |
stretch
<overflow-position> =
unsafe |
safe
<content-position> =
center |
start |
end |
flex-start |
flex-end
示ä¾
>å°å 容æ¾å ¥å¼¹æ§å®¹å¨ä¸
<div id="container">
<div class="small">Lorem</div>
<div class="small">Lorem<br />ipsum</div>
<div class="large">Lorem</div>
<div class="large">Lorem<br />ipsum</div>
<div class="large"></div>
<div class="large"></div>
</div>
CSS
#container {
display: flex;
height: 240px;
width: 240px;
flex-wrap: wrap;
background-color: #8c8c8c;
writing-mode: horizontal-tb; /* Can be changed in the live sample */
direction: ltr; /* Can be changed in the live sample */
place-content: flex-end center; /* Can be changed in the live sample */
}
div > div {
border: 2px solid #8c8c8c;
width: 50px;
background-color: #a0c8ff;
}
.small {
font-size: 12px;
height: 40px;
}
.large {
font-size: 14px;
height: 50px;
}
ç»æ
è§è
| è§è |
|---|
| CSS Box Alignment Module Level 3> # place-content> |
| åå§å¼ | 该ç®åæå¯¹åºçæ¯ä¸ªå±æ§ï¼
|
|---|---|
| éç¨å ç´ | multi-line flex containers |
| æ¯å¦æ¯ç»§æ¿å±æ§ | å¦ |
| 计ç®å¼ | 该ç®åæå¯¹åºçæ¯ä¸ªå±æ§ï¼
|
| å¨ç»ç±»å | 离æ£å¼ |
æµè§å¨å ¼å®¹æ§
åè§
- CSS Flexbox Guide: Basic Concepts of Flexbox
- CSS Flexbox Guide: Aligning items in a flex container
- CSS Grid Guide: Box alignment in CSS Grid layouts
- CSS Box Alignment
- The
align-contentproperty - The
justify-contentproperty