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

              
                <main>
  <h1>Keyboard Overflow Tests</h1>
  
  <p>
    This is an example for my post <cite><a href="http://adrianroselli.com/2016/02/keyboard-and-overflow.html">Keyboard and Overflow</a></cite>. That link also acts a handy tab-stop to see where you are as you start playing.
  </p>

  <h2>With Ellipsis</h2>
  
  <table id="Books-ellipsis" class="ellipsis">
    <colgroup>
      <col>
      <col>
      <col class="number">
    </colgroup>
    <thead>
      <tr>
        <th>Author</th>
        <th>Title</th>
        <th class="number">Year</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><div>Homer</div></td>
        <td><div><em>Iliad</em></div></td>
        <td class="number"><div>BC ~800</div></td>
      </tr>
      <tr>
        <td><div>Miguel De Cervantes</div></td>
        <td><div ><em>The Ingenious Gentleman Don Quixote of La Mancha</em></div></td>
        <td class="number"><div>1605</div></td>
      </tr>
      <tr>
        <td><div>Mary Shelley</div></td>
        <td><div><em>Frankenstein; or, The Modern Prometheus</em></div></td>
        <td class="number"><div>1818</div></td>
      </tr>
      <tr>
        <td><div>Herman Melville</div></td>
        <td><div><em>Moby-Dick; or, The Whale</em></div></td>
        <td class="number"><div>1851</div></td>
      </tr>
      <tr>
        <td><div>Emma Dorothy Eliza Nevitte Southworth</div></td>
        <td><div><em>The Hidden Hand</em></div></td>
        <td class="number"><div>1888</div></td>
      </tr>
      <tr>
        <td><div>F. Scott Fitzgerald</div></td>
        <td><div><em>The Great Gatsby</em></div></td>
        <td class="number"><div>1925</div></td>
      </tr>
      <tr>
        <td><div>George Orwell</div></td>
        <td><div><em>Nineteen Eighty-Four</em></div></td>
        <td class="number"><div>1948</div></td>
      </tr>
      <tr>
        <td><div>Peter Weiss</div></td>
        <td><div><em>The Persecution and Assassination of Jean-Paul Marat as Performed by the Inmates of the Asylum of Charenton Under the Direction of the Marquis de Sade</em></div></td>
        <td class="number"><div>1963</div></td>
      </tr>                            
      <tr>
        <td><div>William Goldman</div></td>
        <td><div><em>The Princess Bride: S. Morgenstern's Classic Tale of True Love and High Adventure</em></div></td>
        <td class="number"><div>1973</div></td>
      </tr>
    </tbody>
  </table>

  <h2>With Scroll</h2>
  
  <table id="Books-scroll" class="scroll">
    <colgroup>
      <col>
      <col>
      <col class="number">
    </colgroup>
    <thead>
      <tr>
        <th>Author</th>
        <th>Title</th>
        <th class="number">Year</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><div>Homer</div></td>
        <td><div><em>Iliad</em></div></td>
        <td class="number"><div>BC ~800</div></td>
      </tr>
      <tr>
        <td><div>Miguel De Cervantes</div></td>
        <td><div ><em>The Ingenious Gentleman Don Quixote of La Mancha</em></div></td>
        <td class="number"><div>1605</div></td>
      </tr>
      <tr>
        <td><div>Mary Shelley</div></td>
        <td><div><em>Frankenstein; or, The Modern Prometheus</em></div></td>
        <td class="number"><div>1818</div></td>
      </tr>
      <tr>
        <td><div>Herman Melville</div></td>
        <td><div><em>Moby-Dick; or, The Whale</em></div></td>
        <td class="number"><div>1851</div></td>
      </tr>
      <tr>
        <td><div>Emma Dorothy Eliza Nevitte Southworth</div></td>
        <td><div><em>The Hidden Hand</em></div></td>
        <td class="number"><div>1888</div></td>
      </tr>
      <tr>
        <td><div>F. Scott Fitzgerald</div></td>
        <td><div><em>The Great Gatsby</em></div></td>
        <td class="number"><div>1925</div></td>
      </tr>
      <tr>
        <td><div>George Orwell</div></td>
        <td><div><em>Nineteen Eighty-Four</em></div></td>
        <td class="number"><div>1948</div></td>
      </tr>
      <tr>
        <td><div>Peter Weiss</div></td>
        <td><div><em>The Persecution and Assassination of Jean-Paul Marat as Performed by the Inmates of the Asylum of Charenton Under the Direction of the Marquis de Sade</em></div></td>
        <td class="number"><div>1963</div></td>
      </tr>                            
      <tr>
        <td><div>William Goldman</div></td>
        <td><div><em>The Princess Bride: S. Morgenstern's Classic Tale of True Love and High Adventure</em></div></td>
        <td class="number"><div>1973</div></td>
      </tr>
    </tbody>
  </table>
  
  <p>
    This is an example for my post <cite><a href="http://adrianroselli.com/2016/02/keyboard-and-overflow.html">Keyboard and Overflow</a></cite>. That link also acts a handy tab-stop to see where you are as you finish playing.
  </p>

