To apply a gradient border on an irregular shape using a pseudo-element, follow these steps:
<div class="irregular-shape">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
.irregular-shape {
position: relative;
width: 200px;
height: 150px;
background-color: #ccc;
}
.irregular-shape::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
.irregular-shape::before {
background: linear-gradient(to right, #f00, #00f);
}
/* or */
.irregular-shape::before {
background: radial-gradient(circle at center, #f00, #00f);
}
.irregular-shape::before {
transform: skew(30deg);
transform-origin: bottom;
}
Here's the complete CSS example:
.irregular-shape {
position: relative;
width: 200px;
height: 150px;
background-color: #ccc;
}
.irregular-shape::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
background: linear-gradient(to right, #f00, #00f);
transform: skew(30deg);
transform-origin: bottom;
}
Asked: 2023-07-07 12:50:20 +0000
Seen: 11 times
Last updated: Jul 07 '23