right
åºçº¿
广æ³å¯ç¨
*
èª 2015å¹´7æ èµ·ï¼æ¤ç¹æ§å·²å¨ä¸»æµæµè§å¨ä¸å¾å°æ¯æï¼å¯å¨å¤§å¤æ°è®¾å¤åæµè§å¨çæ¬ä¸æ£å¸¸ä½¿ç¨ã
* æ¤ç¹æ§çæäºé¨åçæ¯æç¨åº¦å¯è½ææä¸åã
right CSS 屿§å®ä¹äºå®ä½å
ç´ çå³å¤è¾¹è·è¾¹çä¸å
¶å
å«åå³è¾¹çä¹é´çåç§»ï¼éå®ä½å
ç´ è®¾ç½®æ¤å±æ§æ æã
/* <length> values */
right: 3px;
right: 2.4em;
/* <percentage>s of the width of the containing block */
right: 10%;
/* Keyword value */
right: auto;
/* Global values */
right: inherit;
right: initial;
right: unset;
rightçææåå³äºå
ç´ çposition屿§ï¼
- å½
position设置为absoluteæfixedæ¶ï¼right屿§æå®äºå®ä½å ç´ å³å¤è¾¹è·è¾¹çä¸å ¶å å«åå³è¾¹çä¹é´çåç§»ã - å½
position设置为relativeæ¶ï¼right屿§æå®äºå ç´ çå³è¾¹ç离å¼å ¶æ£å¸¸ä½ç½®çåç§»ã - å½
position设置为stickyæ¶ï¼å¦æå ç´ å¨ viewport éé¢ï¼right屿§çææå position 为relativeçåï¼å¦æå ç´ å¨ viewport å¤é¢ï¼right屿§çææå position 为fixedçåã - å½
position设置为staticæ¶ï¼right屿§æ æã
å½ left å right åæ¶æå®æ¶ï¼å
ç´ çä½ç½®ä¼è¢«é夿å®ãå½å®¹å¨æ¯ä»å·¦å°å³æ¶ï¼left çå¼ä¼è¢«ä¼å
设å®ï¼å½å®¹å¨æ¯ä»å³å°å·¦æ¶ï¼right çå¼ä¼è¢«ä¼å
设å®ã
| åå§å¼ | auto |
|---|---|
| éç¨å ç´ | positioned elements |
| æ¯å¦æ¯ç»§æ¿å±æ§ | å¦ |
| Percentages | refer to the width of the containing block |
| 计ç®å¼ | if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, auto |
| å¨ç»ç±»å | a length, percentage or calc(); |
è¯æ³
>åå¼
<length>-
å¯ä»¥æ¯è´çï¼æ£ç æè null
<length>表示ï¼- 对äºç»å¯¹å®ä½çå ç´ ï¼å ç´ å³å¤è¾¹è·è¾¹çä¸å ¶å å«åå³è¾¹çä¹é´çåç§»ã
- 对äºç¸å¯¹å®ä½å®ä½çå ç´ ï¼å ç´ çå³è¾¹ç离å¼å ¶æ£å¸¸ä½ç½®çåç§»ã
<percentage>-
代表å ç´ å å«åç宽度çç¾åæ¯
<percentage>ã auto-
è¿ä¸ªå ³é®å表示ï¼
- 对äºç»å¯¹å®ä½å
ç´ ï¼å
ç´ å°å¿½ç¥æ¤å±æ§è以
left屿§ä¸ºåï¼å¦ææ¤æ¶è®¾ç½®width: autoï¼å°åºäºå 容éè¦ç宽度设置宽度ï¼å¦æleftä¹ä¸ºautoçè¯ï¼å ç´ çæ°´å¹³ä½ç½®å°±æ¯å®åå¦ä½ä¸ºéæï¼å³ staticï¼å ç´ æ¶è¯¥å¨çä½ç½®ã - 对äºç¸å¯¹å®ä½å
ç´ ï¼å
ç´ ç¸å¯¹æ£å¸¸ä½ç½®çåç§»éå°åºäº
left屿§ï¼å¦æleftä¹ä¸ºautoçè¯ï¼å ç´ å°ä¸ä¼æåç§»ã
- 对äºç»å¯¹å®ä½å
ç´ ï¼å
ç´ å°å¿½ç¥æ¤å±æ§è以
inherit-
è¿ä¸ªå ³é®å表示该å¼ä¸å ¶ç¶å ç´ ï¼å¯è½ä¸æ¯å®çå å«åï¼ç计ç®å¼ç¸åã对è¿ä¸ªè®¡ç®å¼çå¤çå°åå®åæ¬ä¸º
<length>ã<percentage>æauto䏿 ·ã
å½¢å¼è¯æ³
right =
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
示ä¾
#example_3 {
width: 100px;
height: 100px;
background-color: #ffc7e4;
position: relative;
top: 20px;
left: 20px;
}
#example_4 {
width: 100px;
height: 100px;
background-color: #ffd7c2;
position: absolute;
bottom: 10px;
right: 20px;
}
<div id="example_3">Example 3</div>
<div id="example_4">Example 4</div>
è§è
| è§è |
|---|
| CSS Positioned Layout Module Level 3 > # insets > |