I tried to create a custom button for me using CSS pseudo elements. I can make it too, but it is background dependent. I mean one of the pseudo elements should be the exact same color of the div background. For example, if I want to place the button in an image or gradient background, then the problem creates. How can I make something like that which is not depend on background objects color ?
My Approach is:
.teno-btn {
border: none;
display: block;
text-align: center;
cursor: pointer;
text-transform: uppercase;
outline: none;
overflow: hidden;
position: relative;
color: #fff;
font-weight: 700;
font-size: 15px;
background-color: #000644;
padding: 17px 40px;
margin: 0 auto;
/* box-shadow: 0 5px 15px rgba(0, 0, 0, 0.20); */
}
.teno-btn span {
position: relative;
z-index: 1;
}
.teno-btn:after {
content: "";
position: absolute;
left: 40px;
top: 40px;
height: 40px;
width: 100px;
background: #ffffff;
-webkit-transform: translateX(-98%) translateY(-25%) rotate(45deg);
transform: translateX(-98%) translateY(-25%) rotate(45deg);
}
.teno-btn:before {
content: "";
position: absolute;
left: 20px;
top: 40px;
height: 40px;
width: 100px;
transform: rotate(45deg);
background: #5ceb95;
-webkit-transform: translateX(-98%) translateY(-25%) rotate(45deg);
transform: translateX(-98%) translateY(-25%) rotate(0deg);
}
<button class="teno-btn mi-ripple mi-ripple-rise">
<span> Download Now </span>
</button>
Here is my expected button that I can use in any background or anywhere:
2
Answers
You can do it like below without pseudo-elements
If you want the cut to be rectangle, we add another variable:
And if your background is a solid coloration, you can use one gradient to define both colors:
There’s no way you can make it independent since you are trying to cover the button’s background using the
::after
pseudo element.The solution would be to use one pseudo element and shape it like a triangle, then cut the bottom left corner of your button so the background behind it becomes visible.
Here is the updated CSS: