The effect

The renderings are as follows

Implementation approach

  1. Div implements a rectangular shadow of the sun
  2. Before the pseudo-element makes another shadow rectangle, and the existing transition is 90°
  3. Draw a circle for the after pseudo-element to implement the sun style

Dom structure

Use two nested div containers, the parent to control the position of the icon display, and the child to write a shadow rectangle for the sun.

<div class="container">
    <div class="sunny"></div>
</div>Copy the code

CSS styles

1, define the parent container style, control icon position, incidentally to the whole page to add a background color, convenient preview

body{
    background: rgba(73, 74, 95, 1);
}

.container{
    width: 170px;
    height: 170px;
    position: relative;
    margin: 250px auto;
}Copy the code

2, shadow rectangle style, with a 360° rotation animation

.sunny{ width: 20px; height: 140px; position: absolute; top: 20px; left: 90px; Background: -webkit-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,0.8) 50%, rgba(255,255,255,0) 100%); animation: sunny 15s linear infinite; } @keyframes sunny { 0%{ transform: rotate(0deg); } 100%{ transform: rotate(360deg); }}Copy the code

3. Write another vertical shadow rectangle

.sunny::before{
    content: ' ';
    width: 20px;
    height: 140px;
    position: absolute;
    bottom: 0;
    left: 0;
    background: -webkit-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,0.8) 50%, rgba(255,255,255,0) 100%);
    transform: rotate(90deg)
}Copy the code

The pattern of the sun circle

.sunny::after{
    content: ' ';
    width: 80px;
    height: 80px;
    position: absolute;
    top: 30px;
    left: -30px;
    background: #ffee44;
    border-radius: 50%;
    box-shadow: rgba(255,255,0,0.2) 0 0 0 15px;
}Copy the code