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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              <header>
  <h1>Composi Coin Toss</h1>
</header>
<section></section>
            
          
!

CSS

            
              /* Bootstrap 4 Reset */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-family: sans-serif;
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  -ms-overflow-style: scrollbar;
  -webkit-tap-highlight-color: transparent;
  font-size: 62.5%;
}

@-ms-viewport {
  width: device-width;
}

article, aside, dialog, figcaption, figure, footer, header, hgroup, main, nav, section {
  display: block;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  font-size: 1.4rem;
  font-weight: normal;
  line-height: 1.5;
  color: #212529;
  text-align: left;
  background-color: #fff;
}

[tabindex="-1"]:focus {
  outline: none !important;
}

hr {
  box-sizing: content-box;
  height: 0;
  overflow: visible;
}

h1, h2, h3, h4, h5, h6 {
  margin-top: 0;
  margin-bottom: .5rem;
}

p {
  margin-top: 0;
  margin-bottom: 1rem;
}

abbr[title],
abbr[data-original-title] {
  text-decoration: underline;
  -webkit-text-decoration: underline dotted;
          text-decoration: underline dotted;
  cursor: help;
  border-bottom: 0;
}

address {
  margin-bottom: 1rem;
  font-style: normal;
  line-height: inherit;
}

ol,
ul,
dl {
  margin-top: 0;
  margin-bottom: 1rem;
}

ol ol,
ul ul,
ol ul,
ul ol {
  margin-bottom: 0;
}

dt {
  font-weight: bold;
}

dd {
  margin-bottom: .5rem;
  margin-left: 0;
}

blockquote {
  margin: 0 0 1rem;
}

dfn {
  font-style: italic;
}

b,
strong {
  font-weight: bolder;
}

small {
  font-size: 80%;
}

sub,
sup {
  position: relative;
  font-size: 75%;
  line-height: 0;
  vertical-align: baseline;
}

sub {
  bottom: -.25em;
}

sup {
  top: -.5em;
}

a {
  color: #007bff;
  text-decoration: none;
  background-color: transparent;
  -webkit-text-decoration-skip: objects;
}

a:hover {
  color: #0056b3;
  text-decoration: underline;
}

a:not([href]):not([tabindex]) {
  color: inherit;
  text-decoration: none;
}

a:not([href]):not([tabindex]):focus, a:not([href]):not([tabindex]):hover {
  color: inherit;
  text-decoration: none;
}

a:not([href]):not([tabindex]):focus {
  outline: 0;
}

pre,
code,
kbd,
samp {
  font-family: monospace, monospace;
  font-size: 1em;
}

pre {
  margin-top: 0;
  margin-bottom: 1rem;
  overflow: auto;
  -ms-overflow-style: scrollbar;
}

figure {
  margin: 0 0 1rem;
}

img {
  vertical-align: middle;
  border-style: none;
}

svg:not(:root) {
  overflow: hidden;
}

a,
area,
button,
[role="button"],
input:not([type=range]),
label,
select,
summary,
textarea {
  -ms-touch-action: manipulation;
  touch-action: manipulation;
}

table {
  border-collapse: collapse;
}

caption {
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
  color: #868e96;
  text-align: left;
  caption-side: bottom;
}

th {
  text-align: inherit;
}

label {
  display: inline-block;
  margin-bottom: .5rem;
}

button {
  border-radius: 0;
  border: solid 1px #ccc;
  background-color: #ccc;
  overflow: hidden;
}

button:focus {
  outline: 1px dotted;
  outline: 5px auto -webkit-focus-ring-color;
}

input,
button,
select,
optgroup,
textarea {
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

button,
input {
  overflow: visible;
}

button,
select {
  text-transform: none;
}

button,
html [type="button"],
[type="reset"],
[type="submit"] {
  -webkit-appearance: button;
}

button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
  padding: 0;
  border-style: none;
}

input[type="radio"],
input[type="checkbox"] {
  box-sizing: border-box;
  padding: 0;
}

input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"] {
  -webkit-appearance: listbox;
}

textarea {
  overflow: auto;
  resize: vertical;
}

fieldset {
  min-width: 0;
  padding: 0;
  margin: 0;
  border: 0;
}

legend {
  display: block;
  width: 100%;
  max-width: 100%;
  padding: 0;
  margin-bottom: .5rem;
  font-size: 1.5rem;
  line-height: inherit;
  color: inherit;
  white-space: normal;
}

progress {
  vertical-align: baseline;
}

[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
  height: auto;
}

[type="search"] {
  outline-offset: -2px;
  -webkit-appearance: none;
}

[type="search"]::-webkit-search-cancel-button,
[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
}

::-webkit-file-upload-button {
  font: inherit;
  -webkit-appearance: button;
}

output {
  display: inline-block;
}

summary {
  display: list-item;
}

template {
  display: none;
}

[hidden] {
  display: none !important;
}

html, body, h1, h2, h3, h4, h5, h6, p, ol, ul, li, dl,
dt, dd, blockquote, address, table {
  margin: 0;
  padding: 0;
}

* {
  font-weight: 100;
}


/****************/
/* Local Styles */
/****************/

html, body {
  height: 100%;
  -webkit-font-smoothing: antialiased;
}
header {
  background-color: #458fd9;
  box-shadow: 0 6px 6px rgba(69, 143, 217, 0.75);
  padding: 20px;
  position: relative;
  z-index: 1000;
}
header h1 {
  color: #fff;
  margin: 0;
  font-size: 2.5rem;
  font-weight: 300;
}
body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

