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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                // inputs that control the language
input(type="radio", id="en", class="lang", name="lang", value="en", checked=true)
input(type="radio", id="es", class="lang", name="lang", value="es")

// input that control what player's turn it is
input(type="checkbox", id="turn", checked="true")

// inputs and labels that control the piece position for player 1
each players in [1,2]
  each n, index in [0,1,38,3,4,5,6,14,31,9,10,11,12,13,14,26,6,17,18,19,20,42,22,23,24,25,26,27,84,29,30,31,32,33,34,35,44,37,38,39,40,41,42,43,44,45,25,47,48,11,50,67,52,53,54,55,56,57,58,59,60,61,19,63,60,65,66,67,68,69,70,91,72,73,53,75,76,77,98,79,80,81,82,83,84,85,86,94,88,68,90,91,88,93,94,75,96,97,98,80,100,80,98,97,96,75]
    input(type="radio", name="cb-player"+players, id="cb-player"+players+"-"+index, class="cb cb"+n, value=index, checked=(players==2 && n==0))
    label.dice(for="cb-player"+players+"-"+n)
   
    
// intro message in English and Spanish
div#intro
  div
    label(for="es", class="switch") En Español
    label(for="en", class="switch") In English
    h1
    p.from 
      a(href="https://en.wikipedia.org/wiki/Snakes_and_Ladders", target="_blank") Wikipedia:
    p.desc
    p.credit 
    p.start-button
      label(for="cb-player1-0", class="start") 

// message about turn and position
div#turninfo
  span#player
  span#tile-position
  span .
  label#next-turn(for="turn")

// board and piece
div#board 
  div.ficha.player1
  div.ficha.player2
  // numbered tiles, uncomment if svg completed
  //each val in [100,99,98,97,96,95,94,93,92,91,81,82,83,84,85,86,87,88,89,90,80,79,78,77,76,75,74,73,72,71,61,62,63,64,65,66,67,68,69,70,60,59,58,57,56,55,54,53,52,51,41,42,43,44,45,46,47,48,49,50,40,39,38,37,36,35,34,33,32,31,21,22,23,24,25,26,27,28,29,30,20,19,18,17,16,15,14,13,12,11,1,2,3,4,5,6,7,8,9,10]
    div(class="tile tile"+val, data-index=val)
  // svg with all ladders and snakes
  //svg(viewBox="0 0 600 600", width="600px", height="600px")
    line(x1=89, y1=574, x2=140, y2=392)
    line(x1=103, y1=578, x2=153, y2=396)

// congratulatory message when reaching end tile
div#finish 
  div
              
            
!

CSS

              
                /***** dice animation */
@keyframes changeOrder {
  from { z-index: 6;}
  to { z-index: 1; }
}

@-webkit-keyframes changeOrder {
  from { z-index: 6; }
  to { z-index: 1; }
}

