shape-outside
åºçº¿
广æ³å¯ç¨
*
èª 2020å¹´1æ èµ·ï¼æ¤ç¹æ§å·²å¨ä¸»æµæµè§å¨ä¸å¾å°æ¯æï¼å¯å¨å¤§å¤æ°è®¾å¤åæµè§å¨çæ¬ä¸æ£å¸¸ä½¿ç¨ã
* æ¤ç¹æ§çæäºé¨åçæ¯æç¨åº¦å¯è½ææä¸åã
shape-outside ç CSS 屿§å®ä¹äºä¸ä¸ªå¯ä»¥æ¯éç©å½¢çå½¢ç¶ï¼ç¸é»çå
èå
容åºå´ç»è¯¥å½¢ç¶è¿è¡å
è£
ãé»è®¤æ
åµä¸ï¼å
èå
容å
å´å
¶è¾¹è·æ¡; shape-outsideæä¾äºä¸ç§èªå®ä¹æ¤å
è£
çæ¹æ³ï¼å¯ä»¥å°ææ¬å
è£
å¨å¤æå¯¹è±¡å¨å´è䏿¯ç®åçæ¡ä¸ã
å°è¯ä¸ä¸
shape-outside: circle(50%);
shape-outside: ellipse(130px 140px at 20% 20%);
shape-outside: url("/proxy/developer.mozilla.org/shared-assets/images/examples/round-balloon.png");
shape-outside: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
<section class="default-example" id="default-example">
<div class="example-container">
<img
class="transition-all"
id="example-element"
src="/proxy/developer.mozilla.org/shared-assets/images/examples/round-balloon.png"
width="150" />
We had agreed, my companion and I, that I should call for him at his house,
after dinner, not later than eleven oâclock. This athletic young Frenchman
belongs to a small set of Parisian sportsmen, who have taken up âballooningâ
as a pastime. After having exhausted all the sensations that are to be found
in ordinary sports, even those of âautomobilingâ at a breakneck speed, the
members of the âAéro Clubâ now seek in the air, where they indulge in all
kinds of daring feats, the nerve-racking excitement that they have ceased to
find on earth.
</div>
</section>
.example-container {
text-align: left;
padding: 20px;
}
#example-element {
float: left;
width: 150px;
margin: 20px;
}
è¯æ³
/* å
³é®åå¼ */
shape-outside: none;
shape-outside: margin-box;
shape-outside: content-box;
shape-outside: border-box;
shape-outside: padding-box;
/* 彿°å¼ */
shape-outside: circle();
shape-outside: ellipse();
shape-outside: inset(10px 10px 10px 10px);
shape-outside: polygon(10px 10px, 20px 20px, 30px 30px);
/* <url> å¼ */
shape-outside: url(image.png);
/* æ¸åå¼ */
shape-outside: linear-gradient(45deg, rgba(255, 255, 255, 0) 150px, red 150px);
/* å
¨å±å¼ */
shape-outside: initial;
shape-outside: inherit;
shape-outside: unset;
shape-outside 屿§æå®ä½¿ç¨ä¸é¢å表ç弿¥å®ä¹æµ®å¨å
ç´ çæµ®å¨åºåãè¿ä¸ªæµ®å¨åºåå³å®äºè¡å
å
å®¹ï¼æµ®å¨å
ç´ ï¼æå
裹çå½¢ç¶ã
å¼
none-
该浮å¨åºåä¸äº§çå½±åï¼è¡å å ç´ ä»¥é»è®¤çæ¹å¼å 裹ç该å ç´ ç margin boxã
<shape-box>-
æ ¹æ®æµ®å¨å ç´ çè¾¹ç¼ï¼éè¿ CSS box model æ¥å®ä¹ï¼å½¢ç¶è®¡ç®åºæµ®å¨çåºåãå¯è½æ¯
margin-box,border-box,padding-box, æècontent-boxãè¿ä¸ªå½¢ç¶å æ¬äºç±border-radius屿§å¶é åºæ¥ç弧度ï¼ä¸background-clipç表ç°ç±»ä¼¼ï¼ãmargin-box-
å®ä¹ä¸ä¸ªç±å¤è¾¹è·çå¤è¾¹ç¼å°éå½¢æçå½¢ç¶ãè¿ä¸ªå½¢ç¶çè§çåå¾ç±ç¸åºç
border-radiusåmarginçå¼å³å®ã妿border-radius / marginçæ¯ç大äºçäº1, é£ä¹è¿ä¸ª margin box çè§ç弧度就æ¯border-radius + marginï¼å¦ææ¯çå°äº1ï¼é£ä¹è¿ä¸ª margin box çè§ç弧度就æ¯border-radius + (margin * (1 + (ratio-1)^3))ã border-box-
å®ä¹ä¸ä¸ªç±è¾¹ççå¤è¾¹ç¼å°éå½¢æçå½¢ç¶ãè¿ä¸ªå½¢ç¶éµå¾ªæ£å¸¸çè¾¹çå¤é¨åè§çå½¢æè§åã
padding-box-
å®ä¹ä¸ä¸ªç±å è¾¹è·çå¤è¾¹ç¼å°éå½¢æçå½¢ç¶ãè¿ä¸ªå½¢ç¶éµå¾ªæ£å¸¸çè¾¹çå é¨åè§çå½¢æè§åã
content-box-
å®ä¹ä¸ä¸ªç±å 容åºåçå¤è¾¹ç¼å°éå½¢æçå½¢ç¶ï¼è¯è ï¼è¡¨è¿°çä¸å¤ªå¥½ï¼å°±æ¯è¢« padding å 裹çåºåï¼å¨ chrome æ§å¶å°ä¸çç忍¡åå¾ä¸çèè²åºåãï¼ãæ¯ä¸ä¸ªè§ç弧度å
0æborder-radius - border-width - paddingä¸çè¾å¤§å¼ã
<basic-shape>-
åºäº
inset()ãcircle()ãellipse()æpolygon()å ¶ä¸ä¸ä¸ªåé åºæ¥çå½¢ç¶è®¡ç®åºæµ®å¨åºåã妿忶åå¨<shape-box>ï¼é£ä¹ä¼ä¸º<basic-shape>æ¹æ³å®ä¹ä¸ä¸ªåèçï¼è¿ä¸ªåèçé»è®¤ä¸ºmargin-boxã <image>-
æåå¹¶ä¸è®¡ç®æå®
<image>ç alpha ééå¾åºæµ®å¨åºåï¼è¯è ï¼å³æ ¹æ®å¾ççééæåºåè¿è¡å 裹ï¼ãå°±è·éè¿shape-image-thresholdæ¥å®ä¹ä¸æ ·ã夿³¨ï¼ç¨æ·ä»£ç å¿ é¡»ä½¿ç¨ç± HTML5 è§èå®ä¹ç CORS-enabled fetch æ¹æ³æ¥å¤ç
shape-outsideçå¼ä¸çææ URLã彿è·çæ¶åï¼ç¨æ·ä»£çå¿ é¡»ä½¿ç¨âå¿åâæ¨¡å¼æ¥è®¾ç½®å±å æ ·å¼è¡¨ç URL ç referrer source å设置æå¨ææ¡£ç URL ç originã妿è¿å¯¼è´åºç°æ²¡æææçå¤ä»½å¾åè¿æ ·çç½ç»é误ï¼äº§ççå½±åå°±è·æå®äºå¼none䏿 ·ã
æ£å¼è¯æ³
shape-outside =
none |
[ <basic-shape> || <shape-box> ] |
<image>
<basic-shape> =
<basic-shape-rect> |
<circle()> |
<ellipse()> |
<polygon()> |
<path()> |
<shape()>
<shape-box> =
<visual-box> |
margin-box |
half-border-box
<image> =
<url> |
<image()> |
<image-set()> |
<cross-fade()> |
<element()> |
<gradient>
<basic-shape-rect> =
<inset()> |
<rect()> |
<xywh()>
<circle()> =
circle( <radial-size>? [ at <position> ]? )
<ellipse()> =
ellipse( <radial-size>? [ at <position> ]? )
<polygon()> =
polygon( <'fill-rule'>? [ round <length> ]? , [ <length-percentage> <length-percentage> ]# )
<path()> =
path( <'fill-rule'>? , <string> )
<shape()> =
shape( <'fill-rule'>? from <position> , <shape-command># )
<visual-box> =
content-box |
padding-box |
border-box
<image()> =
image( <image-tags>? [ <image-src>? , <color>? ]! )
<image-set()> =
image-set( <image-set-option># )
<cross-fade()> =
cross-fade( <cf-image># )
<element()> =
element( <id-selector> )
<inset()> =
inset( <length-percentage>{1,4} [ round <'border-radius'> ]? )
<rect()> =
rect( <top> , <right> , <bottom> , <left> )
<xywh()> =
xywh( <length-percentage>{2} <length-percentage [0,â]>{2} [ round <'border-radius'> ]? )
<radial-size> =
<radial-extent> |
<length [0,â]> |
<length-percentage [0,â]>{2}
<position> =
<position-one> |
<position-two> |
<position-four>
<fill-rule> =
nonzero |
evenodd
<length-percentage> =
<length> |
<percentage>
<shape-command> =
<move-command> |
<line-command> |
close |
<horizontal-line-command> |
<vertical-line-command> |
<curve-command> |
<smooth-command> |
<arc-command>
<image-tags> =
ltr |
rtl
<image-src> =
<url> |
<string>
<image-set-option> =
[ <image> | <string> ] [ <resolution> || type( <string> ) ]?
<cf-image> =
[ <image> | <color> ] &&
<percentage [0,100]>?
<id-selector> =
<hash-token>
<border-radius> =
<length-percentage [0,â]>{1,4} [ / <length-percentage [0,â]>{1,4} ]?
<radial-extent> =
closest-corner |
closest-side |
farthest-corner |
farthest-side
<position-one> =
left |
center |
right |
top |
bottom |
x-start |
x-end |
y-start |
y-end |
block-start |
block-end |
inline-start |
inline-end |
<length-percentage>
<position-two> =
[ left | center | right | x-start | x-end ] && [ top | center | bottom | y-start | y-end ] |
[ left | center | right | x-start | x-end | <length-percentage> ] [ top | center | bottom | y-start | y-end | <length-percentage> ] |
[ block-start | center | block-end ] && [ inline-start | center | inline-end ] |
[ start | center | end ]{2}
<position-four> =
[ [ left | right | x-start | x-end ] <length-percentage> ] && [ [ top | bottom | y-start | y-end ] <length-percentage> ] |
[ [ block-start | block-end ] <length-percentage> ] && [ [ inline-start | inline-end ] <length-percentage> ] |
[ [ start | end ] <length-percentage> ]{2}
<move-command> =
move <command-end-point>
<line-command> =
line <command-end-point>
<horizontal-line-command> =
hline [ to [ <length-percentage> | left | center | right | x-start | x-end ] | by <length-percentage> ]
<vertical-line-command> =
vline [ to [ <length-percentage> | top | center | bottom | y-start | y-end ] | by <length-percentage> ]
<curve-command> =
curve [ [ to <position> with <control-point> [ / <control-point> ]? ] | [ by <coordinate-pair> with <relative-control-point> [ / <relative-control-point> ]? ] ]
<smooth-command> =
smooth [ [ to <position> [ with <control-point> ]? ] | [ by <coordinate-pair> [ with <relative-control-point> ]? ] ]
<arc-command> =
arc <command-end-point> [ [ of <length-percentage>{1,2} ] && <arc-sweep>? && <arc-size>? && [ rotate <angle> ]? ]
<command-end-point> =
to <position> |
by <coordinate-pair>
<control-point> =
<position> |
<relative-control-point>
<coordinate-pair> =
<length-percentage>{2}
<relative-control-point> =
<coordinate-pair> [ from [ start | end | origin ] ]?
<arc-sweep> =
cw |
ccw
<arc-size> =
large |
small
æå¼
å½å¨ä¸¤ä¸ª <basic-shape> ä¹é´äº§çå¨ç»æ¶ï¼å°ä¼åºç¨ä»¥ä¸è§åãshape éçå¼å°ä¼è¢«å½æä¸ä¸ªç®åå表æå
¥ãæå
¥å表çå¼çç±»åå¯è½æ¯ <length>ï¼<percentage>ï¼æ calc()ã妿å表çå¼ä¸æ¯ä»¥ä¸çå ç§ç±»åï¼ä½æ¯é½ç¸åçè¯ï¼å¦å¨ä¸¤ä¸ªå表çç¸åä½ç½®æ¾å°äº nonzero ï¼ï¼é£äºå¼ä¼æå
¥å°å表ä¸ã
- 两个形ç¶å¿ 须使ç¨åæ ·çåèçã
- å¦æä¸¤ä¸ªå½¢ç¶é½æ¯
ellipse()æcircle()ç±»åï¼å¹¶ä¸å®ä»¬ç radii 齿²¡æä½¿ç¨closest-sideæfarthest-sideå ³é®åï¼åå°ä¸¤ä¸ªå½¢ç¶å¯¹åºå¼ä¹é´çå¼æå ¥å° shape æ¹æ³ä¸ã - å¦æä¸¤ä¸ªå½¢ç¶çç±»å齿¯
inset()ï¼åå°ä¸¤ä¸ªå½¢ç¶å¯¹åºå¼ä¹é´çå¼æå ¥å° shape æ¹æ³ä¸ã - å¦æä¸¤ä¸ªå½¢ç¶é½æ¯
polygon()ï¼ä¸¤ä¸ªå¤è¾¹å½¢ä¹é´æç¸åçå®ç¹æ°éå¹¶ä¸<fill-rule>ç¸åï¼åå°ä¸¤ä¸ªå½¢ç¶å¯¹åºå¼ä¹é´çå¼æå ¥å° shape æ¹æ³ä¸ã - å ¶ä½æææ åµé½ä¸ä¼åçæå ¥ã
示ä¾
>HTML
<div class="main">
<div class="left"></div>
<div class="right"></div>
<p>
Sometimes a web page's text content appears to be funneling your attention
towards a spot on the page to drive you to follow a particular link.
Sometimes you don't notice.
</p>
</div>
CSS
.main {
width: 500px;
}
.left,
.right {
width: 40%;
height: 12ex;
background-color: lightgray;
}
.left {
-webkit-shape-outside: polygon(0 0, 100% 100%, 0 100%);
shape-outside: polygon(0 0, 100% 100%, 0 100%);
float: left;
-webkit-clip-path: polygon(0 0, 100% 100%, 0 100%);
clip-path: polygon(0 0, 100% 100%, 0 100%);
}
.right {
-webkit-shape-outside: polygon(100% 0, 100% 100%, 0 100%);
shape-outside: polygon(100% 0, 100% 100%, 0 100%);
float: right;
-webkit-clip-path: polygon(100% 0, 100% 100%, 0 100%);
clip-path: polygon(100% 0, 100% 100%, 0 100%);
}
p {
text-align: center;
}
Result
è§è
| è§è |
|---|
| CSS Shapes Module Level 1> # shape-outside-property> |