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="magic8ball">
  <div id="window">
    <div id="message">
      <span>
      </span>
    </div>
  </div>
</div>
<button type="button" onclick="shake()">Shake</button>
              
            
!

CSS

              
                *{
  box-sizing: border-box;
}

body{
  height: 100vh;
  background-image: url(https://images.unsplash.com/photo-1526721940322-10fb6e3ae94a?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ);
  background-size: cover;
}

#magic8ball{
  width: 500px;
  height: 500px;
  background-color: black;
  position: absolute;
  left: calc(50% - 250px);
  top: calc(50% - 250px);
  border-radius: 250px;
}

#window{
  width: 200px;
  height: 200px;
  background-color: darkblue;
  position: absolute;
  left: calc(50% - 100px);
  top: calc(50% - 100px);
  border-radius: 100px;  
}

#message span{
  width: 150px;
  height: 150px;
  opacity: 0;
  background-color: white;
  position: absolute;
  left: calc(50% - 75px);
  top: calc(50% - 85px);
  clip-path: polygon(50% 0%, 100% 90%, 0% 90%);
  shape-outside: polygon(0% 0%, 50% 0%, 0% 90%);
  display: flex;
  text-align: center;
  align-items: center;
  justify-content: center;
  padding: 85px 45px 45px 45px;
  transition: opacity 1s ease-in-out;
}


              
            
!

JS

              
                const answers = `It is certain
It is decidedly so
Without a doubt
Yes - definitely
You may rely on it
As I see it, yes
Most likely
Outlook good
Yes
Signs point to yes
Reply hazy, try again
Ask again later
Better not to tell you now
Cannot predict now
Concentrate and ask again
Don't count on it
My reply is no
Sources say no
Outlook not so good
Very doubtful`.split("\n");

const choice = () => answers[Math.floor(Math.random() * answers.length)];

const message = document.querySelector("span");

const show = () => {
  message.innerText = choice(answers);
  message.style.opacity = 1;
  document.body.removeEventListener("transitionend", show, true);
};

function shake() {
  document.body.addEventListener("transitionend", show, true);
  message.style.opacity = 0;
}

window.addEventListener('load', show, true);
              
            
!
999px

Console