simple-react-compass
Version:
Simple React Compass
237 lines (206 loc) • 4.47 kB
CSS
/**
* Compass.css
* @author Tomas Malio
* @email tomasmalio@gmail.com
* @date 2023-05-14
* @version 1.0
* @license MIT
*/
/* Compass */
.compass {
width: 300px; /* width of the compass */
height: 300px; /* height of the compass */
position: relative;
margin: auto;
}
.compass__circle {
width: 100%;
height: 100%;
border-radius: 50%;
background-color: #2c2c2c; /* background color of the compass */
border-color: #ff6441; /* border color of the compass */
border-width: 4px; /* border width of the compass */
border-style: solid;
position: relative;
}
@keyframes compassWiggle {
0% { transform: rotate(-1deg); }
50% { transform: rotate(1deg); }
100% { transform: rotate(-1deg); }
}
.compass__arrow-wrapper {
display: inline-block;
left: 50%;
position: absolute;
transform: translate(-50%, -50%) rotate(var(--arrow-rotation));
top: 50%;
z-index: 1;
}
/* Arrows (North and South) */
/* The arrows are positioned in the center of the compass */
/* and rotate around the center point */
/* The north arrow is colored with $north-color */
/* and the south arrow is colored with $south-color */
.compass__arrow {
animation: compassWiggle 2s ease-in-out infinite;
height: 100px;
transform-origin: center center;
width: 6px;
z-index: 2;
}
.compass__arrow::before,
.compass__arrow::after {
content: '';
position: absolute;
left: 0;
width: 100%;
height: 50%;
}
.compass__arrow::before {
top: 0;
background-color: #ff6441; /* color of the north arrow */
clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}
.compass__arrow::after {
bottom: 0;
background-color: #ffffff; /* color of the south arrow */
clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.compass__labels {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.compass__labels .degree {
font-size: 28px;
font-weight: bold;
color: #ffffff;
}
.compass__labels .direction {
font-size: 20px;
color: #ffffff;
opacity: 0.8;
}
.compass__line {
position: absolute;
background-color: #ffffff0f;
z-index: 0;
pointer-events: none;
border-radius: 1px;
}
.compass__line--vertical {
top: 20%;
left: 50%;
width: 2px;
height: 60%;
transform: translateX(-50%);
}
.compass__line--horizontal {
top: 50%;
left: 20%;
width: 60%;
height: 2px;
transform: translateY(-50%);
}
.compass__mark--direction-h::before {
top: 10%;
}
.compass__mark--direction-h::after {
bottom: 10%;
}
.compass__mark--direction-v::before {
top: 10%;
}
.compass__mark--direction-v::after {
bottom: 10%;
}
.compass__line--vertical {
top: 25%;
height: 50%;
}
.compass__line--horizontal {
left: 25%;
width: 50%;
}
.compass__ticks {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
pointer-events: none;
}
.compass__tick {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
transform-origin: center center;
}
.compass__tick span {
position: absolute;
top: 10px; /* Distance from the border */
left: 50%;
width: 1px;
height: 5px;
background-color: #ffffff55;
transform: translateX(-50%);
border-radius: 2px;
}
/* The pivot point of the compass */
/* The pivot point is the center of the compass */
/* and is used to rotate the compass */
/* The pivot point is colored with $circle-background-color */
/* and has a box shadow to give it a 3D effect */
/* The pivot point is positioned in the center of the compass */
/* and is used to rotate the compass */
/* The pivot point is a circle with a diameter of 10px */
.compass__pivot {
position: absolute;
top: 50%;
left: 50%;
width: 10px;
height: 10px;
background-color: #646464;
border-radius: 50%;
transform: translate(-50%, -50%);
z-index: 5;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3), inset 0 0 2px rgba(0, 0, 0, 0.4);
}
.compass__cardinals {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.compass__cardinals span {
position: absolute;
color: #ffffff;
font-weight: bold;
font-size: 18px;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
}
.compass__cardinals .N {
top: 10px;
left: 50%;
transform: translateX(-50%);
}
.compass__cardinals .S {
bottom: 10px;
left: 50%;
transform: translateX(-50%);
}
.compass__cardinals .E {
right: 10px;
top: 50%;
transform: translateY(-50%);
}
.compass__cardinals .W {
left: 10px;
top: 50%;
transform: translateY(-50%);
}