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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              <button class="actual">Not Correct</button>
<button class="expected">Expected</button>
<button class="via-itp">Independent Transforms</button>
<button class="via-variables">CSS Variables</button>
            
          
!
            
              
.actual, .expected {
  transform: translateY(-150%);
}

/* will (perhaps unintentionally) override the original translate */
.actual:hover {
  transform: scale(.8);
}
/* will (perhaps unintentionally) override the original translate and scale */
.actual:active {
  transform: rotate(-5deg);
}


/* explicitly restates each previous transform function and works as intended */
.expected:hover {
  transform: translateY(-150%) scale(.8);
}
.expected:active {
  transform: translateY(-150%) scale(1) rotate(-5deg);
}
.expected:hover:active {
  transform: translateY(-150%) scale(.8) rotate(-5deg);
}

/* will have similar experience to expected, but organized differently */
.via-variables {
  --y: -150%;
  --scale: 1;
  --rotation: 0deg;
  
  transform: translateY(var(--y)) scale(var(--scale)) rotate(var(--rotation));
}
.via-variables:hover {
  --scale: .8;
}
.via-variables:active {
  --rotation: -5deg;
}

.via-itp {
  
  transition: 
    translate 125ms ease-out,
    scale 125ms ease-out,
    rotate 125ms ease-out;
  translate: 0 -150%;
}
.via-itp:hover {
  scale: .8 .8;
}
.via-itp:active {
  rotate: -5deg;
}




button {
  border: 2px solid hsl(140, 80%, 70%);
  border-radius: 5vmin;
  appearance: none;
  height: 3rem;
  padding: 0 1rem;
  background: hsl(140, 80%, 70%);
  margin: 1rem;
  
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1rem;
  
  transition: transform 125ms ease-out;
}

body {
  height: 100vh;
  background: linear-gradient(to bottom,
    hsl(220, 12%, 12%) calc(50vh - 1px),
    hsl(220, 12%, 32%) calc(50vh - 1px),
    hsl(220, 12%, 32%) calc(50vh + 1px),
    hsl(220, 12%, 12%) calc(50vh + 1px));
  display: flex;
  justify-content: center;
  align-items: center;
}

button:focus {
  outline: 0; /* just for demo clarity for hover v active */
}



/*
.via-variables,
.via-itp {
  background: transparent;
  color: transparent;
}
.active.via-variables,
.active.via-itp {
  background: hsl(140, 80%, 70%);
  color: black;
}
*/
            
          
!
            
              document.querySelector('.via-itp').addEventListener('click', add);
document.querySelector('.via-variables').addEventListener('click', add);

function add(e) {
  e.currentTarget.classList.add('active')
}
            
          
!
999px
Loading ..................

Console