</main>

              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Lato:400,700);

body {
  background-color: #6D695C;
  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAACVBMVEUAAAAAAAAAAACDY+nAAAAAA3RSTlMmDQBzGIDBAAAAG0lEQVR42uXIIQEAAADCMHj/0NdkQMws0HEeAqvwAUGJthrXAAAAAElFTkSuQmCC);
  font-size: 100%;
  color: #333;
  font-family: Lato, Arial, sans-serif;
  padding: 0;
  margin: 0;
}

main {
  display: block;
  box-sizing: border-box;
  /*width: 90%;
  margin: 1em auto;
  padding: 1em 2em;*/
  color: #000;
  background-color: rgba(204,204,204,.7);
  border: .07em solid rgba(0,0,0,.5);
  border-radius: .5em;
}

table {
  /*border: 1px dotted #00f;*/
  margin: 1em 0;
  border-collapse: collapse;
  width: 100%;
}

th, td {
  /*padding: .25em .5em .25em 1em;*/
  /*border: 1px dotted #0f0;*/
  vertical-align: text-top;
  text-align: left;
  /*text-indent: -.5em;*/
}

tr:nth-child(even) {
  background-color: rgba(255,255,255,.25);
}

tr:nth-child(odd) {
  background-color: rgba(0,0,0,.1);
}

th {
  vertical-align: bottom;
  background-color: rgba(0,0,0,.5);
  color: #fff;
  font-weight: bold;
}

td.right, th.right, td.number, th.number/*, col.number || td, col.right || td  CSS4 table col selector */ {
  text-align: right;
}

/* Experimental styles */

th {
  padding: .25em 1vw;
}


td:nth-of-type(1) {
  /*width: 25%;*/
}

td:nth-of-type(1) div {
  width: 12em;
  width: 20vw;
}

td:nth-of-type(2) {
  /*width: 65%;*/
}

td:nth-of-type(2) div {
  width: 20em;
  width: 60vw;
}

td:nth-of-type(3) {
  /*width: 10%;*/
}

td:nth-of-type(23) div {
  width: 12vw;
}

td {
  position: relative;
  min-height: 1em;
  padding: 0;
  text-indent: 0;
}

td div {
  box-sizing: border-box;
  /*height: 1.7em;*/
  /*width: 100%;*/
  /*max-width: 10em;*/ /* apparently i need a set size, not a % */
  /*width: calc(100%/2);*/
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /*display: block;*/
  margin: 0;
  padding: 0;
  /*outline: 1px dotted #f00;*/
  padding: .25em .5vw .25em 1vw;
  text-indent: -.5vw;
  /*display: inline;*/
}

.scroll td div {
  overflow: scroll;
  text-overflow: initial;
  white-space: normal;
}

.ellipsis td div:focus, .ellipsis td div:hover {
  height: auto;
  position: absolute;
  width: 100%;
  max-width: 100%;
  white-space: normal;
  overflow: visible;
  text-overflow: initial;
  z-index: 1;
  outline: 1px solid #999;
}

.scroll td div, .scroll td div:focus, .scroll td div:hover {
  overflow: auto;
  height: 2em;
}

.scroll td div:focus, .scroll td div:hover {
  outline: 1px solid #999;
}

