CSS にてオブジェクトをぐるぐる回転させる

ローディングや更新、同期のような時間がかかる処理の場合に、
アイコンフォントをぐるぐる回転させているのを時折見る。
それを CSS のみで実装してみる。

サンプルコード

.rotate と rotate-sample が重要。
他は見た目を整えるために使用。

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
	<style type="text/css">
		html, body {
			margin: 0;
			height: 100%;
		}
		body {
			display: flex;
			align-items: center;
		}
		.square {
			width: 100px;
			height: 100px;
			background: #ccc;
			margin: auto;
		}
		.rotate {
			animation-name: rotate-sample;
			animation-iteration-count: infinite;
			animation-duration: 4s;
			animation-timing-function: linear;
		}
		@keyframes rotate-sample {
			0% {
				transform: rotate(0);
			}
			100% {
				transform: rotate(360deg);
			}
		}
	</style>
</head>
<body>
	<div class="square rotate"></div>
</body>
</html>
カテゴリー:CSS