I am currently building a website which requires buttons to have a slant on the left hand side of the button. The website is responsive and the button requires rounded corners too. I am trying to avoid using background images too.
Would someone be able to show me a solution to this? Ignore the icon on the button, I am able to do this. I just need the slanted side.
Sample jsfiddle
body {
background: lightblue;
font-family: sans-serif;
}
div {
background: purple;
width: 200px;
padding: 30px;
border: 3px solid white;
color: white;
}
<div>Some Text</div>
Note: I am adding a separate answer because though the answers that I linked in comment seem to give a solution, this one is a bit more complex due to the presence of border also along with the border-radius.
The shape can be created by using the following parts:
I have also added a hover
effect to the snippet to demonstrate the responsive nature of the shape.
.outer {
position: relative;
height: 75px;
width: 300px;
text-align: center;
line-height: 75px;
color: white;
text-transform: uppercase;
}
.outer:before,
.outer:after {
position: absolute;
content: '';
top: 0px;
height: 100%;
width: 55%;
background: purple;
border: 2px solid white;
border-left-width: 3px;
z-index: -1;
}
.outer:before {
left: 0px;
border-radius: 20px;
border-right: none;
transform: skew(20deg);
transform-origin: top left;
}
.outer:after {
right: 0px;
border-top-right-radius: 20px;
border-bottom-right-radius: 20px;
border-left: none;
}
/* Just for demo of responsive nature */
.outer{
transition: all 1s;
}
.outer:hover{
height: 100px;
width: 400px;
line-height: 100px;
}
body{
background: lightblue;
}
<div class='outer'>
Call me back
</div>
Advantage:
In the below snippet, I have given each component a different color to visually illustrate how the shape is achieved:
.outer {
position: relative;
height: 75px;
width: 300px;
text-align: center;
line-height: 75px;
color: white;
text-transform: uppercase;
}
.outer:before,
.outer:after {
position: absolute;
content: '';
top: 0px;
height: 100%;
width: 55%;
background: purple;
border: 2px solid white;
border-left-width: 3px;
z-index: -1;
}
.outer:before {
left: 0px;
border-radius: 20px;
border-right: none;
transform: skew(20deg);
transform-origin: top left;
background: seagreen;
border-color: red;
}
.outer:after {
right: 0px;
border-top-right-radius: 20px;
border-bottom-right-radius: 20px;
border-left: none;
background: yellowgreen;
border-color: maroon;
}
/* Just for demo of responsive nature */
.outer{
transition: all 1s;
}
.outer:hover{
height: 100px;
width: 400px;
line-height: 100px;
}
body{
background: lightblue;
}
<div class='outer'>
Call me back
</div>
Yes You can do using an white overlay using css-pseudo element before or after like this
.slantButton {
position: relative;
background-color: #8D3F81;
border: 1px solid transparent;
border-radius: 5px 5px 5px 20px;
color: #fff;
padding: 10px 20px;
text-transform: uppercase;
font-size: 18px;
cursor: pointer;
outline: 0;
}
.slantButton:before {
content: '';
position: absolute;
top: 0;
left: -5px;
width: 0;
height: 0;
border-bottom: 42px solid #fff;
border-right: 16px solid transparent;
}
<button class="slantButton">Call Me Back</button>
I have applied different border radius to bottom left corner using
border-radius: 5px 5px 5px 20px;
Then using css triangle in pseudo element. Made one white overlay of triangle and made slant edge as you suggested
.slantButton {
position: relative;
background-color: #8D3F81;
border: 1px solid transparent;
border-radius: 5px 5px 5px 20px;
color: #fff;
padding: 10px 20px;
text-transform: uppercase;
font-size: 18px;
cursor: pointer;
outline: 0;
}
.slantButton:before {
content: '';
position: absolute;
top: 0;
left: -5px;
width: 0;
height: 0;
border-bottom: 42px solid rgba(0,0,0,0.5);
border-right: 16px solid transparent;
}
<button class="slantButton">Call Me Back</button>
This is also possible using CSS border-radius' by setting multiple values.
This does have a bit more curvature than your example image but it is much cleaner and doesn't require extra elements or pseudo elements.
body {
background: lightblue;
font-family: sans-serif;
}
div {
background: purple;
width: 200px;
padding: 30px;
border: 3px solid white;
border-radius: 15px;
border-bottom-left-radius: 50px 150px;
color: white;
}
<div>Some Text</div>
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