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

              
                <h1>Content Group</h1>
<p>How to wrap an image, link, and text as one large touch target, while using progressively enhanced, valid HTML and keeping things fully accessible.</p>

<article class="article-teaser js-content-group" data-url="https://google.com" data-title="Google">  
  <img src="http://placehold.it/200x150" width="200" height="150" alt=""/>  
  <h2>
    <a href="https://google.com">Google</a>
  </h2>  
  <p>Search the internet for things.</p>  
</article>

<article class="article-teaser js-content-group" data-url="https://apple.com" data-title="Apple">  
  <img src="http://placehold.it/200x150" width="200" height="150" alt=""/>  
  <h2>
    <a href="https://apple.com">Apple</a>
  </h2>  
  <p>This one points to the Apple homepage.</p>  
</article>

<article class="article-teaser js-content-group" data-url="http://a11yproject.com" data-title="A11Y Project">  
  <img src="http://placehold.it/200x150" width="200" height="150" alt=""/>  
  <h2>
    <a href="http://a11yproject.com">A11YProject</a>
  </h2>  
  <p>One more for testing purposes.</p>  
</article>

<ul>
  <li>The idea behind this is to minimize the amount of tab presses required by keyboard users to navigate through content.</li>
  <li>Inspired after watching this video from Nomensa: <a href="http://www.nomensa.com/blog/2014/tips-on-combining-image-and-text-links/">Tips on combining image and text links</a>.</li>
  <li>This concept is also a <a href="http://www.w3.org/TR/2014/NOTE-WCAG20-TECHS-20140311/H2">WCAG 2.0 technique requirement</a>.</li>
  <li>Tested with NVDA+Firefox, ChromeVox, and VoiceOver+Chrome.</li>
  <li><a href="https://codepen.io/svinkle/pen/GfumK">jQuery version</a>.</li>
</ul>
              
            
!

CSS

              
                a {
  text-decoration: none;
}

.article-teaser {
  border: solid LightGray 1px;
  display: inline-block;
  margin: 0 1em 1em 0;
  max-width: 10em;
}

.article-teaser img {
  height: auto;
  max-width: 100%;
}
  
.article-teaser h2 {
  padding: 0 .5em;
}
  
.article-teaser p {
  padding: 0 1em;
}

.clickable {
  cursor: pointer;
}
              
            
!

JS

              
                (function (document, window, undefined) {
  'use strict';
  
  // Vars
  var contentGroup = document.querySelectorAll('.js-content-group');
  
  // For each
  [].forEach.call(contentGroup, function(group, index) {
    // Vars
    var link = group.querySelector('a'),
        title = group.querySelector('h2'),
        text = group.querySelector('p');
    
    // Set attributes
    link.setAttribute('tabindex', '-1');    
    title.setAttribute('id', 'group-title-' + index);    
    text.setAttribute('id', 'group-text-' + index);
    text.setAttribute('aria-hidden', 'true');
    
    // Group "button" attibutes
    group.classList.add('clickable');
    group.setAttribute('tabindex', '0');
    group.setAttribute('role', 'link');
    group.setAttribute('aria-labelledby', 'group-title-' + index);
    group.setAttribute('aria-describedby', 'group-text-' + index);
    
    // Click event
    group.addEventListener('click', function () {
      window.location.href = this.getAttribute('data-url');      
    }, false);
    
    // Keydown event
    group.addEventListener('keydown', function (event) {
      if (event.which === 13) {
        event.preventDefault();
        window.location.href = this.getAttribute('data-url');      
      }
    }, false);
  });
    
})(document, window);
              
            
!
999px

Console