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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div id="card" class="card">
  <div class="image">
    <span class="alert">New Style</span>
  </div>
  <div class="des">
    <span class="subtitle">Natural Services</span>
    <h1>Twist Out<span>$60</span></h1>
    <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultrices bibendum tellus vel ullamcorper. Phasellus vel lectus et ipsum porta venenatis. </p>
  </div>
  <hr>
   <a id="book" class="adding">Add to Order</a>
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Roboto:400,700');

//////////// Universal 

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  border: none;
}

html, body {
  height: 100%;
}

//////////// Centering

body {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: linear-gradient(PaleVioletRed , LightPink);
  font-family: 'Roboto', sans-serif;
  font-size: 15px;
}

//////////// Card

%card { // placeholder = %
  width: 350px;
  box-shadow: none;
  background-color: #fff;
  -webkit-font-smoothing: antialiased;
  transition: 0.3s ease-out all;
// adding transition on both classes will work with JS
  &:hover {
    -webkit-box-shadow: -1px -1px 16px -4px rgba(0,0,0,0.44);
    -moz-box-shadow: -1px -1px 16px -4px rgba(0,0,0,0.44);
    box-shadow: -1px -1px 16px -4px rgba(0,0,0,0.44);
    transition: 0.3s ease-out all;
  }
}

  .card {
    @extend %card;
    transition: 0.3s ease-out all;
  }

  .card2 {
    @extend %card;
    opacity: 0.8;
    transition: 0.3s ease-out all;
  }

  //////////// Image + tag

  .image {
    display: flex;
    width: 100%;
    background-image: url("https://images.unsplash.com/photo-1519699047748-de8e457a634e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2000&q=80");
    background-size: cover;
    background-position-y: center;
    height: 200px; 
    .alert {
      align-self: end;
      margin: 10px;
      background-color: PaleVioletRed; 
      color: white;
      padding: 6px 8px; 
      font-size: 10px;
      border-radius: 10px;
      text-transform: uppercase;
    }
  }

//////////// Text

  .des {
    padding: 12px;
    .subtitle {
      color: DarkGray;
    }
    h1 {
      margin: 5px 0;
      span {
        font-weight: normal;
        margin-left: 10px;
        color: SeaGreen;
      }
    }
    p {
      line-height: 22px;
    }
  }

  hr {
    border: 1px solid Gainsboro;
    opacity: 0.3;
  }

//////////// Button

  %btn { 
    display: inline-block;
    width: 100%;
    padding: 12px 0 12px 12px;
    text-align: left;
    text-transform: uppercase;
    font-weight: bold;
    font-size: 12px;
    }

  .adding {
    @extend %btn; // everything after this will add onto extend
    background-color: white;
    color: grey;
      &:hover {
        background-color: LavenderBlush;
        color: black;
        cursor: pointer;
      }
    }
    .ordered {
      @extend %btn;
      background-color: PaleVioletRed;
      color: white;
      cursor: pointer;
    }
              
            
!

JS

              
                let btn = document.getElementById('book');
let card = document.getElementById('card');

///////// Clicking

btn.onclick = function() {
  // button in default state 
  if (btn.className == 'adding') {
    //button clicked
    card.className = 'card2';
    btn.className = 'ordered';
    btn.innerHTML = 'Added';
  } else { // button clicked again aka default state
    card.className = 'card';
    btn.className = 'adding';
    btn.innerHTML = 'Add to Order';
  }
} 

///////// Hovering for removing

btn.onmouseover = function() {
  // makes hover say removed
   if (btn.className == 'ordered') {
    btn.innerHTML = 'Remove';
  } 
}

btn.onmouseout = function() {
  // stop hovering
   if (btn.className == 'ordered') {
    btn.innerHTML = 'Added';
  } 
} 
              
            
!
999px

Console