/***** language control */
// English
#en:checked {
  ~ #intro {
    [for="en"] { display: none; }
    h1::before { content: "Snake and Ladders"; }
    p.from::before { content: "Text from"; }
    p.desc::before { content: "«Snakes and Ladders is an ancient Indian board game regarded today as a worldwide classic. [...] A number of 'ladders' and 'snakes' are pictured on the board, each connecting two specific board squares. The object of the game is to navigate one's game piece, according to die rolls, from the start (bottom square) to the finish (top square), helped or hindered by ladders and snakes respectively.»"; }
    p.credit::before { content: "This version was developed as a fun project using HTML and CSS, without any JavaScript code. Click on the DICE to roll the dice and move your piece." ; }
    p.start-button label::before { content: "START"; }
  }
  ~ .dice::before { content: "DICE"; }
  ~ #finish {
    > div::before { content: "CONGRATULATIONS! YOU WON!"; }
  }
  ~ #turn {
    &:checked ~ #turninfo #player::before { content: "Player One's turn. "; }
    &:not(:checked) ~ #turninfo #player::before { content: "Player Two's turn. "; }
    ~ #turninfo {
      #tile-position {
        &::before { content: "Currently on tile ";  }
        &::after { content: "START"; } 
      }
      #next-turn::before { content: "Go to next player"; }
    }
  }
}
// Spanish
#es:checked {
  ~ #intro {
    [for="es"] { display: none; }
    h1::before { content: "Serpientes y Escaleras"; }
    p.from::before { content: "Texto de la"; }
    p.desc::before { content: "«Serpientes y escaleras es un antiguo juego de tablero indio, considerado actualmente como un clásico a nivel mundial. [...] El objetivo del juego es lograr que la ficha del jugador llegue desde el inicio —casillero inferior izquierdo— hasta el final —casillero superior izquierdo—, ayudado por las escaleras y evitando las serpientes.»"; }
    p.credit::before { content: "Esta versión fue desarrollada como un proyecto usando HTML y CSS, sin nada de código JavaScript. Pulsa en el DADO para lanzar el dado y mover la ficha." ; }
    p.start-button label::before { content: "COMENZAR"; }
  }
  ~ .dice::before { content: "DADO"; }
  ~ #finish {
    > div::before { content: "¡ENHORABUENA! ¡GANASTE!"; }
  }
  ~ #turn {
    &:checked ~ #turninfo #player::before { content: "Turno del Jugador Uno. "; }
    &:not(:checked) ~ #turninfo #player::before { content: "Turno del Jugador Dos. "; }
    ~ #turninfo {
      #tile-position {
        &::before { content: "Se encuentra en la casilla ";  }
        &::after { content: "INICIO"; } 
      }
      #next-turn::before { content: "Ir al siguiente turno"; }
    }
  }
}

/***** intro message */
#intro {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0,0,0,0.8);
  z-index: 200;
  h1 {
    margin-top: 0;
  }
  p:last-child {
    margin-bottom: 0;
  }
  > div {
    position: absolute;
    top: 50%;
    left: 50%;
    max-width: 80%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 20px;
    font-family: Arial, Verdana, sans-serif;
    border-radius: 3px;
    display: inline-block;
  }
  label.switch {
    float: right;
    display: inline-block;
  }

  label.start {
    display: block;
    text-align: center;
    background: #5588bb;
    color: white;
    padding: 10px;
    border-radius: 2px;
    cursor: pointer;
  }
}

/***** Player and turn information */
#turninfo {
  position: absolute;
  top: 10px;
  left: 10px;
  font-family: arial, verdana, sans-serif;
  #player {
    font-weight: bold;
  }
}

/***** Ending message */
#finish {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.8);
  display: none;
  > div {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 40px;
    text-align: center;
    font-family: Arial, Verdana, sans-serif;
    font-weight: bold;
  }
}

/***** Control of labels and inputs */
input, label { 
  display: none; 
  user-select: none; 
}

// for testing purposes: input[type="checkbox"] { display: block; }

#turninfo,
#turninfo #next-turn {
  display: none;
}

#next-turn::before {
  color: white;
  background:#58b;
  display: inline-block;
  padding: 2px 7px;
  border-radius: 2px;
  cursor: pointer;
}

input[name=cb-player1]:checked ~ #turninfo,
input[name=cb-player1]:checked ~ #turninfo #next-turn  { 
  display: inline-block; 
}

// as soon as one tile is active, hide the intro
input[name=cb-player1]:checked ~ #intro {
  display: none;
}

// when tile 100 is reached, end the game 
.cb100:checked ~ #finish {
  display: block;
}

// only show the following 6 tile labels. TODO: reduce with SCSS?
#turn:checked ~ [name=cb-player1]:checked + label + input + label,
#turn:checked ~ [name=cb-player1]:checked + label + input + label + input + label, 
#turn:checked ~ [name=cb-player1]:checked + label + input + label + input + label + input + label,
#turn:checked ~ [name=cb-player1]:checked + label + input + label + input + label + input + label + input + label,
#turn:checked ~ [name=cb-player1]:checked + label + input + label + input + label + input + label + input + label + input + label,
#turn:checked ~ [name=cb-player1]:checked + label + input + label + input + label + input + label + input + label + input + label + input + label,

