inset-block
åºçº¿
广æ³å¯ç¨
*
èª 2021å¹´4æ èµ·ï¼æ¤ç¹æ§å·²å¨ä¸»æµæµè§å¨ä¸å¾å°æ¯æï¼å¯å¨å¤§å¤æ°è®¾å¤åæµè§å¨çæ¬ä¸æ£å¸¸ä½¿ç¨ã
* æ¤ç¹æ§çæäºé¨åçæ¯æç¨åº¦å¯è½ææä¸åã
CSS 屿§ inset-block å®ä¹äºå
ç´ çé»è¾åé¦ååæ«åç§»ï¼å¹¶æ ¹æ®å
ç´ ç书忍¡å¼ãè¡å
æ¹ååææ¬æå对åºè³å®ä½åç§»ãæ ¹æ® writing-modeãdirection å text-orientation æå®ä¹çå¼ï¼æ¤å±æ§å¯¹åºäº top å bottomï¼æè
right å left 屿§ã
å°è¯ä¸ä¸
inset-block: 10px 20px;
writing-mode: horizontal-tb;
inset-block: 20px 40px;
writing-mode: vertical-rl;
inset-block: 5% 20%;
writing-mode: horizontal-tb;
inset-block: 1rem auto;
writing-mode: vertical-lr;
<section id="default-example">
<div class="example-container">
<div id="example-element">I am absolutely positioned.</div>
<p>
As much mud in the streets as if the waters had but newly retired from the
face of the earth, and it would not be wonderful to meet a Megalosaurus,
forty feet long or so, waddling like an elephantine lizard up Holborn
Hill.
</p>
</div>
</section>
.example-container {
border: 0.75em solid #ad1457;
padding: 0.75em;
text-align: left;
position: relative;
width: 100%;
min-height: 200px;
}
#example-element {
background-color: #07136c;
border: 6px solid #ffa000;
color: white;
position: absolute;
inset: 0;
}
屿§ææ
æ¤å±æ§ä¸ºä¸å CSS 屿§çç®å屿§ï¼
è¯æ³
css
/* é¿åº¦å¼ */
inset-block: 3px 10px;
inset-block: 2.4em 3em;
inset-block: 10px; /* åºç¨äºåé¦ååæ« */
/* å
å«åç宽度æé«åº¦çç¾åæ¯ */
inset-block: 10% 5%;
/* å
³é®è¯å¼ */
inset-block: auto;
/* å
¨å±å¼ */
inset-block: inherit;
inset-block: initial;
inset-block: revert;
inset-block: revert-layer;
inset-block: unset;
åå¼
inset-block 屿§çåå¼ä¸ left 屿§ç¸åã
å½¢å¼å®ä¹
| åå§å¼ | 该ç®åæå¯¹åºçæ¯ä¸ªå±æ§ï¼
|
|---|---|
| éç¨å ç´ | positioned elements |
| æ¯å¦æ¯ç»§æ¿å±æ§ | å¦ |
| Percentages | logical-height of containing block |
| 计ç®å¼ | 该ç®åæå¯¹åºçæ¯ä¸ªå±æ§ï¼
|
| å¨ç»ç±»å | a length, percentage or calc(); |
å½¢å¼è¯æ³
inset-block =
<'top'>{1,2}
<top> =
auto |
<length-percentage> |
<anchor()> |
<anchor-size()>
<length-percentage> =
<length> |
<percentage>
<anchor()> =
anchor( <anchor-name>? &&
<anchor-side> , <length-percentage>? )
<anchor-size()> =
anchor-size( [ <anchor-name> || <anchor-size> ]? , <length-percentage>? )
<anchor-name> =
<dashed-ident>
<anchor-side> =
inside |
outside |
top |
left |
right |
bottom |
start |
end |
self-start |
self-end |
<percentage> |
center
<anchor-size> =
width |
height |
block |
inline |
self-block |
self-inline
示ä¾
>设置åé¦ååæ«åç§»
HTML
html
<div>
<p class="exampleText">ç¤ºä¾ææ¬</p>
</div>
CSS
css
div {
background-color: yellow;
width: 120px;
height: 120px;
}
.exampleText {
writing-mode: vertical-lr;
position: relative;
inset-block: 20px 50px;
background-color: #c8c800;
}
ç»æ
è§è
| è§è |
|---|
| CSS Logical Properties and Values Module Level 1> # propdef-inset-block> |
| CSS Positioned Layout Module Level 3> # propdef-inset-block> |
æµè§å¨å ¼å®¹æ§
åè§
- 对åºçå®ä½å±æ§ï¼
topãrightãbottomåleft - 对åºçå®ä½ç®å屿§ï¼
inset - 对åºçè¡åç®å屿§ï¼
inset-inline writing-modeãdirectionãtext-orientation