First time working with clip path and shape outside, I’m trying to write text inside a triangle with text being clipped. I already tried svg solutions, but text becomes very unreadable which is bad for seo, text readers, etc. (something like "lor em ip sum" )
I was trying this solution, it partially worked, but obviously top area can’t be "joined" by the side shapes, but I’m starting to think that achieving what I’m thinking is almost impossible in CSS.
Does someone have a suggestion? I also searched for a JavaScript library but couldn’t find
.container {
width: 600p;
height: 600px;
background: white;
max-width:600px;
position:relative;
}
.left-shape{
shape-outside: polygon(0% 100%, 0% 0%, 50% 0%);
clip-path:polygon(0% 100%, 0% 0%, 50% 0%);
float: left;
width: 50%;
height: 100%;
background:yellow;
}
.right-shape{
shape-outside: polygon(50% 0%, 100% 0%, 100% 100%);
clip-path: polygon(50% 0%, 100% 0%, 100% 100%);
float: right;
width: 50%;
height: 100%;
background:yellow;
}
.container p {
position:relative;
top: 50px
}
<div class="container">
<div class="left-shape"></div>
<div class="right-shape"></div>
<p>Aenean ac pellentesque lacus, sit amet posuere nisl. Nunc consequat fermentum bibendum. Sed congue quis est ac pellentesque. Donec euismod turpis et massa pretium condimentum. Mauris id felis a enim consequat elementum non vel nisl. Integer nulla nulla, aliquet sed justo nec, gravida pulvinar purus. Suspendisse venenatis tempor dapibus. Sed ac porttitor mauris, sit amet condimentum lacus. Vivamus convallis risus ac augue mattis finibus. Pellentesque in pharetra felis. Integer vel dictum nibh. Donec nec scelerisque sem. Phasellus hendrerit at dolor eu mattis. Aliquam ac ante velit. Nullam tincidunt nibh ut urna euismod placerat.
</p>
</div>
2
Answers
You are almost good, you need to rectify the
clip-path
. Your element is taking 50% of the width so you don’t need 50% in the polygonAs @temani-afif already answered https://stackoverflow.com/a/70141997/11974339
I just want to add one little thing to make this better.
Use
text-align: justify;
which will make your text fit the shape.And
If breaking word in the starting is no problem for you you can play with
word-break: break-word;
orword-break: break-all;