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>Gradients on Scolling Content Boxes</h1>
<h2>Basic Example</h2>
<div class="scrolling_container">
  <div class="scrolling_inner">
    <table class="scrolling">
      <thead>
        <tr>
          <th>Browser</th>
          <th>Percentage</th>
          <th>Created</th>
          <th>Last Updated</th>
          <th>Current Version</th>
          <th>Developer</th>
          <th>Written In</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Chrome</td>
          <td>76.9%</td>
          <td>September 2, 2008</td>
          <td>September 14, 2017</td>
          <td>61.0.3163.91</td>
          <td>Google Inc.</td>
          <td>C++</td>
        </tr>
        <tr>
          <td>FireFox</td>
          <td>13.1%</td>
          <td>September 23, 2002</td>
          <td>August 25, 2017</td>
          <td>55.0.3</td>
          <td>Mozilla Foundation</td>
          <td>C++, JavaScript, HTML, C, Rust</td>
        </tr>
        <tr>
          <td>IE/Edge</td>
          <td>4.3%</td>
          <td>August 16, 1995</td>
          <td>April 11, 2017</td>
          <td>40.15063.0.0</td>
          <td>Microsoft</td>
          <td>C++</td>
        </tr>
        <tr>
          <td>Safari</td>
          <td>3.0%</td>
          <td>January 7, 2003</td>
          <td>July 19, 2017</td>
          <td>10.3.3</td>
          <td>Apple</td>
          <td>C++, Objective-C</td>
        </tr>
        <tr>
          <td>Opera</td>
          <td>1.2%</td>
          <td>April 10, 1995</td>
          <td>August 26, 2017</td>
          <td>47.0.2631.71</td>
          <td>Opera Software</td>
          <td>C++</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>
<h2>Alternating Row Colors</h2>
<div class="scrolling_container">
  <div class="scrolling_inner">
    <table class="scrolling alternate-rows">
      <thead>
        <tr>
          <th>Browser</th>
          <th>Percentage</th>
          <th>Created</th>
          <th>Last Updated</th>
          <th>Current Version</th>
          <th>Developer</th>
          <th>Written In</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Chrome</td>
          <td>76.9%</td>
          <td>September 2, 2008</td>
          <td>September 14, 2017</td>
          <td>61.0.3163.91</td>
          <td>Google Inc.</td>
          <td>C++</td>
        </tr>
        <tr>
          <td>FireFox</td>
          <td>13.1%</td>
          <td>September 23, 2002</td>
          <td>August 25, 2017</td>
          <td>55.0.3</td>
          <td>Mozilla Foundation</td>
          <td>C++, JavaScript, HTML, C, Rust</td>
        </tr>
        <tr>
          <td>IE/Edge</td>
          <td>4.3%</td>
          <td>August 16, 1995</td>
          <td>April 11, 2017</td>
          <td>40.15063.0.0</td>
          <td>Microsoft</td>
          <td>C++</td>
        </tr>
        <tr>
          <td>Safari</td>
          <td>3.0%</td>
          <td>January 7, 2003</td>
          <td>July 19, 2017</td>
          <td>10.3.3</td>
          <td>Apple</td>
          <td>C++, Objective-C</td>
        </tr>
        <tr>
          <td>Opera</td>
          <td>1.2%</td>
          <td>April 10, 1995</td>
          <td>August 26, 2017</td>
          <td>47.0.2631.71</td>
          <td>Opera Software</td>
          <td>C++</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>
<h2>Vibrant Colors</h2>
<div class="scrolling_container">
  <div class="scrolling_inner">
    <table class="scrolling vibrant-rows">
      <thead>
        <tr>
          <th>Browser</th>
          <th>Percentage</th>
          <th>Created</th>
          <th>Last Updated</th>
          <th>Current Version</th>
          <th>Developer</th>
          <th>Written In</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Chrome</td>
          <td>76.9%</td>
          <td>September 2, 2008</td>
          <td>September 14, 2017</td>
          <td>61.0.3163.91</td>
          <td>Google Inc.</td>
          <td>C++</td>
        </tr>
        <tr>
          <td>FireFox</td>
          <td>13.1%</td>
          <td>September 23, 2002</td>
          <td>August 25, 2017</td>
          <td>55.0.3</td>
          <td>Mozilla Foundation</td>
          <td>C++, JavaScript, HTML, C, Rust</td>
        </tr>
        <tr>
          <td>IE/Edge</td>
          <td>4.3%</td>
          <td>August 16, 1995</td>
          <td>April 11, 2017</td>
          <td>40.15063.0.0</td>
          <td>Microsoft</td>
          <td>C++</td>
        </tr>
        <tr>
          <td>Safari</td>
          <td>3.0%</td>
          <td>January 7, 2003</td>
          <td>July 19, 2017</td>
          <td>10.3.3</td>
          <td>Apple</td>
          <td>C++, Objective-C</td>
        </tr>
        <tr>
          <td>Opera</td>
          <td>1.2%</td>
          <td>April 10, 1995</td>
          <td>August 26, 2017</td>
          <td>47.0.2631.71</td>
          <td>Opera Software</td>
          <td>C++</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>
