cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div class="sky">
  <div class="sky-level">
    <!--
      Will be populated with several
      divs in JS. e.g:
      <div></div>
      <div></div>
      <div></div>
      ...
    -->
  </div>
  <div class="sky-level"></div>
  <div class="sky-level"></div>
  <div class="sky-level"></div>
  <div class="sky-level"></div>
  <div class="sky-level"></div>
  <div id="stars" class="sky-stars">
    <!--
    Markup for stars here. e.g.:
    span.dot
    span.dot.dot--blinking
    span.star.star--lg
      span.star__part
      span.star__part
    span.star.star--sm
      span.star__part
      span.star__part
    ...
    -->
  </div>
</div>
            
          
!
            
              $transition: 40;  // These 4 values
$dots: 12;        // should be
$lg-stars: 2;     // synced with
$sm-stars: 3;     // JS code.
$px: 4px;
$lg-star: 48px;
$sm-star: 28px;
$star-color: #FEC8C9;
$level-colors: (
  #F9329D,
  #FE5EB4,
  #FE6FBB,
  #FE70EE,
  #E270FE,
  #BA70FE
);
$levels: length($level-colors);

html, body, .sky {
  width: 100%;
  height: 100%;
}

.sky {
  position: relative;
}

.sky-level {
  box-sizing: border-box;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  
  $percent: 100 / $levels;
  @for $i from 1 through $levels {
    &:nth-child(#{$i}) {
      padding-top: #{$percent * $i}vh;
      height: #{$percent * $i}vh;
      color: nth($level-colors, $i);
      background: currentColor;
      z-index: $levels - $i;
    }
  }
    
  div {
    float: left;
    height: $px;
    background: currentColor;
  }
    
  $p: ceil(20 / $transition);
  @for $i from 1 through $levels {
    @for $j from 1 through $transition {
      &:nth-child(#{$i})
      div:nth-child(#{$j}) {
        $r: $p * ($transition - $j + 1);
        width: #{random($r) + "%"};
        margin-left:
          #{random(25) + "%"};
      }
    }
  }
}

.sky-stars {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: $levels + 1;
  
  .dot {
    position: absolute;
    width: $px;
    height: $px;
    background: $star-color;
    
    @for $i from 1 through $dots {
      &:nth-child(#{$i}) {
        top: #{random(90) + "%"};
        left: #{random(100) + "%"};
      }
    }
    
    &--blinking {
      animation:
        blink .25s linear infinite;
    }
  }
  
  .star {
    position: absolute;
    color: $star-color;
    animation:
      scale .5s linear infinite;
    
    &--sm {
      width: $sm-star;
      height: $sm-star;
      
      @for $i from 1 through $sm-stars {
        $index: $dots + $i;
        &:nth-child(#{$index}) {
          top: #{random(80) + "%"};
          left: #{random(90) + "%"};
        }
      }
    }
    
    &--lg {
      width: $lg-star;
      height: $lg-star;
      
      @for $i from 1 through $lg-stars {
        $index: $dots + $sm-stars + $i;
        &:nth-child(#{$index}) {
          top: #{random(60) + "%"};
          left: #{random(80) + "%"};
        }
      }
    }
    
    &::after {
      content: "";
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background: currentColor;
      animation:
        grow .5s linear infinite;
    }
    
    &__part {
      position: absolute;
      background: currentColor;
      
      &:nth-child(1) {
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 100%;
        height: 20%;
      }
      
      &:nth-child(2) {
        left: 50%;
        top: 0;
        transform: translateX(-50%);
        width: 20%;
        height: 100%;
      }
    }
  }
}

@keyframes blink {
  0%, 32%, 67% {
    opacity: 1;
  }
  33%, 66% {
    opacity: 0;
  }
}

@keyframes scale {
  0%, 16.4%,
  83.6%, 100% {
    transform: scale(.75, .75);
  }
  16.5%, 33%,
  66.6%, 83.5% {
    transform: scale(1, 1);
  }
}

@keyframes grow {
  0%, 16.4%,
  83.6%, 100% {
    width: 20%;
    height: 20%;
  }
  16.5%, 33%,
  66.6%, 83.5% {
    width: 50%;
    height: 50%;
  }
  33.1%, 50%, 66.5% {
    width: 100%;
    height: 100%;
  }
}
            
          
!
            
              var transition = 40
var dots = 12
var lgStars = 2
var smStars = 3

function nJoin(n, markup) {
  var fn = typeof markup == 'function' ?
        markup : e => markup
  return new Array(n)
    .join(' ')
    .split(' ')
    .map(fn)
    .join('')
}

// Transition layers
Array
  .from(document.querySelectorAll(
    '.sky-level'
  ))
  .slice(0, -1)
  .forEach(layer => {
    layer.innerHTML = nJoin(transition,
      '<div></div>'
    )
  })

// Stars and dots
var bigStars = nJoin(lgStars, `
  <span class="star star--lg">
    <span class="star__part"></span>
    <span class="star__part"></span>
  </span>
`)

var smallStars = nJoin(smStars, `
  <span class="star star--sm">
    <span class="star__part"></span>
    <span class="star__part"></span>
  </span>
`)

var dotStars = nJoin(dots, e => {
  var isBlinking = Math.random() < .33
  var className = 'dot'
  isBlinking && (
    className += ' dot--blinking'
  )
  return `
    <span class="${className}"></span>
  `
})

document
  .getElementById('stars')
  .innerHTML += (
    dotStars + 
    smallStars +
    bigStars
  )
            
          
!
999px
Loading ..................

Console