<button type="button" class="btn-close">
<span class="icon-cross"></span>
<span class="visually-hidden">Close</span>
</button>
<span class="cross-stand-alone"></span>
<span class="cross-1px"></span>
@use 'sass:math';
// Display a cross with CSS only.
//
// $size : px or em
// $color : color
// $thickness : px
@mixin cross($size: 20px, $color: currentColor, $thickness: 1px) {
margin: 0;
padding: 0;
border: 0;
background: none;
position: relative;
width: $size;
height: $size;
&:before,
&:after {
content: '';
position: absolute;
top: math.div($size - $thickness, 2);
left: 0;
right: 0;
height: $thickness;
background: $color;
border-radius: $thickness;
}
&:before {
transform: rotate(45deg);
}
&:after {
transform: rotate(-45deg);
}
span {
display: block;
}
}
// Example 1.
.btn-close {
margin: 0;
border: 0;
padding: 0;
background: hsl(216, 100, 50);
border-radius: 50%;
width: 80px;
height: 80px;
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
cursor: pointer;
transition: all 150ms;
.icon-cross {
@include cross(40px, #fff, 6px);
}
&:hover,
&:focus {
transform: rotateZ(90deg);
background: hsl(216, 100, 40);
}
}
// Example 2.
.cross-stand-alone {
@include cross(40px, #000, 4px);
}
// Example 3.
.cross-1px {
@include cross(80px, #000);
}
// Demo styles.
body {
display: flex;
flex-flow: row nowrap;
justify-content: space-around;
align-items: center;
align-content: flex-start;
height: 100vh;
}
// For screen readers.
.visually-hidden {
position: absolute !important;
clip: rect(1px, 1px, 1px, 1px);
padding: 0 !important;
border: 0 !important;
height: 1px !important;
width: 1px !important;
overflow: hidden;
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.