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 möglicherweise nicht rechteckig ist -, um die sich benachbarter Inline-Content wickeln soll. Standardmäßig wickelt sich Inline-Content um den Rand des Margen-Box; shape-outside bietet eine Möglichkeit, dieses Wickeln anzupassen, um Text um komplexe Objekte herumzuführen, anstatt um rechteckige Boxen.
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 unten aufgeführten Werte angegeben, die den float-Bereich für float-Elemente definieren. Der float-Bereich bestimmt die Form, um die sich Inline-Content (float-Elemente) wickelt.
Werte
none-
Der float-Bereich bleibt unbeeinflusst. Inline-Content wickelt sich wie gewohnt um den Rand des Elements.
<shape-box>-
Der float-Bereich wird gemäß der Form der Kanten eines Float-Elements berechnet (wie durch das 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 (ähnliches Verhalten wiebackground-clip).margin-box-
Definiert die Form, die von der äußeren Margenkante umschlossen wird. Die Eckradien dieser Form werden durch die entsprechenden
border-radiusundmarginWerte bestimmt. Wenn das Verhältnisborder-radius / margin1oder mehr ist, dann ist der Eckradius der Margen-Boxborder-radius + margin. Ist das Verhältnis kleiner als1, dann ist der Eckradius der Margen-Boxborder-radius + (margin * (1 + (ratio - 1) ^ 3)). border-box-
Definiert die Form, die von der äußeren Randkante umschlossen wird. Die Form folgt den normalen Eckradius-Formungsregeln für die Außenseite des Rahmens.
padding-box-
Definiert die Form, die von der äußeren Polsterkante umschlossen wird. Die Form folgt den normalen Eckradius-Formungsregeln für die Innenseite des Rahmens.
content-box-
Definiert die Form, die von der äußeren Inhaltkante umschlossen wird. Jeder Eckradius dieser Box 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 erstellt wird; andere<basic-shape>Funktionen sind ungültig. Wenn auch ein<shape-box>angegeben ist, definiert er die Referenzbox für die<basic-shape>Funktion. Andernfalls ist die Standard-Referenzboxmargin-box. <image>-
Der float-Bereich wird basierend auf dem Alphakanal des angegebenen
<image>extrahiert und berechnet, wie durchshape-image-thresholddefiniert.
Hinweis:
Wenn das Bild ungültig ist, ist die Wirkung 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
| 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>
<shape-box> =
<visual-box> |
margin-box |
half-border-box
<image> =
<url> |
<image()> |
<image-set()> |
<cross-fade()> |
<element()> |
<gradient>
<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> )
<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>
Beispiele
>Kanalisierung von Text
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> |