Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="center">
            <div class="label">
                Luna
            </div>
            <div class="sun"></div>
            <div class="moon">
                <div class="moon__darkSide">
                </div>
                <div class="moon__half moon__half--a">
                </div>
                <div class="moon__half moon__half--b">
                </div>
            </div>
        </div>
              
            
!

CSS

              
                $moon: #DFD8C8;
$background: darken($moon, 10%);
$darkSide: darken($moon, 40%);

$cycleTime: 30;
$moonSize: 250px;

body {
    margin: 0;
    padding: 0;
}

.center {
     display: flex;
     flex-flow: column;
     align-items: center;
     justify-content: center;
     width: 100vw;
     height: 100vh;
     background-color: $background;
     overflow: hidden;
}
.sun {
    background: radial-gradient(white 50.9999%, transparent 51%, transparent 100%);
    position: absolute;
    top: 50%;
    margin: (-50-$moonSize) auto auto;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 1px solid white;
    opacity: 1;
    transform-origin: 50% $moonSize+50;
    animation: rotateSun #{$cycleTime}s linear infinite;
}
.label {
    font-family: 'Bungee Hairline', monospace;
    font-size: 50px;
    color: $darkSide;
    margin: -.5em auto auto;
    width: 100%;
    position: absolute;
    top: 50%;
    left: 1em;
}

.moon {
    width: $moonSize;
    height: $moonSize;
    min-width: $moonSize;
    min-height: $moonSize;
    margin: auto;
    overflow: hidden;
    position: relative;
    animation: flipAnimation #{$cycleTime}s linear infinite;

    &__darkSide {
        position: absolute;
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: $darkSide;
    }

    &__half {
        width: 50%;
        height: 100%;
        position: absolute;

        &--a {
            left: 0;
            border-radius: $moonSize/2 0 0 $moonSize/2;
            transform-origin: right;
            background-color: $moon;
        }
        &--b {
            right: 0;
            border-radius: 0 $moonSize/2 $moonSize/2 0;
            transform-origin: left;
            animation: phase #{$cycleTime/2}s linear infinite alternate;

        }
    }
}

// flip animation in order to loop it back and forth
@keyframes flipAnimation {
    0% {
        transform: scaleX(-1);
    }
    49.99% {
        transform: scaleX(-1);
    }
    50% {
        transform: scaleX(1);
    }
    100% {
        transform: scaleX(1);
    }
}

// animation for the phase
@keyframes phase {
    0% {
        transform: scaleX(-1);
        background-color: $darkSide;
    }
    49.99% {
        background-color: $darkSide;
    }
    50% {
        background-color: $moon;
    }
    100% {
        transform: scaleX(1);
        background-color: $moon;
    }
}
@keyframes rotateSun {
    0% {
        transform: rotateZ(0deg);
    }
    100% {
        transform: rotateZ(360deg);
    }

}

              
            
!

JS

              
                
              
            
!
999px

Console