123

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="controller">
  <div class="top-button right"></div>
  <div class="top-button left"></div>
  <div class="controller-side dpad">
    <div class="controller-inner left">
      <div class="d-pad">
        <ul class="arrows">
          <li class="up"></li>
          <li class="right"></li>
          <li class="down"></li>
          <li class="left"></li>
        </ul>
        <div class="center">
        </div>
      </div>
    </div>
  </div>
  <div class="controller-center">
    <div class="button select"></div>
    <div class="button start"></div>
  </div>
  <div class="controller-side buttons">
    <div class="controller-inner right">
      <ul class="underlay">
      <div class="underlay-span xy"></div>
      <div class="underlay-span ab"></div>
        <li class="a"></li>
        <li class="b"></li>
        <li class="x"></li>
        <li class="y"></li>
      </ul>
      <ul class="overlay">
        <li class="a"></li>
        <li class="b"></li>
        <li class="x"></li>
        <li class="y"></li>
      </ul>
    </div>
  </div>
</div>

<aside>For a break-down of how I built this controller, check out the <a href="https://codepen.io/tstandiford/post/snes-controller" target="blank">related blog post</a>, written here on CodePen.</aside>
            
          
!
            
              /*resets those pesky list items*/
ul,li,ol{
  padding:0px;
  margin:0px;
  list-style-type:none;
}

body{
background:#1e1300;
}

$controller-width:500px;

/* calculations */

$controller-side-diameter:$controller-width * .4;
$controller-side-radius:$controller-side-diameter/2;
$controller-center-height:$controller-side-diameter - $controller-side-radius/6;
$controller-center-width: $controller-width - $controller-side-diameter;
$controller-side-offset: $controller-side-diameter *.1;
$button-diameter: 27px;
/* colors */

$controller-body: #D1D1D1;
$controller-inner: #ACA9AC;
$d-pad: #717574;
$light-button: #B9B7E4;
$dark-button: #5D46AE;

/* mixins */

@mixin arrow($rotate, $left,$top) {
  transform:translate(-50%,-50%) rotate($rotate);
  left:$left;
  top:$top;
}

@mixin center($position){
  transform:translate(-50%,-50%);
  top:50%;
  left:50%;
  position:$position;
}

@mixin button($left, $top){
  left:$left;
  top:$top;
}

@mixin button-text($right,$top){
  position:absolute;
  right:$right;
  top:$top;
  font-family:sans-serif;
  color:$controller-body;
  font-style:italic;
  font-size:85%;
}

aside{
  display:none;
}

@media screen and (min-width:800px){
  aside{
    width:900px;
    max-width:100%;
    text-align:center;
    position:absolute;
    bottom:20px;
    left:50%;
    transform:translateX(-50%);
    color:$controller-body;
    font-family:sans-serif;
    font-size:110%;
    display:initial;
  }

  aside>a{
    color:$light-button;
    text-decoration:none;
  }
  
  aside>a:hover{
    color:$dark-button;
  }
}
/*---BODY---*/

.controller{
  width:$controller-width;
 @include center(fixed);
}

.controller-side:before{
  content:" ";
  display:block;
  width:$controller-side-diameter + 5px;
  height:$controller-side-diameter - 2px;
  position:absolute;
  top:1px;
  border-radius:100%;
}

.controller-side.dpad:before{
  left:3px;
  top:1px;
}

.controller-side.buttons:before{
  right:3px;
  top:1px;
}

.controller-side{
  width:$controller-side-diameter;
  height:$controller-side-diameter;
  border-radius:100%;
  float:left;
}