tr:nth-child(even), tr:nth-child(even) div {
  background-color: #ccc;
}

tr:nth-child(odd),tr:nth-child(odd) div {
  background-color: #ddd;
}

main {
  position: relative;
}

main {
  width: auto;
  padding: 1em 2vw;
  margin: 1em 2vw;
}


/*

2 | 2 main 2 | 2 == 8

0 | 0 table 0 | 0 == 0

0 | 0 td 0 | 0 == 0

cols have 100 - 8 = 92 to split by three...

20, 60, 12


0 | 1 div .5 | 0 == 1.5  x  3 == 4.5

*/
              
            
!

JS

              
                // Checking to see if there is probably an ellipsis
function CheckOverflow(aDiv) {
  try{
    eID = aDiv;
    // There is no way to test for presense of ellipsis, so we
    // compare the width/height with the clipped width/height
    if (eID.scrollWidth > eID.offsetWidth || eID.scrollHeight > eID.offsetHeight) {
      // element probably has ellipsis
      // console.log('yep!');
      return true;
    } else {
      // element probably does not overflow
    }
  } catch(e) {
    console.log('CheckOverflow(): ' + e);
  }
}
// Adding accessibility attributes
function AddKbdAttrs(aDiv) {
  try{
    // Get the element with the passed ID
    //eID = document.getElementById(divID);
    eID = aDiv;
    //eID.style.backgroundColor = '#0f0';
    // Give the element a tabindex=0 so it has a tab stop
    eID.setAttribute('tabindex', '0');
    // Give it a role so screen readers know this is a thing
    eID.setAttribute('role', 'region');
    // Now give it a label so screen readers know why it's a thing
    eID.setAttribute('aria-label', 'Text that visually overflows.');
  } catch(e) {
    console.log('AddKbdAttrs(): ' + e);
  }
}
// Find elements within a given container and see if they are candidates
// to have content overflowing with an ellipsis, then add the appropriate
// accessibility attributes for keyboard users that also keep screen
// reader users from getting an aural assault
function PossibleOverflows(containerID) {
  try{
    // Get the element with the passed ID
    // I do this to reduce the number of nodes to traverse
    // To-do: Modify function to use document root if blank
    var eID = document.getElementById(containerID);
    // Get all the elements that match the selector
    // You could put your own in here to reduce the resultant node list
    var matches = eID.querySelectorAll('div');
    // Return the node list count
    // console.log(matches.length);
    // Now loop
    for( i=0; i < matches.length; i++ ) {
      var match = matches[i];
      // Get the rendered style of each
      var computedStyle = window.getComputedStyle(match, null);
      // Now get the overflow property
      var computedOverflow = computedStyle.getPropertyValue('overflow');
      //console.log(computedOverflow);
      // If it is hidden, do stuff
      if (computedOverflow === 'hidden') {
        // Now identify if it is set to use an ellipsis
        var hasEllipsis = computedStyle.getPropertyValue('text-overflow') === 'ellipsis';
        // Now check if this matches
        //console.log(window.getComputedStyle(match, null).textOverflow);
        if (hasEllipsis) {
          // Now check it against my ellipsis function
          var anyEllipsis = CheckOverflow(match);
          // If the function says it's ellipsising, call the function to add attrs
          if (anyEllipsis === true) {
            // Call function to add attributes
            AddKbdAttrs(match);
          }
        }
      } else if (computedOverflow === 'scroll' || computedOverflow === 'auto') {
        // Now identify if the overflow is scrolling (auto, scroll, scroll-x, scroll-y)
        //console.log('foo');
        var probablyScroll = CheckOverflow(match);
        if (probablyScroll === true) {
          // Call function to add attributes
          AddKbdAttrs(match);
        }
      }
    }
  } catch(e) {
    console.log('PossibleOverflows(): ' + e);
  }  
}


//PossibleOverflows('Books-ellipsis');
//PossibleOverflows('Books-scroll');

window.onload = PossibleOverflows('Books-ellipsis');
window.onload = PossibleOverflows('Books-scroll');

//window.onresize = PossibleOverflows('Books-ellipsis');
//window.onresize = PossibleOverflows('Books-scroll');
              
            
!
999px

Console