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

Auto Save

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

              
                <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Work+Sans:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Caveat+Brush&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;800&display=swap" rel="stylesheet">

<div class="rdc-tu-dov">
  <h1>Display the Currently Selected Option Name</h1>
  <div class="rdc-tu-dov-inner">
     <div class="rdc-tu-dov-box">
       <div class="rdc-tu-dov-legend">
         <legend>FLAVOR</legend><span class="rdc-tu-dov-name one">vanilla</span>
</div>
  <div class="rdc-tu-dov-opts fl">
    <span class="rdc-tu-dov-opt fl rdc-active" data-value="vanilla"><img src="https://uploads-ssl.webflow.com/638ad076698caa5b223b1bc6/63e4a6da3963c57c417746f1_coffee-cup.png"></span>
    <span class="rdc-tu-dov-opt fl" data-value="caramel"><img src="https://uploads-ssl.webflow.com/638ad076698caa5b223b1bc6/63e4a6d727705d1be44d2888_coffee-cup%20(1).png"></span>
    <span class="rdc-tu-dov-opt fl" data-value="mocha"><img src="https://uploads-ssl.webflow.com/638ad076698caa5b223b1bc6/63e4a6d56d2b6cee9e06da84_coffee-cup%20(2).png"></span>
    <span class="rdc-tu-dov-opt fl" data-value="americano"><img src="https://uploads-ssl.webflow.com/638ad076698caa5b223b1bc6/63e4a6d38c122ba45840dceb_coffee-cup%20(3).png"></span>
</div>
</div>
         <div class="rdc-tu-dov-box">
       <div class="rdc-tu-dov-legend">
         <legend>SIZE</legend><span class="rdc-tu-dov-name two">small</span>
</div>
  <div class="rdc-tu-dov-opts sz">
    <span class="rdc-tu-dov-opt sz rdc-active" data-value="small">SMALL</span>
    <span class="rdc-tu-dov-opt sz" data-value="large">LARGE</span>
</div>
</div>
</div>
  <a href="https://www.reddelacruz.dev/tutorials" target="blank">by rdc</a>
  <a class="bmacrdc" href="https://www.buymeacoffee.com/reddelacruzdev" target="blank"><img src="https://uploads-ssl.webflow.com/638ad076698caa5b223b1bc6/63e4d944f470fc036178c8bb_rdc%20red%20dela%20cruz%20buy%20me%20a%20coffee%202.png"></a>
</div>
              
            
!

CSS

              
                * {
  font-family: 'Work Sans';
  box-sizing: border-box;
  margin: 0;
}
.rdc-tu-dov {background-color: #f6edcd}
.rdc-tu-dov,
.rdc-tu-dov-opts,
.rdc-tu-dov-inner,
.rdc-tu-dov-opt,
.rdc-tu-dov-legend {display: flex}

.rdc-tu-dov {height: 100vh}

.rdc-tu-dov,
.rdc-tu-dov-inner {flex-flow: column}

.rdc-tu-dov,
.rdc-tu-dov-opt,
.rdc-tu-dov-legend {
  align-items: center;
}
.rdc-tu-dov,
.rdc-tu-dov-opt {
  justify-content: center;
}

.rdc-tu-dov-opt {
  background-color: #E5D484;
  padding: 15px;
  width: 24%;
  margin: .5%;
  cursor: pointer;
  transition: all .2s;
  border: 4px solid transparent;
}

.rdc-tu-dov-opt:hover {filter: brightness(.9)}

.rdc-tu-dov-box:first-of-type {margin-bottom: 20px}

.rdc-tu-dov-inner {
  background-color: #f0e8c0;
  width: 100%;
  max-width: 500px;
  padding: 40px 30px;
  border: 7px solid #4f463b;
}

h1,a {color: #2C2522;}

h1 {
  font-size: 30px;
  margin-bottom: 40px;
  text-align: center;
}

img {max-width: 100%}
legend {color: #4D4239}

legend,
.rdc-tu-dov-opt.sz {font-weight: 600}

.rdc-tu-dov-opt.sz {
  font-size: 14px;
  color: #553829;
}

.rdc-tu-dov-opt.rdc-active {border: 4px solid #6b604a}

.rdc-tu-dov-name {
  margin: 0 0 5px 5px;
  font-family: 'Caveat Brush';
  font-size: 24px;  
  color: #362E2A;
}

a {
  font-family: 'Montserrat';
  margin-top: 30px;
  font-weight: 800;
  font-size: 20px;
}

.bmacrdc img {width: 80px}
              
            
!

JS

              
                // 1. Declare a variable for all of the options regardless if it's under size, color etc. 'querySelectorAll' helps in achieving this.

const opts = document.querySelectorAll('.rdc-tu-dov-opt')

// 2. Write your function
const updateOptName = function () {
  
  // Declare the siblings of the clicked option by using the 'this' keyword
  const thisSiblings = this.parentElement.children
  
  // Declare option name container for the clicked option by using the 'this' keyword
  const optName = this.parentElement.previousElementSibling.children[1]
  
  // Delete the 'rdc-active' class from all of the siblings of the clicked option. This way, you are not deleting it from the other option type's options. This is done to remove the border around the box which means it is currently selected.
  
  Array.from(thisSiblings).forEach(thisSibling =>       thisSibling.classList.remove('rdc-active'))
  
  // Using the innerText property, you can now add the value of the clicked option to its option name container.
  optName.innerText = this.getAttribute('data-value')
  
  // Add the 'rdc-active' class to show the border on the clicked option.
  this.classList.add('rdc-active')
}

// Run the code when an option is clicked
opts.forEach(opt => opt.addEventListener('click',updateOptName))
              
            
!
999px

Console