Proprietà shape-outside

La proprietà shape-outside consente di definire forme di flusso non standard per elementi fluttuanti. Gli elementi adiacenti fluiranno attorno alla forma specificata, e non al contenitore rettangolare.

Sintassi

cssselettore {
  shape-outside: valore;
}

Valori

Valore Descrizione
circle() Forma di flusso circolare
ellipse() Forma di flusso ellittica
polygon() Forma poligonale arbitraria
url() Forma basata sul canale alfa di un'immagine
margin-box Utilizza i bordi del margin (valore predefinito)

Esempio

Creiamo una forma di flusso circolare per un elemento fluttuante. Utilizziamo le proprietà shape-outside e clip-path:

html<div class="shape"></div>
<p>
  some long text
</p>
css.shape {
  width: 150px;
  height: 150px;
  float: left;
  shape-outside: circle(50%);
  clip-path: circle(50%);
  background: #3498db;
}

p {
  width: 500px;
  text-align: justify;
}

Результат:

Esempio

Definiamo una spaziatura tramite la proprietà shape-margin:

html<div class="shape"></div>
<p>
  some long text
</p>
css.shape {
  width: 150px;
  height: 150px;
  float: left;
  shape-outside: circle(50%);
  shape-margin: 10px;
  clip-path: circle(50%);
  background: #3498db;
}

p {
  width: 500px;
  text-align: justify;
}

Результат:

Esempio

Senza la proprietà clip-path il testo fluirà attorno al cerchio, ma l'elemento non avrà la forma di un cerchio:

html<div class="shape"></div>
<p>
  some long text
</p>
css.shape {
  width: 150px;
  height: 150px;
  float: left;
  shape-outside: circle(50%);
  background: #3498db;
}

p {
  width: 500px;
  text-align: justify;
}

Результат:

Esempio

Un'altra forma per l'elemento:

html<div class="shape"></div>
<p>
  some long text
</p>
css.shape {
  width: 200px;
  height: 200px;
  background-color: #4CAF50;
  float: left;
  shape-outside: polygon(0% 0%, 100% 50%, 0% 100%);
  clip-path: polygon(0% 0%, 100% 50%, 0% 100%);
  margin-right: 20px;
  margin-bottom: 20px;
}

p {
  width: 500px;
  text-align: justify;
}

Результат:

Esempio

Un'altra forma per l'elemento:

html<div class="shape"></div>
<p>
  some long text
</p>
css.shape {
  width: 200px;
  height: 200px;
  background-color: #4CAF50;
  float: left;
  shape-outside: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  margin-right: 20px;
  margin-bottom: 20px;
}

p {
  width: 500px;
  text-align: justify;
}

Результат:

Vedi anche

  • proprietà clip-path,
    che crea la forma visibile dell'elemento
  • proprietà float,
    necessaria per il funzionamento di shape-outside
  • proprietà shape-margin,
    che aggiunge una spaziatura attorno alla forma