mask-repeat
åºçº¿
广æ³å¯ç¨
èª 2023å¹´12æ èµ·ï¼æ¤ç¹æ§å·²å¨ä¸»æµæµè§å¨ä¸å¾å°æ¯æï¼å¯å¨å¤§å¤æ°è®¾å¤åæµè§å¨çæ¬ä¸æ£å¸¸ä½¿ç¨ã
CSS ç mask-repeat 屿§å®ä¹äºé®ç½©å¾çæ¯å¦é夿¾ç¤ºå¤ä¸ªå¯æ¬ï¼ä»¥åå¦ä½éå¤ãä¸ä¸ªé®ç½©å¾çå¯ä»¥æ°´å¹³éå¤ãåç´é夿ååéå¤ï¼ä¹å¯ä»¥ä¸éå¤ã
/* One-value syntax */
mask-repeat: repeat-x;
mask-repeat: repeat-y;
mask-repeat: repeat;
mask-repeat: space;
mask-repeat: round;
mask-repeat: no-repeat;
/* Two-value syntax: horizontal | vertical */
mask-repeat: repeat space;
mask-repeat: repeat repeat;
mask-repeat: round space;
mask-repeat: no-repeat round;
/* Multiple values */
mask-repeat:
space round,
no-repeat;
mask-repeat:
round repeat,
space,
repeat-x;
/* Global values */
mask-repeat: inherit;
mask-repeat: initial;
mask-repeat: unset;
é»è®¤æ
åµä¸ï¼éå¤çå¾çä¼è¢«åªå为å¾çç大å°ï¼ä½ä»ä»¬å¯ä»¥èªè¡ç¼©æ¾éåºï¼ä½¿ç¨ roundï¼ï¼æè
ä»ä¸ç«¯å°å¦ä¸ç«¯åååå¸ï¼ä½¿ç¨ spaceï¼ã
| åå§å¼ | repeat |
|---|---|
| éç¨å ç´ | all elements; In SVG, it applies to container elements excluding the <defs> element and all graphics elements |
| æ¯å¦æ¯ç»§æ¿å±æ§ | å¦ |
| 计ç®å¼ | Consists of two keywords, one per dimension |
| å¨ç»ç±»å | 离æ£å¼ |
è¯æ³
One or more <repeat-style> values, separated by commas.
åå¼
<repeat-style>-
åå¼è¯æ³å¯å°ä¸¤ä¸ªå¼ç®å为ä¸ä¸ªï¼
åå¼ ä¸ä¹çæçåå¼ repeat-xrepeat no-repeatrepeat-yno-repeat repeatrepeatrepeat repeatspacespace spaceroundround roundno-repeatno-repeat no-repeatå¨åå¼è¯æ³ä¸ï¼ç¬¬ä¸ä¸ªå¼ä»£è¡¨äºæ°´å¹³æ¹åçè¡ä¸ºï¼ç¬¬äºä¸ªå¼ä»£è¡¨äºåç´æ¹åçè¡ä¸ºãä¸é¢æ¯æ¯ä¸ªé项çç¨æ³è§£éï¼
repeatThe image is repeated as much as needed to cover the whole mask painting area. The last image will be clipped if it doesn't fit. spaceThe image is repeated as much as possible without clipping. The first and last images are pinned to either side of the element, and whitespace is distributed evenly between the images. The mask-positionproperty is ignored unless only one image can be displayed without clipping. The only case where clipping happens usingspaceis when there isn't enough room to display one image.roundAs the allowed space increases in size, the repeated images will stretch (leaving no gaps) until there is room for another one to be added. When the next image is added, all of the current ones compress to allow room. Example: An image with an original width of 260px, repeated three times, might stretch until each repetition is 300px wide, and then another image will be added. They will then compress to 225px. no-repeatThe image is not repeated (and hence the mask painting area will not necessarily be entirely covered). The position of the non-repeated mask image is defined by the mask-positionCSS property.
å½¢å¼è¯æ³
mask-repeat =
<repeat-style>#
<repeat-style> =
repeat-x |
repeat-y |
repeat-block |
repeat-inline |
<repetition>{1,2}
<repetition> =
repeat |
space |
round |
no-repeat
示ä¾
>åå¼
CSS
#masked {
width: 250px;
height: 250px;
background: blue linear-gradient(red, blue);
mask-image: url(star.svg);
mask-repeat: repeat; /* å¯å¨å®æ¶ç¤ºä¾ live sample ä¸ä¿®æ¹ */
margin-bottom: 10px;
}
使ç¨å¤ä¸ªé®ç½©å¾ç
You can specify a different <repeat-style> for each mask image, separated by commas:
.examplethree {
mask-image: url("mask1.png"), url("mask2.png");
mask-repeat: repeat-x, repeat-y;
}
Each image is matched with the corresponding repeat style, from first specified to last.
è§è
| è§è |
|---|
| CSS Masking Module Level 1 > # the-mask-repeat > |