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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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 id="main">
  <article>
    <section>
      <h1>Select with Dynamic Button</h1>
    </section>

    <section id="intro">
      <div class="flex-container clearfix">
        <div class="column-half flex-container">
          <p>
            Select an option to change the button text and link.
          </p>
          <p>
            Be prepared to see photos of your fave cuties 😉
          </p>
          <label for="pet-select">Choose a pet</label>

          <select name="pets" id="pet-select">
            <option id="something" value="something" data-link="#">--Please choose an option--</option>
            <option id="dog" value="dog" data-link="https://balistreetphotographer.com/galleries/i-love-bali-dogs">Dog</option>
            <option id="cat" value="cat" data-link="https://unsplash.com/s/photos/cat">Cat</option>
            <option id="hamster" value="hamster" data-link="https://unsplash.com/s/photos/hamster">Hamster</option>
            <option id="parrot" value="parrot" data-link="https://unsplash.com/s/photos/parrot">Parrot</option>
            <option id="spider" value="spider" data-link="https://unsplash.com/s/photos/spider">Spider</option>
            <option id="goldfish" value="goldfish"  data-link="https://unsplash.com/s/photos/goldfish">Goldfish</option>
          </select>
          <a id="redirect" href="#" target="_blank">
           <button id="select-button">See ??? Photos</button>
          </a>
        </div>
      </div>
    </section>
  </article>
</main>

<footer id="footer">
  <section>
    <div class="flex-container clearfix">
      <p><a href="https://www.caughtmyeye.cc/" target="_blank">caught my eye</a>
    </div>
  </section>
</footer>
              
            
!

CSS

              
                /** || Add your styles here */

p {
  font-size: 1.5rem;
}

label {
  font-size: 2rem;
}

label,
select,
button {
  display: block;
  margin: 2%;
  text-align: center;
}

button,
select {
  font-size: 1.5rem;
  padding: 1% 2%;
}

#select-button {
  color: white;
  background-color: blue;
  border-radius: 3px;
  text-transform: uppercase;
}

#select-button:hover {
  background-color: limegreen;
  color: black;
}

a#redirect {
  border-bottom: none;
  text-decoration: none;
}

/** || General Styles */

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

/* Variables */

:root {
  --dt-padding: 10px 30px 10px 30px;
  --mob-padding: 1%;
  --med-margin: 3rem;
  --p-margin: 0 0 1em 0;
  --dark-colour: black;
  --light-colour: white;
  --light-black: #111;
  --footer-colour: #F05E35; /* Deep Orange */
  --debug-outline: none; /* 2px dotted firebrick; */
  --no-border: none;
}

/* Normalise */

/**
 * 1. Correct the line height in all browsers.
 * 2. Prevent adjustments of font size after orientation changes in iOS.
 */

html {
  line-height: 1.15; /* 1 */
  -webkit-text-size-adjust: 100%; /* 2 */
}

/**
 * Remove the margin in all browsers.
 */

body {
  background: var(--dark-colour);
  color: var(--light-colour);
  font-size: 18px;
  margin: 0;
  padding-bottom: 60px;
}

/** 
 * || Stuff below is optional. 
 * 
 * Pick and choose what you want. 
 */

main {
  margin-bottom: var(--med-margin);
}

main, footer {
  text-align: center;
  padding: var(--mob-padding); /* Mobile First */
  font: 1rem 'Helvetica Neue Light', Helvetica, Arial, sans-serif;
}

main p {
  text-align: left;
  margin: var(--p-margin);
}

#intro p {
  text-align: center;
}

main h1,
main h2 {
  font-weight: 100;
}

h1, main h1 {
  font-size: 2rem;
}

.flex-container {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
}

.grid-container {
  display: grid;
  /* Rows / Columns */
  grid-template: 1fr auto 1fr / repeat(4, 1fr);
  gap: 3px;
  /*
  width: 45vw;
  border: 1.5px solid var(--light-colour);
  */
}

.grid-container .grid-item {
  border: 1.5px solid var(--light-colour);
  text-align: center;
  padding: 0.5rem;
  border: var(--debug-border);
}

/* Fallback if no flexbox support. */
.clearfix:after {
  content: "";
  display: table;
  clear: both;
}

.column-full {
  float: none;
  width: 100%;
  outline: var(--debug-outline);
}

.column-half {
  float: left;
  width: 50%;
  outline: var(--debug-outline);

}

.column-third {
  float: left;
  width: 33.333%;
  outline: var(--debug-outline);
}

a, footer a {
  color: var(--footer-colour);
  text-decoration: none;
}

main a, footer a {
  border-bottom: 2px solid;
  line-height: 1.45;
}

a:hover {
  opacity: .7;
}

code {
  color: limegeen;
}

#footer {
  bottom: 0;
  background-color: var(--light-black);
  left: 0;
  padding: 0;
  position: fixed;
  right: 0;
}

/* Media Queries */

/** 
 * Kick in desktop sizing only when needed. 
 * 667px is iPhone 6 landscape width. 
 */
@media screen and (min-width: 667px) {
  main {
    padding: var(--dt-padding);
  }
}

/* End General Styles */

              
            
!

JS

              
                (function () {
  const input = document.getElementById("pet-select");
  let button = document.getElementById("select-button");
  const redirect = document.getElementById("redirect");
  let selection = "something";

  // Event handlers
  input.onchange = handleChange;
  button.onclick = handleClick;

  // This function changes the button text and link.
  function handleChange(e) {
    selection = e.target.value;
    button.textContent = `See ${selection} Photos`.toUpperCase();
    const link = document.getElementById(`${selection}`).dataset.link;
    if (link) redirect.setAttribute("href", link);
  }

  // Optional function for demo purposes.
  function handleClick(e) {
    let plural = (selection === "goldfish") ? "es" : "s";
    alert(`We love ${selection}${plural} too!`);
  }
})();

              
            
!
999px

Console