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 class="slider"></div>

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Racing+Sans+One|Roboto');

@function randomVal() {
  @return random(256) - 1;
}

@mixin randomRGBA() {
  background-color: rgba(randomVal(), randomVal(), randomVal(), .25);
}

body {
 // overflow: hidden;
  height: 100%;
}

.slide {
  display: flex;
  flex-wrap: nowrap;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  opacity: 0;
  z-index: 1;
  transition: opacity 1s;
 
  @media (min-width: 768px) {
    flex-direction: row;
    flex-wrap: wrap;
  }
  
  
  &.visible {
    opacity: 1;
    z-index: 2;
  }
}

$slides: 6;
@while $slides>=0 {
  .slide[data-slide="slide-#{$slides}"] {
    @include randomRGBA();
  }
  $slides: $slides - 1;
}

.slide-image {
  flex: 0 1 50%;

  img {
    width: 100%;
    height: 75vh;
    object-fit: cover;
  
    @media (min-width: 768px) {
      height: 100vh;
    }
  }
}

.slide-caption {
  flex: 0 1 50%;
  display: flex;
  background-color: inherit;
}

.slide-caption-content {
  margin: auto;
  width: 100%;
  font-family: 'Roboto', sans-serif;
  line-height: 1;
  font-size: calc(14px + (19 - 14) * (100vw - 426px) / (768 - 426));
  background-color: inherit;
  padding: 0 .5em;
  
  @media(min-width: 768px) {
    width: 90%;
    line-height: 1.5;
    font-size: 1.25rem;
  }
  
  p {
    padding: 0 1em;
  }
}

.title-bg {
  background-color: inherit;
  padding: 0 .75em;

  h1 {
    font-family: 'Racing Sans One', serif;
    font-size: calc(28px + (44 - 28) * (100vw - 426px) / (768 - 426));
    font-weight: 700;
    line-height: 1.2;
    padding: 5px 0;
    
    @media(max-width: 425px) {
      margin: 0;
    }
    
    @media(min-width: 768px) {
      font-size: 2.8125rem;
    }
    
  }
}
              
            
!

JS

              
                const sliderData = [
  {
    img: "https://images-na.ssl-images-amazon.com/images/M/MV5BMTk2NTI1MTU4N15BMl5BanBnXkFtZTcwODg0OTY0Nw@@._V1_SY1000_CR0,0,675,1000_AL_.jpg",
    name: "The Avengers",
    desc: "Earth's mightiest heroes must come together and learn to fight as a team if they are to stop the mischievous Loki and his alien army from enslaving humanity."
  },
  {
    img: "https://images-na.ssl-images-amazon.com/images/M/MV5BMTczNTI2ODUwOF5BMl5BanBnXkFtZTcwMTU0NTIzMw@@._V1_SY1000_CR0,0,674,1000_AL_.jpg",
    name: "Iron Man",
    desc: "After being held captive in an Afghan cave, billionaire engineer Tony Stark creates a unique weaponized suit of armor to fight evil."
  },
  {
    img: "https://images-na.ssl-images-amazon.com/images/M/MV5BOGE4NzU1YTAtNzA3Mi00ZTA2LTg2YmYtMDJmMThiMjlkYjg2XkEyXkFqcGdeQXVyNTgzMDMzMTg@._V1_SY1000_CR0,0,674,1000_AL_.jpg",
    name: "Thor",
    desc: "The powerful but arrogant god Thor is cast out of Asgard to live amongst humans in Midgard (Earth), where he soon becomes one of their finest defenders."
  },
  {
    img: "https://images-na.ssl-images-amazon.com/images/M/MV5BMTAwMjU5OTgxNjZeQTJeQWpwZ15BbWU4MDUxNDYxODEx._V1_SY1000_CR0,0,674,1000_AL_.jpg",
    name: "Guardians of the Galaxy",
    desc: "A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe."
  },
  {
    img: "https://images-na.ssl-images-amazon.com/images/M/MV5BNjgwNzAzNjk1Nl5BMl5BanBnXkFtZTgwMzQ2NjI1OTE@._V1_SY1000_CR0,0,674,1000_AL_.jpg",
    name: "Doctor Strange",
    desc: "While on a journey of physical and spiritual healing, a brilliant neurosurgeon is drawn into the world of the mystic arts."
  },
  {
    img: "https://images-na.ssl-images-amazon.com/images/M/MV5BMTYzOTc2NzU3N15BMl5BanBnXkFtZTcwNjY3MDE3NQ@@._V1_SY1000_CR0,0,640,1000_AL_.jpg",
    name: "Captain America",
    desc: 'Steve Rogers, a rejected military soldier transforms into Captain America after taking a dose of a "Super-Soldier serum". But being Captain America comes at a price as he attempts to take down a war monger and a terrorist organization'
  }
];

for (let i = 0; i < sliderData.length; i++) {
  const slider = document.querySelector(".slider");
  const {img, name, desc} = sliderData[i];
  const slideData = `
    <div class="slide ${i == 0 ? 'visible' : ''}" data-slide="slide-${i}">
      <div class="slide-image">
       <img src="${img}" />
      </div>
      <div class="slide-caption">
        <div class="slide-caption-content">
          <div class="title-bg">
            <h1>${name}</h1>
          </div>
          <p>${desc}</p>
        </div>
      </div>
    </div>
  `;
  slider.innerHTML += slideData;
}

const slides = document.querySelectorAll(".slide");
let currentSlide = 0;
const slideInterval = setInterval(() => {
  slides[currentSlide].classList.remove("visible");
  currentSlide = (currentSlide + 1) % slides.length;
  slides[currentSlide].classList.add("visible");
}, 5000);

              
            
!
999px

Console