cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <!-- 
  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>
            
          
!
            
              @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;
}


            
          
!
            
              // 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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console