I'm able to create the same button with CSS. The rounded corners are the important part corners are the main reason. Triangle button with rounded corners, please see my below code and image
.lngbtn {
position: relative;
width: 150px;
height: 50px;
margin: 50px;
color: #FFFFFF;
background-color: #f4d046;
text-align: center;
line-height: 48px;
padding: 16px;
font-weight: bold;
}
.lngbtn:before {
content:"";
position: absolute;
right: 100%;
top:0px;
width:0px;
height:0px;
border-top:25px solid transparent;
border-right:30px solid #f4d046;
border-bottom:25px solid transparent;
}
.lngbtn:after {
content:"";
position: absolute;
left: 100%;
top:0px;
width:0px;
height:0px;
border-top:25px solid transparent;
border-left:30px solid #f4d046;
border-bottom:25px solid transparent;
}
<a href="#" class="lngbtn">Get to know us</a>
Here is how we can achieve with css
Try this one.
I am not saying that this cannot be achieved with CSS but doing this with CSS would be a tedious job. SVG is always the recommended tool for creating complex shapes like this (and this particular shape is tough to create even using SVG).
SVGs are:
In SVG, it just requires a
path
to be created in the form of a rounded hexagon and then for thatpath
image to be placed behind the container.Below is some explanation about the various commands used in the
path
element'sd
attribute (but I'd strongly advise you to learn SVG commands - here is a tutor from the MDN):M
- moves the imaginary pen to the point specified by the coordinates.L
- draws a straight line from the point represented by the previous coordinate to current one.Q
- Draws a quadratic curve from the current position of the pen to the point that is indicated by the second set of coordinates that follow theQ
command. The first set of coordinates represent the control point. This control point determines the slope of the curve.z
- Closes the shape by drawing a straight line from the current pen position to the starting point.For your case, since you need the shape to be a button (or a link), you should wrap the
path
element inside aa
(SVG anchor element) like in the below snippet and use thetext
element to add text (like aspan
). You'd also notice that I have modified the shape slightly to make the angles on the sides little narrower.Notes:
The shape is not 100% perfect but I'd leave the fine tuning to you. The answer is to help you with a starting point.
I've added a
stroke
(border) just to show that it also can be done. If not needed you can remove it by removing thestroke
andstroke-width
properties from the CSS forpath
element.Don't be put off by how lengthy the SVG code is, it is so big only because I've repeated it more than once - once for each container. That can be reduced.
Since the triangles and the main body of the button are the same color, you can make your
before
andafter
into squares and rotate them by 45 degrees withtransform: rotate(45deg)
to make it look like they are triangles. You can then useborder-radius
to make the edges rounded. It'll take some positioning and sizing to get them look right. I've made an example at https://jsfiddle.net/93zbLqLy/The downside of this method is that you can only have triangle edges that are 45 degrees.