Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten. Erfahre mehr über dieses Experiment.

View in English Always switch to English

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-Eigenschaft CSS definiert eine Form – die nicht rechteckig sein muss – um die herum angrenzender Inline-Content fließen soll. Standardmäßig fließt Inline-Content um seine Margin-Box; shape-outside bietet eine Möglichkeit, dieses Fließen anzupassen, sodass es möglich ist, Text um komplexe Objekte statt um rechteckige Boxen 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

css
/* 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 mit Werten aus der unten stehenden Liste spezifiziert, die den Float-Bereich für Float-Elemente definieren. Der Float-Bereich bestimmt die Form, um die herum Inline-Content (Float-Elemente) fließen.

Werte

none

Der Float-Bereich bleibt unbeeinflusst. Inline-Content fließt wie gewohnt um die Margin-Box des Elements.

<shape-box>

Der Float-Bereich wird basierend auf der Form der Kanten eines Float-Elements berechnet (wie im CSS-Boxmodell definiert). Dies kann margin-box, border-box, padding-box oder content-box sein. Die Form schließt jede durch die border-radius-Eigenschaft erzeugte Krümmung ein (ein Verhalten, das dem von background-clip ähnlich ist).

margin-box

Definiert die Form, die von der äußeren Margin-Kante eingeschlossen wird. Die Eckenradien dieser Form werden durch die entsprechenden border-radius- und margin-Werte bestimmt. Wenn das Verhältnis von border-radius / margin 1 oder mehr beträgt, ist der Eckenradius der Margin-Box border-radius + margin. Wenn das Verhältnis weniger als 1 ist, beträgt der Eckenradius der Margin-Box border-radius + (margin * (1 + (ratio - 1) ^ 3)).

border-box

Definiert die Form, die durch die äußere Border-Kante eingeschlossen wird. Die Form folgt den normalen Regeln zur Eckenradiusgestaltung für die Außenseite der Border.

padding-box

Definiert die Form, die durch die äußere Padding-Kante eingeschlossen wird. Die Form folgt den normalen Regeln zur Eckenradiusgestaltung für die Innenseite der Border.

content-box

Definiert die Form, die durch die äußere Content-Kante eingeschlossen wird. Jeder Eckenradius dieser Box ist der größere von 0 oder border-radius - border-width - padding.

<basic-shape>

Der Float-Bereich wird basierend auf der Form berechnet, die durch eine inset(), circle(), ellipse() oder polygon()-Funktion erzeugt wird; andere <basic-shape>-Funktionen sind ungültig. Wenn eine <shape-box> ebenfalls angegeben ist, definiert sie die Referenzbox für die <basic-shape>-Funktion. Andernfalls ist die Referenzbox standardmäßig margin-box.

<image>

Der Float-Bereich wird extrahiert und basierend auf dem Alphakanal des angegebenen <image> berechnet, wie durch shape-image-threshold definiert.

Hinweis: Wenn das Bild ungültig ist, ist der Effekt so, als wäre das Schlüsselwort none angegeben worden. Zusätzlich muss das Bild mit CORS-Headern bereitgestellt werden, die seine Verwendung erlauben.

Formale Definition

Anfangswertnone
Anwendbar aufFlusselemente
VererbtNein
Berechneter Wertwie definiert für <basic-shape> (gefolgt von shape-box, falls angegeben), dem <image>, dessen URI absolut gemacht wurde, ansonsten wie angegeben.
Animationstypja, 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

Trichterförmiger Text

HTML

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

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

Browser-Kompatibilität

Siehe auch