Skip to content

Instantly share code, notes, and snippets.

@sakamies
Created March 28, 2012 10:37
Show Gist options
  • Save sakamies/2225318 to your computer and use it in GitHub Desktop.
Save sakamies/2225318 to your computer and use it in GitHub Desktop.
Pixel Perfect CSS Rotation
/* Pixel Perfect CSS Rotation */
body {
text-align: center;
}
.clock {
display: inline-block;
background: black;
border-radius: 100%;
width: 101px;
height: 101px;
position: relative;
}
.hand {
position: absolute;
top: 50%;
left: 50%;
width: 40px;
height: 1px;
background: red;
transition: all .5s ease;
transform-origin: left center;
}
.sharp.hand {
transform-origin: 1.25% 50%; /* 0.5/40*100 */
/* Set the origin exactly to the center of
the first pixel from the left */
}
.clock:hover .hand {
background: white;
transform: rotateZ(90deg);
}
<small>Hover clocks to rotate the hand 90 degrees.</small>
<h3>Blurry clock hand</h3>
<div class="clock">
<div class="hand"> </div>
</div>
<h3>Sharp clock hand</h3>
<div class="clock">
<div class="sharp hand"> </div>
</div>
{"view":"separate","seethrough":"","prefixfree":"1","page":"all"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment