Reputation: 3687
Updated again with Safari screenshot after @LGSon's answer:
Update:
Thanks for your answers, but the following code does not produce the correct effet, one can clearly see the separation between the SVG and the a
tag because of the difference in height:
.divsclass {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 146 206'%3E%3Cdefs%3E%3Cstyle%3E.c1%7Bfill:%23fff;%7D.c2%7Bfill:none;stroke:%23a0310f;stroke-linecap:round;stroke-miterlimit:10;stroke-width:10px;%7D%3C/style%3E%3C/defs%3E%3Cpath d='M146 0H98.53l-1 .47-94 94a12 12 0 0 0 0 17l94 94L99 206h47z' class='c1'/%3E%3Cpath d='M113.18 28.2l-73 74.8 73 74.81' class='c2'/%3E%3C/svg%3E");
background-repeat: no-repeat;
}
.divsclass a {
color: red;
text-transform: uppercase;
background-color: white;
margin-left: .75em;
border-bottom-right-radius: 10px;
border-top-right-radius: 10px;
font-size: 75%;
}
<div style="padding: 1em; background: black">
<div class="divsclass"><a role="button">BACK</a></div>
</div>
I'm trying to create the following button where the text inside it (BACK in the example below) can be of variable length. I'm trying with a background image on the left and a border radius on the right but it's not working (using :before
). Any ideas?
P.S. I do have an image of the left triangle as a separate SVG if that helps.
Upvotes: 0
Views: 1464
Reputation: 87211
This can be done using CSS alone in combination with the pseudo elements
a {
position: relative;
display: inline-block;
padding: 2px 10px 2px 20px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
overflow: hidden;
text-decoration: none;
}
a::before,
a::after {
position: absolute;
content: '';
left: 0;
top: 50%;
width: 100%;
padding-bottom: 100%;
background: lightgray;
transform: rotate(-45deg);
transform-origin: left top;
z-index: -1;
}
a::after {
left: 5px;
border: 1px solid black;
}
<a href="#">BACK</a>
Updated
And here is a version using the existing SVG and a pseudo
span {
display: inline-block;
background-color: black;
padding: 2px 10px 2px 20px;
}
a {
position: relative;
display: block;
color: red;
padding: 2px 10px 2px 0;
text-transform: uppercase;
background-color: white;
border-bottom-right-radius: 10px;
border-top-right-radius: 10px;
font-size: 75%;
}
a::before {
content: '';
position: absolute;
top: 0;
left: -14px;
height: 100%;
width: 15px;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 146 206'%3E%3Cdefs%3E%3Cstyle%3E.c1%7Bfill:%23fff;%7D.c2%7Bfill:none;stroke:%23a0310f;stroke-linecap:round;stroke-miterlimit:10;stroke-width:10px;%7D%3C/style%3E%3C/defs%3E%3Cpath d='M146 0H98.53l-1 .47-94 94a12 12 0 0 0 0 17l94 94L99 206h47z' class='c1'/%3E%3Cpath d='M113.18 28.2l-73 74.8 73 74.81' class='c2'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-size: 100%;
background-position: center;
}
<span><a role="button">BACK</a></span>
Upvotes: 1
Reputation: 49
If you use a div as a button and an image as a background you can make your CSS like this:
div.divsclass {
border-radius: 15px 50px 30px 5px:
}
So you can set the border-radius in all of the 4 corners, if you want to only with CSS. Or edit your SVG, as mentioned before.
Upvotes: 0