shape-outside
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. It’s been available across browsers since Januar 2020.
* Some parts of this feature may have varying levels of support.
Die shape-outside CSS Eigenschaft definiert eine Form – die nicht rechteckig sein muss –, um die herum angrenzender Inline-Inhalt fließen soll. Standardmäßig fließt Inline-Inhalt um seine Randbox herum; shape-outside bietet eine Möglichkeit, dieses Umfließen anzupassen, sodass es möglich wird, Text um komplexe Objekte statt um rechteckige Kästen fließen zu lassen.
Probieren Sie es aus
shape-outside: circle(50%);
shape-outside: ellipse(130px 140px at 20% 20%);
shape-outside: url("/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="/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;
}
Syntax
/* Keyword values */
shape-outside: none;
shape-outside: margin-box;
shape-outside: content-box;
shape-outside: border-box;
shape-outside: padding-box;
/* Function values */
shape-outside: circle();
shape-outside: ellipse();
shape-outside: inset(10px 10px 10px 10px);
shape-outside: polygon(10px 10px, 20px 20px, 30px 30px);
/* Shape box with basic shape */
shape-outside: circle() border-box;
shape-outside: margin-box ellipse();
/* <url> value */
shape-outside: url("image.png");
/* <gradient> value */
shape-outside: linear-gradient(45deg, white 150px, red 150px);
/* Global values */
shape-outside: inherit;
shape-outside: initial;
shape-outside: revert;
shape-outside: revert-layer;
shape-outside: unset;
Die shape-outside Eigenschaft wird unter Verwendung der Werte aus der untenstehenden Liste angegeben, die den Float-Bereich für Float-Elemente definieren. Der Float-Bereich bestimmt die Form, um die Inline-Inhalt (Float-Elemente) fließen.
Werte
none-
Der Float-Bereich bleibt unverändert. Inline-Inhalt fließt um die Randbox des Elements wie üblich.
<shape-box>-
Der Float-Bereich wird gemäß der Form der Kanten eines Float-Elements berechnet (wie im CSS-Box-Modell definiert). Dies kann
margin-box,border-box,padding-boxodercontent-boxsein. Die Form schließt jede Krümmung ein, die durch dieborder-radiusEigenschaft erzeugt wird (ein Verhalten, das dem vonbackground-clipähnlich ist).margin-box-
Definiert die durch die äußere Randkante eingeschlossene Form. Die Eckenradien dieser Form werden durch die entsprechenden
border-radiusundmarginWerte bestimmt. Wenn das Verhältnisborder-radius / margin1oder mehr ist, dann ist der Eckenradius der Randboxborder-radius + margin. Wenn das Verhältnis weniger als1ist, dann ist der Eckenradius der Randboxborder-radius + (margin * (1 + (verhältnis - 1) ^ 3)). border-box-
Definiert die durch die äußere Rahmenkante eingeschlossene Form. Die Form folgt den normalen Formenregeln des Rahmenradius für die Außenseite des Rahmens.
padding-box-
Definiert die durch die äußere Füllungskante eingeschlossene Form. Die Form folgt den normalen Formenregeln des Rahmenradius für die Innenseite des Rahmens.
content-box-
Definiert die durch die äußere Inhaltkante eingeschlossene Form. Jeder Eckenradius dieses Kastens ist der größere von
0oderborder-radius - border-width - padding.
<basic-shape>-
Der Float-Bereich wird basierend auf der Form berechnet, die durch eine
inset(),circle(),ellipse(), oderpolygon()Funktion erzeugt wird; andere<basic-shape>Funktionen sind ungültig. Wenn auch eine<shape-box>angegeben ist, definiert sie die Referenzbox für die<basic-shape>Funktion. Andernfalls ist die Referenzbox standardmäßigmargin-box. <image>-
Der Float-Bereich wird basierend auf dem Alphakanal des angegebenen
<image>extrahiert und berechnet, wie es durchshape-image-thresholddefiniert ist.
Hinweis:
Wenn das Bild ungültig ist, hat dies denselben Effekt, als ob das Schlüsselwort none angegeben worden wäre. Zusätzlich muss das Bild mit CORS Headern bereitgestellt werden, die dessen Verwendung erlauben.
Formale Definition
| Anfangswert | none |
|---|---|
| Anwendbar auf | Flusselemente |
| Vererbt | Nein |
| Berechneter Wert | wie definiert für <basic-shape> (gefolgt von shape-box, falls angegeben), dem <image>, dessen URI absolut gemacht wurde, ansonsten wie angegeben. |
| Animationstyp | ja, wie angegeben für <basic-shape>, ansonsten nein |
Formale Syntax
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
Beispiele
>Text trichtern
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: 530px;
}
.left,
.right {
background-color: lightgray;
height: 12ex;
width: 40%;
}
.left {
clip-path: polygon(0 0, 100% 100%, 0 100%);
float: left;
shape-outside: polygon(0 0, 100% 100%, 0 100%);
}
.right {
clip-path: polygon(100% 0, 100% 100%, 0 100%);
float: right;
shape-outside: polygon(100% 0, 100% 100%, 0 100%);
}
p {
text-align: center;
}
Ergebnis
Spezifikationen
| Specification |
|---|
| CSS Shapes Module Level 1> # shape-outside-property> |