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

              
                <div id="app"></div>
              
            
!

CSS

              
                :root {
  --font-sans: 'Josefin Sans', sans-serif;
  --font-serif: 'Tinos', serif;
  --base-gutter: 28px;
  --product-inner-padding: 5vw;
  --color-primary: #000000;
  --color-secondary: #23CE6B;
  --color-tertiary: #FFFFFF;
}

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

html,
body {
  min-height: 100vh;
}

main {
  margin: 0 auto;
  max-width: 1080px;
  padding: var(--base-gutter) 0;
  width: 95%;
}

@media only screen and (max-width: 40em) {
  main {
    display: block !important;
  }
}

header {
  font-family: var(--font-sans);
  position: sticky;
  top: 0;
  left: 0;
  width: 100%;
  background: var(--color-primary);
  padding: 20px 4vw;
  color: var(--color-tertiary);
  z-index: 100;
}

header h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1;
  margin: 0 auto;
  max-width: 1080px;
}

hr {
  margin: var(--base-gutter) auto;
  width: 100%;
  height: 10px;
  border: 0;
  background: var(--color-primary);
}

p {
  line-height: 1.7;
  font-size: 14px;
  opacity: 0.7;
  text-align: left;
}

/* Helpers */
.df { display: flex }
.ait { align-items: flex-start }

.ff-sans { font-family: var(--font-sans) }
.ff-serif { font-family: var(--font-serif) }

/* Image Gallery */
.image-gallery {
  width: 60%;
  padding: 2vh 0;
}

@media only screen and (max-width: 70em) {
  .image-gallery { width: 100%; }
}

.image-gallery-main {
  width: 100%;   
  height: auto;
  display: block;
}

/* Product */
.product {
  width: 50%;
  min-height: 100vh;
  text-align: center;
  padding: 0 var(--product-inner-padding);
  display: flex;
  flex-direction: column;
}

@media only screen and (max-width: 40em) {
  .product { width: 100%; }
}

.product-title {
  max-width: 85%;
  margin: 0 auto;
  margin-bottom: var(--base-gutter);
  font-size: 24px;
  padding-top: 2.5vh;
}

.product-price {
  margin-bottom: var(--base-gutter);
  font-weight: 400;
  font-size: 22px;
}

/* Thumbnails */
.thumbnails {
  display: flex;
  width: 240px;
}

.thumbnails-item {
  list-style: none;
  margin-top: var(--base-gutter);
  margin-right: 15px;
  opacity: 0.5;
  transition: opacity 350ms linear;
}

.thumbnails-item-active {
  opacity: 1;
}


.thumbnails-item:last-of-type { margin-right: 0; }

.thumbnails-item img {
  width: 100%;
  display: block;
  height: auto;
}


/* Button */
.button {
  box-sizing: border-box;
  font-family: var(--font-sans);
  font-size: 22px;
  background: var(--color-primary);
  color: var(--color-tertiary);
  border: 0;
  -webikit-appearance: none;
  padding: 20px 30px;
  width: 100%;
  display: block;
  transition: background 250ms ease-in-out;
}

.button:hover {
  background: var(--color-secondary);
  cursor: pointer;
}

.button:disabled {
  background: var(--color-secondary);
  cursor: not-allowed;
}

.count {
  position: fixed;
  top: 19px;
  right: 20px;
  z-index: 100;
  background: white;
  padding: 3px 10px 0 10px;
  border-radius: 100px;
  font-weight: 500;
  min-height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pulse {
  animation: pulse 350ms ease-in-out;
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  
  50% {
    transform: scale(1.5);
  }
  
  100% {
    transform: scale(1);
  }
}

.offer {
  margin-top: var(--base-gutter);
  color: var(--color-secondary);
  border: 2px solid var(--color-secondary);
  padding: 8px 10px;
}
              
            
!

JS

              
                function Header() {
  return (
    <header>
      <h1>Shop.</h1>
    </header>
  );
}

function ImageGallery(props) {
  const [image, setImage] = React.useState(0);

  return (
    <div className="image-gallery">
      <img className="image-gallery-main" src={props.images[image].src} />

      <ul class="thumbnails">
        {props.images.map((item, index) => {
          return (
            <li key={image.id} className={`thumbnails-item ${image == item.id && `thumbnails-item-active`}`}>
              <img onClick={() => setImage(item.id) } src={item.src} />
            </li>
          );
        })}
      </ul>
    </div>
  );
}

function Product(props) {
  
  const [count, setCount] = React.useState(0);
  
  
  const addToBasket = (e) => {
    const button = e.target;
    const counter = document.querySelector('.count');
    
    setCount(count + 1);
    counter.classList.add('pulse');
    
    button.innerText = 'Added to basket!'
    button.setAttribute('disabled', true);
    
    setTimeout((e) => {
      button.removeAttribute('disabled');
      button.innerText = 'Add to basket'
      counter.classList.remove('pulse');
    }, 1000)
  }
  
  return (
    <div className="product">
      <div className="product-info">
        <h2 className="product-title ff-sans">{props.product.name}</h2>
        <h4 className="product-price ff-sans">{props.product.price}</h4>
        <button onClick={addToBasket} className="button">Add to basket</button>
      </div>
      
      <span className="offer ff-sans">20% off with voucher: FU3L3D</span>
      
      <div className="product-info">
        <hr />  
        <p className="product-description ff-serif">{props.product.description}</p>
        <hr />
      </div>
      
      <span className="count ff-sans">{count}</span>
      
    </div>
  )
}

class App extends React.Component {
  render() {
    const galleryImages = [
      {
        id: 0,
        src: `https://s3-us-west-2.amazonaws.com/s.cdpn.io/3219/polar-multi-colour-t-shirt-black-multi-1.jpg`
      },
      {
        id: 1,
        src: `https://s3-us-west-2.amazonaws.com/s.cdpn.io/3219/polar-multi-colour-t-shirt-black-multi-2.jpg`
      },
      {
        id: 2,
        src: `https://s3-us-west-2.amazonaws.com/s.cdpn.io/3219/polar-multi-colour-t-shirt-black-multi-3.jpg`
      },
    ];
    
    const productInfo = {
      name: `Polar Multi Colour T-Shirt Size L`,
      price: `$45.00`,
      description: `Adorned with multi coloured stripes, this Multi Colour T-Shirt from Polar is made from 210gsm 100% cotton and includes a black colour block curved neckline and subtle logo embroidery on the chest. The body has been cut to a regular fit whilst the short sleeves allow for varying styling possibilities. Flowing vertically down the body and at an angle on the sleeves, the stripes have been roll printed and vary between tones of green, white and yellow, alongside a decorative embroidered logo which has been stitched to sit against the design in a shade of dark green. The body has a straight finish which allows the fabric to be easily tucked into trousers or shorts.`
    }
    
    return (
      <div>
        <Header />
        
        <main className="df ait">
          <ImageGallery images={galleryImages} />
          <Product product={productInfo} />
        </main>
        
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById("app"));

              
            
!
999px

Console