section {
  padding: 14rem 2rem 2rem;
  display: flex;
  flex-direction: column;
  /* justify-content: center; */
  align-items: center;
  flex: 1;
  background-color: #87b9d9;
  background-image: 
    repeating-linear-gradient(45deg, rgba(255,255,255,0.5) 0, rgba(255,255,255,0.5) 20px, transparent 20px, transparent 32px, rgba(255,255,255,0.5) 32px, rgba(255,255,255,0.5) 44px, transparent 44px, transparent 56px, rgba(255,255,255,0.5) 56px, rgba(255,255,255,0.5) 68px, transparent 68px, transparent 80px, rgba(255,255,255,0.5) 0),
    repeating-linear-gradient(-45deg, rgba(255,255,255,0.5) 0, rgba(255,255,255,0.5) 20px, transparent 20px, transparent 32px, rgba(255,255,255,0.5) 32px, rgba(255,255,255,0.5) 44px, transparent 44px, transparent 56px, rgba(255,255,255,0.5) 56px, rgba(255,255,255,0.5) 68px, transparent 68px, transparent 80px, rgba(255,255,255,0.5) 0);
}
#coin-container {
  width: 200px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-top: -40px;
}
#coin-container button {
  border: solid 3px goldenrod;
  background-color: gold;
  border-radius: 6px;
  transition: all .25s ease-out;
  cursor: pointer;
  font-size: 2rem;
  font-weight: 500;
  box-shadow: 0 2px 2px rgba(0,0,0,.5)
}
#coin-container button:hover {
  border-color: red;
  background-color: darkorange;
  color: #fff;
  box-shadow: 0 4px 6px rgba(0,0,0,.5)
}
#coin-container button:active {
  box-shadow: none;
}
#coin {
	width: 190px;
	height: 190px;
	border-radius: 150px;
	-webkit-transition: 0.5s;
	-webkit-transform-style: preserve-3d;
  position: relative;
	box-shadow: 0 4px 8px rgba(0, 0, 0, .8);
  margin-bottom: 30px;
}
#coin #heads {
	width: 190px;
	height: 190px;
  background: transparent url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/77047/USDollar-Head.png) no-repeat center;
  background-size: 102%;
  -webkit-backface-visibility: hidden;
  position: absolute;
	border-radius: 150px;
}
#coin #tails {
	width: 190px;
	height: 190px;
  background: transparent url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/77047/USDollar-Tail.png) no-repeat center;
  background-size: 101%;
	-webkit-transform: rotateX(180deg);
  -webkit-backface-visibility: hidden;
  position: absolute;
	border-radius: 150px;
}
#coin.flipped {
  transform: rotateX(180deg);
}

.animate-coin {
  animation: flip-heads 2s ease-out;
  animation-fill-mode: forwards;
}
.animate-coin2 {
  animation: flip-tails 2s ease-out;
  animation-fill-mode: forwards;
}
@keyframes flip-heads {
  0% {
    transform: scale3d(1,1,1) rotateX(0deg);
    box-shadow: 0 4px 8px rgba(0,0,0,.8);
  }
  50% {
    transform: scale3d(2,2,2) rotateX(720deg);
    box-shadow: 0 0 40px rgba(0,0,0,.8);
  }
  100% {
    transform: scale3d(1,1,1) rotateX(1440deg);
    box-shadow: 0 4px 8px rgba(0,0,0,.8);
  }
}
@keyframes flip-tails {
  0% {
    transform: scale3d(1,1,1) rotateX(0deg);
    box-shadow: 0 -4px 8px rgba(0,0,0,.8);
  }
  50% {
    transform: scale3d(2,2,2) rotateX(720deg);
    box-shadow: 0 0 40px rgba(0,0,0,.8);
  }
  100% {
    transform: scale3d(1,1,1) rotateX(1620deg);
    box-shadow: 0 -4px 8px rgba(0,0,0,.8);
  }
}
            
          
!

JS

            
              /** @jsx h */
const { h, render, Component } = composi

function coinToss() {
  return Math.floor(Math.random() *2)
}

class Coin extends Component {
  constructor(props) {
    super(props)
    this.container = 'section'
    this.state = {
      flipped: false,
      flips: [0,0,0]
    }
  }

  render(toss) {
    return (
      <div id="coin-container">
        <div id="coin">
          <div id="heads"></div>
          <div id="tails"></div>
        </div>
        <button>Flip Coin</button>
      </div>
    )
  }
  flipCoin() {
    // Increase the randomness of the toss:
    let toss = Math.floor(Math.random() * 2)
    let toss2 = Math.floor(Math.random() * 2)
    if (toss == toss2) toss = Math.floor(Math.random() * 2)

    const coin = document.querySelector('#coin')
    // Heads:
    if (toss === 0) {
      coin.removeAttribute('class')
      setTimeout(() => {
        coin.classList.add('animate-coin')
      }, 200)

    // Tails:
    } else {
      coin.className = 'flipped'
      setTimeout(() => {
        coin.classList.add('animate-coin2')
      }, 200)
    }
  }
  handleEvent(e) {
    e.target.nodeName === 'BUTTON' && this.flipCoin()
  }
  componentDidMount() {
    this.element.addEventListener('click', this)
  }
}

const coin = new Coin()
            
          
!
999px

Console