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

              
                <!-- Based on component techniques by Adrian Roselli and Heydon Pickering H/T -->

<h1>Accessible cards demo <span aria-hidden="true">·</span> block link</h1>

<section>

  <ul class="cards">
    <li>
      <!--   Card 1    -->
      <article class="card reorder">
        <h2>
          <a href="https://www.google.com">Card title here</a>
        </h2>
        <img src="https://assets.codepen.io/282691/man-landscape-unsplash.jpg" alt="" loading="lazy" width="500" height="200">
        <p>Some text, just a line to make up some description&hellip;</p>
      </article>
      <!--  End of card 1    -->
    </li>

    <!--  Card 2    -->
    <li>
      <article class="card reorder">
        <h2><a href="#">Second card title here</a></h2>
        <img src="https://assets.codepen.io/282691/abstract-unsplash.jpg" alt="" loading="lazy" width="500" height="200">
        <p>Some text, just a line to make up some description&hellip;</p>
      </article>
      <!--  End of card 2   -->
    </li>
    <!--  Card 3  -->
    <li>
      <article class="card reorder">
        <h2><a href="#">Third card title here</a></h2>
        <img src="https://assets.codepen.io/282691/desk-laptop-unsplash.jpg" alt="" loading="lazy" width="500" height="200">
        <p>Some text, just a line to make up some description&hellip;</p>

      </article>
      <!--   End of card 3   -->
    </li>

  </ul>

</section>
              
            
!

CSS

              
                /*

Basic layout and styles. For production, would probably want to use both Flex and Grid for layout

*/

body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  line-height: 1.4;
  color: #333;
  background: #efefef;
  margin: 0 auto;
  padding: 1em;
}

h2 {
  font-size: 1.4rem;
  margin-top: .5em;
  margin-bottom: .2em;
  line-height: 1;
}

.cards {
  display: flex;
  flex-direction: row;
  justify-content: center;
  flex-wrap: wrap;
  list-style: none;
  margin: 0;
  padding: 0;
}

.cards > * {
  flex: 0 1 25em;
}

.card {
  margin: .75em;
  padding: .75em;
  border-radius: 3px;
  border: 2px #ccc solid;
  border-radius: .6em;
  background-color: white;
}

img {
  width: 100%;
  height: auto;
}

/* Start of moving the image above the heading */

.reorder {
  display: flex;
  flex-direction: column;
}

.reorder img {
   max-width: 100%;
   order: -1;
}

/* End of moving the image above the heading */

.card > * a, .card > .cta {
  display: block;
}

.card h2 > a {
  text-decoration: none;
  color: inherit;
}

.linkify:hover {
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(38, 50, 190, .8);
}

.cards .isfocused {
  outline: 0;
   box-shadow: 0 0 0 3px rgba(38, 50, 190, .8);
}

.isfocused a:focus {
  outline: none;
}

.card .cta {
  text-decoration: underline;
  color: #242AC1;
  font-weight: bold;
}
              
            
!

JS

              
                /* Credit to Alastair Campbell for providing the basis of this script */


// Link up the cards

function linkBoxes() {
  var boxes = document.querySelectorAll("article.card");

  boxes.forEach(function (box) {
    var link = box.querySelector("a");
    if (link) {
      var url = link.getAttribute("href");
      box.addEventListener("click", function () {
        location.href = url;
        link.preventDefault;
      });
      box.classList.add("linkify");
      link.addEventListener("focus", function () {
        box.classList.add("isfocused");
      });
      link.addEventListener("blur", function () {
        box.classList.remove("isfocused");
      });

 /* Inject CTA in to cards as visual affordance but hide from assistive tech announcements */
      box.insertAdjacentHTML("beforeend", '<span class="cta" aria-hidden="true">Read more</span>');
    }
  });
}
document.addEventListener("DOMContentLoaded", function () {
  if ("querySelector" in document) {
    linkBoxes();
  }
});

              
            
!
999px

Console