<p><strong>Inspired by the Pen <a href="https://codepen.io/dbushell/pen/wGaamR" target="_blank">CSS Only Responsive Tables</a> by David Bushell</strong><br/>
I loved the idea of showing a gradient on areas where scrolling can reveal more content, but CSS alone did not offer much flexibility for changing the color of the table rows. This was critical for making a comparison table where the colors could change. A little JS experimenting and voila!</p>
              
            
!

CSS

              
                .scrolling {
  display: inline-block;
  vertical-align: top;
  max-width: 100%;
  overflow-x: auto;
  white-space: nowrap;
  border-collapse: collapse;
  border-spacing: 0;
  -webkit-overflow-scrolling: touch;
}

.scrolling th,
.scrolling td {
  border: 1px solid #c2c2c2;
  vertical-align: middle;
  padding: 10px 12px;
  text-align: left;
}

.scrolling th {
  background: #e7e7e7;
}

.scrolling_inner {
  position: relative;
}

.scrolling_inner.scroll-right::after {
  background: -webkit-radial-gradient(right ellipse, rgba(0, 0, 0, 0.2) 0%, rgba(0, 0, 0, 0) 75%) 100% center;
  background: radial-gradient(ellipse at right, rgba(0, 0, 0, 0.2) 0%, rgba(0, 0, 0, 0) 75%) 100% center;
  background-repeat: no-repeat;
  background-attachment: scroll;
  background-size: 15px 100%;
  background-position: 100% 0%;
  content: '';
  display: block;
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 15px;
  z-index: 500;
}

.scrolling_inner.scroll-left::before {
  background: -webkit-radial-gradient(left ellipse, rgba(0, 0, 0, 0.2) 0%, rgba(0, 0, 0, 0) 75%) 0 center;
  background: radial-gradient(ellipse at left, rgba(0, 0, 0, 0.2) 0%, rgba(0, 0, 0, 0) 75%) 0 center;
  background-repeat: no-repeat;
  background-attachment: scroll;
  background-size: 15px 100%;
  content: '';
  display: block;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 15px;
  z-index: 500;
}

/*
 * For DEMO Purposes
 */
html {
  font-family: sans-serif;
  font-size: 13px;
  padding: 35px;
}

div.scrolling_container {
  max-width: 500px;
}

.scrolling.alternate-rows tbody tr:nth-child(even) {
  background: #f5f5f5;
}

.scrolling.vibrant-rows thead th {
  background: #2c3446;
  color: #fff;
}

.scrolling.vibrant-rows tbody tr:nth-child(even) {
  background: #95aee0;
  color: #fff;
}

.scrolling.vibrant-rows td:nth-child(5) {
  background: #e76074;
  color: #fff;
}




              
            
!

JS

              
                $(document).ready(function(){
	// show gradient in table when scrolling occurs
	$( '.scrolling' ).on( 'scroll', function () {
		var parent_div = $(this).parent();

		if( $(this).scrollLeft() + $(this).innerWidth() >= $(this)[0].scrollWidth ) {
			if( parent_div.hasClass('scroll-right') ) { parent_div.removeClass('scroll-right'); }
		} else if( $(this).scrollLeft() === 0) {
			if( parent_div.hasClass('scroll-left') ) { parent_div.removeClass('scroll-left'); }
		} else {
			if( ! parent_div.hasClass('scroll-right') ) { parent_div.addClass('scroll-right'); }
			if( ! parent_div.hasClass('scroll-left') ) { parent_div.addClass('scroll-left'); }
		}
	});
  
  // determine if gradients are needed on page load
	scrolling_tables = document.getElementsByClassName('scrolling');
  for (var i=0; i<scrolling_tables.length; i++) {
    scrolling_div = scrolling_tables[i];
    if ( scrolling_div.offsetWidth < scrolling_div.scrollWidth ) {
      if( ! $('.scrolling_inner').hasClass('scroll-right') ) {
        $('.scrolling_inner').addClass('scroll-right');
      }
    }
  }
});

// show / hide the gradient on scrolling table
function scrolling_table_shadows() {
	be_compare_container = document.getElementById('be_compare_features_table');
	if( be_compare_container === null ) return;

	if ( be_compare_container.offsetWidth < be_compare_container.scrollWidth ) {
		if( ! $('#be_compare_features_table_inner').hasClass('scroll-right') ) { $('#be_compare_features_table_inner').addClass('scroll-right'); }
	} else {
		if( $('#be_compare_features_table_inner').hasClass('scroll-right') ) { $('#be_compare_features_table_inner').removeClass('scroll-right'); }
		if( $('#be_compare_features_table_inner').hasClass('scroll-left') ) { $('#be_compare_features_table_inner').removeClass('scroll-left'); }
	}
}

// evaluate gradients when the window is resized
$( window ).on( 'resize', function() {
  scrolling_table_shadows();
});
              
            
!
999px

Console