CSSのみで、回転する虹色ボーダーの実装です。虹色を表示するclass名"rainbow"のdiv要素のboxを作り、「::before疑似要素」を使って、boxの背景を中心から90度ずつ4つに分割し、それぞれ背景色を緑、黄色、赤、青に塗ります。その中心を回転軸として「@keyframes rotate」で回転させます。
次に「::after疑似要素」を使って、boxの真上に元のサイズを縦横とも12ピクセル小さくした新しいboxを載せます。新しいboxの背景色を白で塗りつぶし、topとleftから6ピクセルずつずらすことで幅6ピクセルの隙間ができ、そこから下側の背景色がのぞいて、回転する虹色のボーダーとなります。
サンプル
回転する虹色(4色)のボーダー
サンプルのhtmlソース
<div class="rainbow">
回転する虹色(4色)ボーダー
</div>
サンプルのCSSソース
.rainbow {
box-sizing: border-box;
position: relative;
z-index: 0;
width: 400px;
height: 300px;
margin:5px auto;
border-radius: 10px;
overflow: hidden;
padding: 2rem;
}
@-webkit-keyframes rotate {
100% {
-webkit-transform: rotate(1turn);
transform: rotate(1turn);
}
}
@keyframes rotate {
100% {
-webkit-transform: rotate(1turn);
transform: rotate(1turn);
}
}
.rainbow::before {
content: '';
position: absolute;
z-index: -2;
left: -50%;
top: -50%;
width: 200%;
height: 200%;
background-color: #399953;
background-repeat: no-repeat;
background-size: 50% 50%, 50% 50%;
background-position: 0 0, 100% 0, 100% 100%, 0 100%;
background-image: linear-gradient(#399953, #399953), linear-gradient(#fbb300, #fbb300), linear-gradient(#d53e33, #d53e33), linear-gradient(#377af5, #377af5);
-webkit-animation: rotate 4s linear infinite;
animation: rotate 4s linear infinite;
}
.rainbow::after {
content: '';
position: absolute;
z-index: -1;
left: 6px;
top: 6px;
width: calc(100% - 12px);
height: calc(100% - 12px);
background: white;
border-radius: 5px;
}