I am trying to make this design with CSS since I will put a website and the title of each post, depending on its length, the background will adapt but I would like the triangle below to do so too, so I still can’t do that.
So far I have managed to do something similar with CSS. Here is my code:
.pentagon {
display: inline-block;
width: fit-content;
min-width: 50px;
min-height: 50px;
background-color: #b6ce52;
position: relative;
padding: 2px 10px 2px 10px;
font-weight: bold;
}
.pentagon:before {
content: "";
position: absolute;
bottom: -10px;
left: 50%;
transform: translateX(-50%) rotate(360deg);
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #b6ce52;
}
<div class="pentagon">
<p>Title of post</p>
</div>
How could I adapt my code or what values would I have to add to achieve the example layout? I would greatly appreciate your help.
2
Answers
I think you can solve your problem by playing a bit with the clip-path (polygon) CSS property.
Here you can find the documentation with examples:
https://developer.mozilla.org/en-US/docs/Web/CSS/clip-path
This is a useful clip-path generator instead:
https://10015.io/tools/css-clip-path-generator
You could, in addition to existing answers, use the
conic-gradient()
background-image
as below, with explanatory comments in the CSS: