I have been able to successfully use shape-outside: polygon(...)
and clip-path: polygon(...)
to create a desired polygon shape.
I have seen many pages referencing use of shape-inside
, and yet I have read that shape-inside
had been deprecated and has no replacement. They were also written in 2014, so I am hoping that CSS3 has changed since then.
After looking on the web, I was able to piece together something that almost works. I like the shape, but now I need the text wrap inside the shape with the overflow hidden.
I have seen hints about ::before
, but I still don't understand how that would help. Testing it didn't seem to produce any results.
Whether it's simple or complicated, how can I use CSS to wrap the text within the polygon? Or does the solution lie outside of CSS? Do I need to use another approach, like jQuery?
CSS
/*
For reference:
@vertex1: 120px;
@vertex2: @vertex1*2;
*/
.diamondContainer {
display: block;
position: absolute;
text-align: center;
width: @vertex2;
height: @vertex2;
overflow: hidden; /* hide anything longer than allowed string length */
/* This is a diamond shape */
shape-outside: polygon(@vertex1 0, @vertex2 @vertex1, @vertex1 @vertex2, 0 @vertex1);
clip-path: polygon(@vertex1 0, @vertex2 @vertex1, @vertex1 @vertex2, 0 @vertex1);
}
HTML
<div class="diamondOuter">
<div class="diamondWrapper">
<div class="diamondContainer diamondCell2">
<span><strong>Title Text</strong><br />Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.</span>
</div>
</div>
</div>
The path() value allows us to use an SVG path to clip a specific area. For now, the browser support is inconsistent. To make it work across different browsers, we need to use an inline SVG, and then use the url() as a value for clip-path . In CSS, we need to append the path using url() value.
CSS clip-path EditorStart by selecting a polygon() — ellipse() or url() -preset. To move the selected point, use mouse, touch or Arrow -keys. When using Arrow -keys, hold Ctrl to move point in smaller intervals.
The polygon() function is an inbuilt function in CSS which is used with the filter property to create a polygon of images or text. Syntax: polygon( percentage | length); Parameter: This function accepts two parameter percentage or length which is used to hold the value of polygon size.
Look again at shape-outside
.
You don't set it on the text container, but other elements around the text.
In your case, you may need to have at least 2 div
's for the text to flow around.
There is an example of text flowing between 2 polygon
s on this page.
https://www.html5rocks.com/en/tutorials/shapes/getting-started/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With