#turn:not(:checked) ~ [name=cb-player2]:checked + label + input + label,
#turn:not(:checked) ~ [name=cb-player2]:checked + label + input + label + input + label, 
#turn:not(:checked) ~ [name=cb-player2]:checked + label + input + label + input + label + input + label,
#turn:not(:checked) ~ [name=cb-player2]:checked + label + input + label + input + label + input + label + input + label,
#turn:not(:checked) ~ [name=cb-player2]:checked + label + input + label + input + label + input + label + input + label + input + label,
#turn:not(:checked) ~ [name=cb-player2]:checked + label + input + label + input + label + input + label + input + label + input + label + input + label {
  display: block;
  position: absolute;
  display: block;
  width: 50px;
  height: 50px;
  line-height:50px;
  background: #eeeeee;
  text-align: center;
  animation: changeOrder 1.2s infinite;
  -webkit-animation: changeOrder 1.2s infinite;
  top: 70px;
  left: 10px;
}

// to simulate the dice, have the animation with different delays. TODO: reduce with SCSS?
#turn:checked ~ [name=cb-player1]:checked + label + input + label { animation-delay: 0s; }
#turn:checked ~ [name=cb-player1]:checked + label + input + label + input + label { animation-delay: -0.2s; }
#turn:checked ~ [name=cb-player1]:checked + label + input + label + input + label + input + label { animation-delay: -0.4s; }
#turn:checked ~ [name=cb-player1]:checked + label + input + label + input + label + input + label + input + label { animation-delay: -0.6s; }
#turn:checked ~ [name=cb-player1]:checked + label + input + label + input + label + input + label + input + label + input + label { animation-delay: -0.8s; }
#turn:checked ~ [name=cb-player1]:checked + label + input + label + input + label + input + label + input + label + input + label + input + label { animation-delay: -1.0s; }

#turn:not(:checked) ~ [name=cb-player2]:checked + label + input + label { animation-delay: 0s; }
#turn:not(:checked) ~ [name=cb-player2]:checked + label + input + label + input + label { animation-delay: -0.2s; }
#turn:not(:checked) ~ [name=cb-player2]:checked + label + input + label + input + label + input + label { animation-delay: -0.4s; }
#turn:not(:checked) ~ [name=cb-player2]:checked + label + input + label + input + label + input + label + input + label { animation-delay: -0.6s; }
#turn:not(:checked) ~ [name=cb-player2]:checked + label + input + label + input + label + input + label + input + label + input + label { animation-delay: -0.8s; }
#turn:not(:checked) ~ [name=cb-player2]:checked + label + input + label + input + label + input + label + input + label + input + label + input + label { animation-delay: -1.0s; }

// label:active adapted from solution by Temani Afif. Ref: https://stackoverflow.com/a/51451218/3695983 
label:active {
  position:static !important; 
  margin-left: 50px !important;
  background: none !important;
  font-size: 0;
  &::before {
    content:"";
    position:absolute;
    top:0;
    right:-50px;
    left:0;
    bottom:0;
    z-index:200;
  }
}

// Board based on the one from codewars: https://www.codewars.com/kata/snakes-and-ladders-1 
#board {
  position: absolute;
  overflow: visible;
  width: 600px;
  height: 600px;
  background: url(https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/snakesandladdersboard.jpg);
  background-size: cover;
  border: 3px solid black;
  left: 70px;
  top: 70px;
  .ficha {
    position:absolute;
    width: 6px;
    height: 40px;
    overflow: visible;
    bottom: 0;
    left: -30px;
    background: red;
    transition: all 0.5s;
    transform: translate(32px, -14px);
    -webkit-transform: translate(32px, -14px);
    border: 2px solid black;
    z-index: 3;
    &::before,
    &::after {
      content:"";
      background: red;
      display: block;
      width: 20px;
      height: 20px;
      position: absolute;
      top: -4px;
      left: -7px;
      border-radius: 100%;
      border: 2px solid black;
      box-sizing: border-box;
      border-bottom: 0;
    }
    &::before {
      top: 30px;
      width: 40px;
      left: -17px;
      border-bottom:2px solid black;
      border-top: 1px solid black;      
    }
    &.player2 {
      transform: translate(18px, -12px);
      -webkit-transform: translate(18px, -12px);
      background: #00aa00;
      &::before,
      &::after {
        background: #00aa00;
      }
    }
  }
}



