34
loading...
This website collects cookies to deliver better user experience
background-image
for the sprite map and flexbox
for connecting sprites is all you need:.sprite {
background-image: url('https://example.com/sprite.png');
background-size: 475px 440px;
width: 28px;
height: 61px;
}
.button {
display: flex;
&__left {
@extend .sprite;
background-position: -286px -341px;
}
&__right {
@extend .sprite;
background-position: -257px -341px;
}
}
.button__inner {
background-image: url('https://example.com/sprite.png');
background-size: 100% 100%;
height: 61px;
max-width: 12em;
min-width: 165px;
margin-left: -1px;
margin-right: -1px;
display: inline-block;
flex: 1 1 auto;
text-align: center;
p {
display: inherit;
margin-top: 1.25rem;
font-weight: bold;
font-style: italic;
text-transform: uppercase;
}
}
div
elements (one for each sprite):<div class="button">
<div class="button__left"></div>
<div class="button__inner">
<p>Sprite Button</p>
</div>
<div class="button__right"></div>
</div>
.button {
background-color: transparent;
display: inline-block;
margin: 15px auto;
position: relative;
&:after,
&:before {
border-color: white;
border-style: solid;
content: "";
display: block;
height: 16px;
}
&:before {
top: 0;
right: 0;
border-width: 1px 1px 0 0;
margin-left: 16px;
}
&:after {
bottom: 0;
left: 0;
border-width: 0 0 1px 1px;
margin-right: 16px;
}
}
.button__inner {
display: block;
padding: 0 35px;
text-align: center;
text-transform: uppercase;
line-height: 16px;
background-color: transparent;
border-left: 1px solid white;
border-right: 1px solid white;
color: white;
&:after,
&:before {
border-style: solid;
border-color: transparent;
border-width: 0 0 16px 16px;
content: "";
position: absolute;
background-size: 16px 24px;
background-image: repeating-linear-gradient(
-45deg,
white,
white 1px,
transparent 0,
transparent 16px
);
}
&:before {
top: 0;
left: 0;
}
&:after {
bottom: 0;
right: 0;
transform: rotate(180deg);
}
}
div
and a span
for this to work:<div class="button">
<span class="button__inner">
Button Out.
</span>
</div>
@include bevel--opp()
to apply this Sass mixin:/*
* @param $size Bevel size.
* @param $alt Use alternate corners.
*/
@mixin bevel--opp($size: 12px, $alt: false) {
@if $alt {
clip-path: polygon(
0% $size,
$size 0%,
100% 0%,
100% 100%,
100% calc(100% - #{$size}),
calc(100% - #{$size}) 100%,
100% 100%,
0% 100%
);
} @else {
clip-path: polygon(
0% 0%,
0% 0%,
calc(100% - #{$size}) 0%,
100% $size,
100% 100%,
100% 100%,
$size 100%,
0 calc(100% - #{$size})
);
}
}
/*
* @param $size Bevel size.
*/
@mixin bevel--full($size: 12px) {
clip-path: polygon(
0% $size,
$size 0%,
calc(100% - #{$size}) 0%,
100% $size,
100% calc(100% - #{$size}),
calc(100% - #{$size}) 100%,
$size 100%,
0 calc(100% - #{$size})
);
}
.button {
color: white;
background-color: turquoise;
display: inline-block;
padding: 1em;
@include bevel--opp();
&--alt {
@extend .button;
@include bevel--opp($alt: true);
}
&--outline {
@extend .button;
background-color: white;
padding: 0;
.button {
background-color: black;
margin: 1px;
padding: calc(1em - 1px);
}
}
}
<!-- Standard Button -->
<div class="button">Button</div>
<!-- Alternative Button -->
<div class="button--alt">Button</div>
<!-- Fancy Outline Button -->
<div class="button--outline">
<div class="button">Button Out.</div>
</div>
div
elements or overflow. And the code is simpler than the other solutions I’ve mention.clip-path
since that’s the approach I’ve taken with my projects. But, at the end of the day, if any of these approaches work for you, that’s great!