paint-brush
How To Use CSS Shape-Outside, Clip-Path With The Float CSS Propertyby@Addo
2,305 reads
2,305 reads

How To Use CSS Shape-Outside, Clip-Path With The Float CSS Property

by DanielOctober 19th, 2019
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

How To Use CSS Shape-Outside, Clip-Path With The Float CSS Property, I will like to refresh our minds on three main CSS properties. To design a shape in modern web application, we will focus on the following CSS properties: shape-outside, clip-path and float-path. These properties define a shape around which adjacent inline content should wrap. Clip-path also allows us to specify a region of an element to display. The Float property floats the content to the specified direction, which makes a content float to the left or right.

Company Mentioned

Mention Thumbnail

Coin Mentioned

Mention Thumbnail
featured image - How To Use CSS Shape-Outside, Clip-Path With The Float CSS Property
Daniel HackerNoon profile picture

Great web design comes with great shapes that make the website have the looks it deserves. In the past, web applications were usually described as being made of boxes. Meaning, anything you see on the website is enclosed in a box. Now we can confidently say that websites are not only made of boxes but different varieties of shapes.

To build a user-friendly app that users interact with. We need different kinds of shapes to represent our content. In this article, I will like to refresh our minds on three main CSS properties.

To design a shape in modern web application, we will focus on the following CSS properties:

  • shape-outside
  • clip-path
  • float

Shape-outside property

The functionality of this property is to define a shape around which adjacent inline content should wrap. It works with float property, which makes a content float to either the left or right.

This property takes the following functions as its values:

  1. circle()
  2. inset(),
  3. ellipse(),
  4. polygon()
  5. URL()

Syntax

shape-outside: polygon( [&lt;fill-rule&gt;,]? [&lt;shape-arg&gt; &lt;shape-arg&gt;]# )<br>shape-outside: circle(percentage)<br>shape-outside: ellipse(x y)<br>shape-outside: inset(top right bottom left)<br>shape-outside: url(absolute url)

Now let’s see how it is implemented in real life:

.element { shape-outside: circle(50%); }<br>.element { shape-outside: polygon(0 0, 0 10em, 20em 30em); }<br>.element { shape-outside: ellipse(10em 20em at 30% 50%); }<br>.element { shape-outside: inset(10em 10em 10em 10em 10em); }<br>.element { shape-outside: url('https://www.microverse.org'); }

Play around with the values and you will see the shapes you can make out of this amazing CSS property.

Clip-path property

This property attaches the element’s content to the base shape. It also allows us to specify a region of an element to display. Clip-path also accepts the same values as the shape-outside.

For this article, our focus will be on the function values.

clip-path: polygon(6<code class="markup--code markup--pre-code">0% 0%</code>, <code class="markup--code markup--pre-code">0% 100%</code>, <code class="markup--code markup--pre-code">100% 100%</code>);<br>clip-path: ellipse(6em 3em at 12em 4em);<br>clip-path: circle(3em at 3em 3em);

Let’s play around with the values and see it in action.

Float property

Float property floats the content to the specified direction. This property is very important when using shape-outside property. Because shape-outside wrap around a floated element’s bounding box.

There are four valid values for the float property.

Left and Right float elements to specified directions respectively.

None (the default) ensures the element will not float and Inherit which will assume the float value from that elements parent element.

.element { float: left; shape-outside: circle(50%); }

Conclusion

.element { float: left; shape-outside: polygon(0 0, 3em 4em, 5em 2em, 7em 5em); clip-path: polygon(); }

In this article, we have learned three CSS properties .

  • Shape-outside
  • Clip-path
  • Float.

For a detailed explanation visit the following links below: