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.
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>