/***** Piece position for each numbered tile */
$positions: 0, 60, 120, 180, 240, 300, 360, 420, 480, 540, 540, 480, 420, 360, 300, 240, 180, 120, 60, 0;
@for $i from 1 through 2 {
  @for $j from 1 to 100 {
    [name=cb-player#{$i}][value="#{$j}"]:checked ~ #board > .player#{$i}  { 
      left: nth($positions, (($j - 1) % 20) + 1) * 1px; 
      bottom: nth($positions, floor(($j - 1) / 10) + 1) * 1px; 
    }
    #turn:checked ~ [name=cb-player1][value="#{$j}"]:checked ~ #turninfo #tile-position::after { 
      content: "#{$j}" !important; 
    }
    #turn:not(:checked) ~ [name=cb-player2][value="#{$j}"]:checked ~ #turninfo #tile-position::after { 
      content: "#{$j}" !important; 
    }
  }
}

/**** the following code is only valid if the tile section is uncommented above; otherwise use the image from codewars *
svg { 
  position: absolute; 
  top:0; 
  left: 0; 
  z-index:2; 
}

svg line {
  stroke: #8B4513;
  stroke-width: 3px;
  stroke-linecap: round;
}

.tile {
  width: 60px;
  height: 60px;
  background: #9ad0ac;
  display: inline-block;
  position: relative;
  z-index: 2;
  float: left;
  border-left: 1px solid rgba(0,0,0,0.2);
  border-right: 1px solid rgba(0,0,0,0.2);
  border-top: 1px solid rgba(0,0,0,1);
  border-bottom: 1px solid rgba(0,0,0,1);
  box-sizing: border-box;
  opacity: 0.75;
}

.tile10, .tile20, .tile30, .tile40, .tile50, .tile60, .tile70, .tile80, .tile90 {
  border-top: 1px solid rgba(0,0,0,0.2);
}

.tile11, .tile21, .tile31, .tile41, .tile51, .tile61, .tile71, .tile81, .tile91 {
  border-bottom: 1px solid rgba(0,0,0,0.2);
}

.tile::before {
  content: attr(data-index);
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 12px;
  font-family: "Comic Sans Ms", "Comic Sans", "Comic", serif;
}

.tile1::after, .tile100::after {
  content: "\01F449";
  font-size: 25px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -webkit-transform: translate(-50%, -50%);
}

.tile100::after {
  content: "\01F3E0";
}

.tile1, .tile15, .tile24, .tile38, .tile49, .tile55, .tile65, .tile76, .tile86, .tile94 {
  background: #f198b4;
}

.tile2, .tile16, .tile23, .tile35, .tile42, .tile56, .tile64, .tile79, .tile87, .tile93 {
  background: #fef8aa;
}

.tile3, .tile18, .tile26, .tile33, .tile41, .tile58, .tile68, .tile78, .tile81, .tile96 {
  background: #f89448;
}

.tile4, .tile11, .tile29, .tile40, .tile47, .tile51, .tile61, .tile77, .tile88, .tile99 {
  background: #c297c5;
}

.tile5, .tile19, .tile27, .tile32, .tile44, .tile59, .tile69, .tile80, .tile89, .tile97 {
  background: #68caef;
}

.tile6, .tile20, .tile28, .tile31, .tile45, .tile60, .tile70, .tile75, .tile85, .tile98 {
  background: #fef471;
}

.tile7, .tile13, .tile21, .tile36, .tile50, .tile53, .tile63, .tile74, .tile84, .tile91 {
  background: #b9e6fd;
}

.tile8, .tile12, .tile30, .tile39, .tile46, .tile52, .tile62, .tile73, .tile90, .tile100 {
  background: #e5b75f;
}

.tile9, .tile14, .tile22, .tile37, .tile48, .tile54, .tile66, .tile72, .tile83, .tile96 {
  background: #f37859;
}
/* */
              
            
!

JS

              
                // no JavaScript code!
              
            
!
999px

Console