Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

              
                <!-- 
  in a wrapping container include a header and a paragraph element 
  in the paragraph, include for each branch in the text a span element with the sup and sub elements 
-->
<div class="container">
  <h1>Complete the Story<sub>below</sub></h1>
  <p>
    The world is changed.
    I 
    <span class="choice">
      <sup>
        sense
      </sup>
      <sub>
        feel
      </sub> 
    </span>
    it in the water.
    I 
    <span class="choice">
      <sup>
        sense
      </sup>
      <sub>
        feel
      </sub> 
    </span>
    it in the earth.
    I 
    <span class="choice">
      <sup>
        smell
      </sup>
      <sub>
        see
      </sub> 
    </span>
    it in the air.
  </p>

  <p>
    Much that once was...is lost.
    <span class="choice">
      <sup>
        As
      </sup>
      <sub>
        For
      </sub> 
    </span>       
    none now live who 
    <span class="choice">
      <sup>
        remember
      </sup> 
      <sub>
        think of
      </sub>
    </span>
    it.
  </p>

  <p>
    It began with the 
    <span>
      <sup>
        creation
      </sup>
      <sub>
        forging
      </sub> 
    </span>
    of the Great Rings.
    </p>
    <p>
    <span class="choice">
      <sup>
        Four
      </sup>
      <sub>
        Three
      </sub>
    </span>
    were given to the Elves:
    Immortal, 
    <span>
      <sup>
        all-knowing
      </sup>
      <sub>
        wisest
      </sub>
    </span> 
    and fairest
    of all beings.
    </p>
    <p>
    Seven to the Dwarf-
    <span class="choice">
      <sup>
        lords
      </sup>
      <sub>
        people
      </sub>
    </span>.
    Great miners and 
    <span class="choice">
      <sup>
        artisans
      </sup>
      <sub>
        craftsmen
      </sub>
    </span>
    of the mountain halls.
    </p>
    <p>
    And nine...
    <span class="choice">
      <sup>
        nine
      </sup>
      <sub>
        too many
      </sub>
    </span>
    rings were gifted
    to the race of Men...who, above all else, 
    <span class="choice">
      <sup>
        desire
      </sup>
      <sub>
        long for
      </sub>
    </span>
    power.
    </p>
    <p>
    For 
    <span class="choice">
      <sup>
        inside
      </sup>
      <sub>
        within
      </sub>
    </span>
    these rings was 
    <span class="choice">
      <sup>
        bound
      </sup>
      <sub>
        hidden
      </sub>
    </span>
    the strength and 
    <span class="choice">
      <sup>
        will
      </sup>
      <sub>
        skill
      </sub>
    </span>
    to govern each race.
  </p>
</div>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css?family=Lato|Pacifico");

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  min-height: 100vh;
  width: 100%;
  font-family: 'Lato', sans-serif;
  color: #252525;
  background: 
    linear-gradient(to bottom right, #F1F1EE 0%, #A7A694 10%, transparent 10%), 
    linear-gradient(to bottom left, #F1F1EE 0%, #A7A694 10%, transparent 10%), 
    linear-gradient(to top right, #F1F1EE 0%, #A7A694 10%, transparent 10%), 
    linear-gradient(to top left, #F1F1EE 0%, #A7A694 10%, transparent 10%), 
    #A7A694;
}

.container {
  max-width: 650px;
  margin: 2rem auto;  
}
.container h1 {
  text-align: center;
}
.container h1 sub {
  font-size: 1rem;
}
.container p {
  font-size: 1.4rem;
  /* increase the line-height to accommodate for the vertically positioned sup and sub elements */
  line-height: 2;
  margin: 1rem;
}
.container p:first-letter {
  /* style the first letter of every paragraph to be larger and cursive */
  font-family: 'Pacifico', cursive;
  font-size: 2rem;
}
.container span.choice {
  font-size: 1.4rem;
  margin: 0 0.3rem;
}
.container p sub, .container p sup {
  font-style: italic;
  cursor: pointer;
  border-radius: 6px;
  border: 2px solid #838C7B;
  transition: all 0.2s ease-out;
  /* position relative to separate a little more the elements from each other, vertically */
  position: relative;
}
.container p sup {
  bottom: 10px;
}
.container p sub {
  top: 10px;
}
.container p sub:hover, .container p sup:hover {
  /* on hover change the color of the backround to match the color of the border */
  background: #838C7B;
}


              
            
!

JS

              
                // target all sup and sub elements in the paragraph element
const sup = document.querySelectorAll("p sup");
const sub = document.querySelectorAll("p sub");

// add an event listener on all sup and sub elements, at which point call a function which removes the choice not made and displays the correct text in a span
sup.forEach(sup => sup.addEventListener("click", displayChoice));
sub.forEach(sub => sub.addEventListener("click", displayChoice));

function displayChoice(e) {
    // target the parent element of the clicked sup/sub element
    let parentSpan = e.target.parentNode;
    
    // include in the HTML of the span element only the text of the clicked sup/sub element, effectively removing the sup/sub elements themselves
    parentSpan.innerHTML = `${e.target.textContent}`;
    // reset the margin altered in the script
    parentSpan.style.marginLeft = `0px`;
    parentSpan.style.marginRight = `0px`;  
}

// loop through all sup elements (which are horizontally pushed to the right of sub elements)
sub.forEach(sub => {
    // consider the width of the sub elements
    let subWidth = sub.offsetWidth;

    // push the sub elements to the left, by a measure equal to their width
    sub.parentNode.style.marginLeft = `-${subWidth}px`;
    // move the connected sup element to the right by an equal amount, making the sup and sub elements coincide to the right edge of the sub elements
    sub.parentNode.querySelector("sup").style.left = `${subWidth}px`;
});


              
            
!
999px

Console