.controller-side.dpad{
  background:linear-gradient(180deg, #ddd 0%,#666 100%);
}

.controller-side.buttons{
  background: linear-gradient(225deg, #ddd 0%,#eee 25%,#666 75%);
}


.buttons{
  right:0%;
}

.controller-center{
  width:$controller-center-width;
  height:$controller-center-height;
  margin-left:$controller-side-radius * -1;
  margin-right:$controller-side-radius * -1;
}

.controller-center:after{
  content:" ";
  position:absolute;
  width:$controller-center-width;
  height:5px;
  background:linear-gradient(#666, #eee 10%,transparent 100%);
}

.controller-center:before{
  content:" ";
  position:absolute;
  height:2px;
  width:190px;
  background:linear-gradient(transparent,#666);
  bottom:17px;
  left:162px;
}

.controller-side:before, .controller-center{
  background:$controller-body;
  float:left;
}

/*---RIGHT SIDE---*/

.controller-inner.right{
  width:$controller-side-diameter - $controller-side-offset;
  height:$controller-side-diameter - $controller-side-offset;
  background:$controller-inner;
  top:$controller-side-offset/2;
  right:$controller-side-offset/2;
  border-radius:100%;
  border:1px solid #aaa;
  position:absolute;
}

.buttons ul{
  position:absolute;
  right:$controller-side-radius - 10px;
  top:$controller-side-radius - 10px;
  transform:translate(50%,-50%);
  width:$controller-side-diameter - $controller-side-offset - 50px;
  height:$controller-side-diameter - $controller-side-offset - 50px;
}

.buttons li{
  border:1px solid #333;
  display:block;
  height:$button-diameter;
  width:$button-diameter;
  border-radius:100%;
  position:absolute;
  transform:translate(-50%,-50%);
  left:50%;
  top:50%;
}

.buttons .underlay li{
  height:$button-diameter + 8px;
  width:$button-diameter + 8px;
  border:none;
  background:$controller-body;
  
}

.buttons .y,
.buttons .x{
  background:radial-gradient(farthest-corner at 10% 90%,#e1e1ef 0%, #cbcbed 30%,$light-button 50%, $light-button 70%,#e1e1ef 95%);
}

.buttons .a,
.buttons .b{
  background:radial-gradient(farthest-corner at 75% 0%, #dddaed 0%, #9f90dd 20%, $dark-button 50%, $dark-button 70%, #43337c 90%);
}

.buttons .a{
  @include button(80%,50%);
}

.buttons .overlay .a:after{
  content:"A";
}

.buttons .b{
  @include button(50%,75%);
}

.buttons .overlay .b:after{
  content:"B";
}

.buttons .x{
  @include button(50%,25%);
}

.buttons .overlay .x:after{
  content:"X";
}

.buttons .y{
  @include button(20%, 50%);
}

.buttons .overlay .y:after{
  content:"Y";
}

.buttons .y:after,
.buttons .b:after{
  @include button-text(115%, 90%);
}

.buttons .a:after,
.buttons .x:after{
  @include button-text(-60%, -35%);
}

.underlay-span{
  width:52px;
  height:$button-diameter + 8px;
  background:$controller-body;
  position:absolute;
}

.underlay-span.ab{
  right:16%;
  top:50%;
  transform:rotate(-40deg);
}

.underlay-span.xy{
  left:14%;
  top:25%;
  transform:rotate(-40deg);
}

/*---LEFT SIDE----*/

.controller-inner.left{
  width:$controller-side-diameter / 2;
  height:$controller-side-diameter / 2;
  background: linear-gradient(235deg, #aaa, #eee);
  border-radius:100%;
  margin-left:$controller-side-diameter / 4 - 3px;
  margin-top:$controller-side-diameter / 4 - 3px;
  position:absolute;
}

.controller-inner.left:after{
  content:" ";
  display:block;
  width:$controller-side-diameter / 2 - 3px;
  height:$controller-side-diameter / 2 - 3px;
  background:#333;
  margin-top:1px;
  margin-left:1px;
  border-radius:100%;
  background:$controller-body;
}

.d-pad{
  width:$controller-side-diameter / 2 - 40px;
  height:$controller-side-diameter / 2 - 40px;
  float:left;
  margin-left:$controller-side-diameter / 4 - 30px;
  margin-top:$controller-side-diameter / 4 - 30px;
}

.d-pad:after,
.d-pad:before{
  content:" ";
  display:block;
  height:$controller-side-diameter / 2 - 40px;
  width:15px;
  background:$d-pad;
  left:50%;
  border-radius:3px;
  border:2px solid #444;
  border-bottom:1px;
  transform:translateX(-50%);
  position:absolute;
}

.d-pad:before{
  transform:translateX(-50%) rotate(90deg);
}

.arrows{
  position:absolute;
  width:$controller-side-diameter / 2 - 40px;
  height:$controller-side-diameter / 2 - 40px;
  padding:0;
  margin:0;
}

.arrows li{
  list-style-type:none;
  margin:0;
  width:2px;
  height:0px;
  display:block;
  background:transparent;
  position:absolute;
  z-index:1;
  border-left:5px solid transparent;
  border-right:5px solid transparent;
  border-bottom:10px solid #555;
  border-radius:2px;
}

.arrows .right{
  @include arrow(90deg, 85%, 50%);
}

.arrows .left{
  @include arrow(270deg, 15%, 50%);
}

.arrows .up{
  @include arrow(0deg, 50%, 15%);
}

.arrows .down{
  @include arrow(180deg, 50%, 85%);
}
.center{
  width:19px;
  height:19px;
  @include center(absolute);
  background:$d-pad;
  z-index:1;
}

.center:after{
  @include center(absolute);
  width:15px;
  height:15px;
  background:radial-gradient(farthest-corner at 30% 70%, #888, #545454 70%);
  content:" ";
  border-radius:100%;
}

/*---CENTER------*/

.controller-center .button{
  width:39px;
  height:16px;
  display:block;
  background:linear-gradient(280deg, #555, #555 10%,#999 25%, #999 75%,#eee 90%);
  border-radius:10px;
  position:absolute;
}

.controller-center .button:before{
  width:35px;
  height:12px;
  display:block;
  background:linear-gradient(#444,$d-pad,#444);
  border-radius:10px;
  margin-top:2px;
  margin-left:2px;
  content:" ";
}

.button.select{
  @include arrow(-40deg, 42%, 60%);
}

.controller-center .button:after{
  font-family:sans-serif;
  font-style:italic;
  font-size:60%;
  transform:rotate(40deg);
  display:block;
  margin-top:15px;
  margin-left:-15px;
  color:$controller-inner;
}

.button.select:after{
  content:"SELECT";
}

.button.start:after{
  content:"START";
}

.button.start{
  @include arrow(-40deg, 52%, 60%);
}

/*---R AND L BUTTONS---*/

.top-button{
  width:100px;
  height:100px;
  display:block;
  position:absolute;
  top:-5px;
  z-index:-1;
}

.top-button.right:before,
.top-button.left:before{
  content:" ";
  width:60%;
  height:100%;
  display:block;
  position:absolute;
  border-radius:3px;
}

.top-button.right:after,
.top-button.left:after{
  content:" ";
  display:block;
  height:$controller-side-diameter + 5px;
  width:$controller-side-diameter + 5px;
  position:absolute;
}

.top-button.right:before{
  right:0;
  background:linear-gradient(90deg,$controller-body 0%, $controller-body 90%,#666 100%);
}

.top-button.right{
  left:50px;
}

.top-button.right:after{
  background:linear-gradient(235deg,$controller-body 0%, $controller-body 47%,#666 50%,#666 50%,transparent 50%);
  border-radius:100%;
  left:$controller-side-radius * -1 + 45px;
}

.top-button.left:before{
  left:0;
  background:linear-gradient(90deg, #666 0%, $controller-body 10%,$controller-body 100%);
}

.top-button.left{
  right:50px;
}

.top-button.left:after{
  background:linear-gradient(-235deg,$controller-body 0%, $controller-body 47%,#666 50%,#666 50%,transparent 50%);
  border-radius:100%;
  right:$controller-side-radius * -1 + 47px;
}

            
          
!
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.

Console