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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

            
              <section class="wrapper">
  <div>
    <h2>Guess A Number</h2>
    <p>Using Sass-y magic, the computer "knows" a random number between 1 and 5.</p>
    <p>See if you can guess the right one (there will be a party when you do).</p>
  </div>
  <form>
    <fieldset>
      <label for="number1" tabindex="0">
      <input type="radio" name="number" id="number1" value="1"/>
      <span>1</span>
    </label>
      <label for="number2" tabindex="0">
      <input type="radio" name="number" id="number2" value="2"/>
      <span>2</span>
    </label>
      <label for="number3" tabindex="0">
      <input type="radio" name="number" id="number3" value="3"/>
      <span>3</span>
    </label>
      <label for="number4" tabindex="0">
      <input type="radio" name="number" id="number4" value="4"/>
      <span>4</span>
    </label>
      <label for="number5" tabindex="0">
      <input type="radio" name="number" id="number5" value="5"/>
      <span>5</span>
    </label>
    </fieldset>
  </form>
</section>
            
          
!
            
              //set random number
$random-number: random(5);

//mixin for if/else
@mixin game-logic ($number) {
  @if round($random-number) == $number {
    animation: party-colors 2s infinite;
    background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/229892/ice-cream-parrot.gif);
    background-repeat: no-repeat;
    background-size: cover;
    transition: background-color 1s ease;
  }
  @else {
    background-color: grey;
    transition: background-color 1s ease;
  }
}

//include mixin for use
@each $number in 1, 2, 3, 4, 5 {
  #number#{$number}:checked + span::before {
    @include game-logic($number);
  }
}

//keyframe for party-color animation
@keyframes party-colors {
  0% {background-color: teal;}
  25% {background-color: hotpink;}
  50% {background-color: dodgerblue;}
  75% {background-color: gold;}
  100% {background-color: teal;}
}

//The following three steps style the radio buttons
//This tutorial was my reference in that process: https://www.sitepoint.com/replacing-radio-buttons-without-replacing-radio-buttons/

//"hide" radio, still keeping it accessible
//from HTML5 Boilerplate
input[type="radio"] {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
}

//center number below "radio" button
input[type="radio"] + span {
  display: inline-block;
  text-align: center;
  width: 5.3rem;
}

//styles new clickable "radio" area
//uses the + adjacent sibling selector and the ::before pseudo element to style the click area
input[type="radio"] + span::before {
  border: 0.125em solid #346699;
  content: '';
  display: inline-block;
  height: 5rem;
  width: 5rem;
}


//general styles
body {
  color: #346699;
  font-family: Helvetica, sans-serif;
  line-height: 1.4;
}

.wrapper {
  margin: 2rem auto;
  max-width: 40rem;
  width: 95%;
}

h2 {
  font-size: 1.5rem;
  font-weight: bold;
}

div {
  margin-bottom: 2rem;
}

label {
  margin-right: 1rem;
  &:last-of-type {
    margin-right: 0;
  }
}

//removes default focus styling
label:focus {
  outline: none;
}

//adds custom focus state
label:focus input[type="radio"] + span {
  border: 2px dashed black;
  transition: border .3s ease;
}

//add border so that focus state doesn't jump
input[type="radio"] + span {
  border: 2px dashed transparent;
  transition: border .3s ease;
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console