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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <main class="grid" data-active="1">
  <div class="title" id="titles">
    <h1 data-info="1" class="jsActive">Green Tea</h1>
    <h1 data-info="2">Sencha</h1>
    <h1 data-info="3">Matcha</h1>
  </div>

  <div class="image">
    <img src="https://i.imgur.com/ZRGxZQ4.jpg" alt="Varieties of Green Tea">
  </div>

  <div class="content">
    <div data-info="1" class="jsActive">
      <p>Green tea is made from the leaves of Camellia sinensis that have undergone minimal oxidation during processing. Green tea originates in China, but it has become associated with many cultures throughout Asia.</p>
      <p>Green tea has recently become more widespread in the West, where black tea has been the traditionally consumed tea. Green tea has become the raw material for extracts which are used in various beverages, health foods, dietary supplements, and cosmetic items.</p>
      <p>Many varieties of green tea have been created in the countries where it is grown. These varieties can differ substantially due to variable growing conditions, horticulture, production processing, and harvesting time.</p>
    </div>
    <div data-info="2">
      <p>Sencha (煎茶) is a Japanese green tea witch is distinguished by its fresh taste and the uniform and emerald leaves. It is the most popular tea in Japan accounting for about 80% of the produced teas.</p>
      <p>Sencha is like most Japanese green teas briefly treated with hot steam in order to prevent the oxidation (kill green) while in China green tea is mostly roasted for a short time at about 280° C.</p>
      <p>The best and most expensive quality of Sencha is Shincha, the first flush, which is harvested depending on the region between April and May.</p>
    </div>
    <div data-info="3">
      <p>Matcha (抹茶) is a powder green tea used in the Japanese tea ceremony. But nowadays matcha is also used as a fancy drink or to flavour foods such as mochi and soba noodles, shakes or ice cream. Matcha is made of tencha, a shaded tea similar to gyokuro.</p>
      <p>Matcha are often given poetic names called chamei (tea names) either by the producing plantation, shop or creator of the blend, or by the grand master of a particular tea tradition. When a blend is named by the grand master of some tea ceremony lineage, it becomes known as the master's konomi, or favoured blend. </p>
    </div>
  </div>

  <div class="nav">
    <button id="prev" type="button">Prev</button>
    <button id="next" type="button">Next</button>
  </div>
</main>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Gentium+Book+Basic');

html {
  box-sizing: border-box;
}

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

* {
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Gentium Book Basic', serif;
}

p {
  line-height: 1.4;
  margin-bottom: 1em;
}

img {
  max-width: 100%;
  object-fit: contain;
  height: 100%;
}

button {
  font-family: inherit;
  font-size: inherit;
  border: 0;
  padding: 0.5em 1em;
  cursor: pointer;
  transition: background-color 0.5s;
}

button:hover {
  background-color: darkgrey;
}

h1 {
  display: none;
  margin: auto;
}

p {
  display: none;
}

p:last-child {
  margin-bottom: 0;
}

h1.jsActive,
.jsActive p {
  display: block;
}

.grid {
  padding: 10px;
  background-color: #ffff96;
}

.grid > div {
  background-color: #1b2b34;
  padding: 1em;
  color: #ffff96;
}

.nav {
  display: flex;
  justify-content: space-around;
}

@media screen and (min-width: 440px) {
  .grid {
    display: grid;
    grid-template-columns: 6em calc(100% - 6.25em);
    grid-template-rows: 45vh 25vh max-content;
    grid-template-areas: 'title image'
                         'nav image'
                         'content content';
    gap: 0.25em;
    transition: all 1s;
  }
  
  .image { 
    grid-area: image;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .title {
    grid-area: title;
    writing-mode: vertical-rl;
    display: flex;
  }

  .content {
    grid-area: content;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .nav {
    grid-area: nav;
    flex-direction: column;
  }
}

@media screen and (min-width: 820px) {
  .grid {
    grid-template-columns: 55% calc(45% - 0.5em);
    grid-template-rows: 4em 1fr max-content;
    grid-template-areas: 'image title'
                         'image content'
                         'image nav';
    gap: 0.5em;
  }
  
  .title {
    writing-mode: horizontal-tb;
  }
  
  .nav {
    flex-direction: row;
  }
}

              
            
!

JS

              
                const prevBtn = document.getElementById('prev')
const nextBtn = document.getElementById('next')
const totalData = document.getElementById('titles').childElementCount

prevBtn.addEventListener('click', prevHandler, false)
nextBtn.addEventListener('click', nextHandler, false)

function prevHandler(evt) {
  let activeData = parseInt(document.querySelector('[data-active]').dataset.active)
  const prevData = activeData - 1

  if (activeData > 1) {
    Array.prototype.forEach.call(document.querySelectorAll('[data-info="' + activeData + '"]'), info => {
      info.classList.remove('jsActive')
    })
    Array.prototype.forEach.call(document.querySelectorAll('[data-info="' + prevData + '"]'), info => {
      info.classList.add('jsActive')
    })
    document.querySelector('[data-active]').dataset.active = activeData - 1
  } else {
    console.log('Reach the start already')
  }
}

function nextHandler(evt) {
  let activeData = parseInt(document.querySelector('[data-active]').dataset.active)
  const nextData = activeData + 1
  if (activeData < totalData) {
    Array.prototype.forEach.call(document.querySelectorAll('[data-info="' + activeData + '"]'), info => {
      info.classList.remove('jsActive')
    })
    Array.prototype.forEach.call(document.querySelectorAll('[data-info="' + nextData + '"]'), info => {
      info.classList.add('jsActive')
    })
    document.querySelector('[data-active]').dataset.active = activeData + 1
  } else {
    console.log('Reach the end already')
  }
}
              
            
!
999px

Console