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

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>
  <h1>Responsive Table Sass Mixin</h1>
  <p>Have any number of heading columns you want, the mixin works with any number</p>
  
  <p> Use the mixin 'responive-tables' and placehold 'responive-tables' to get started</p>
  
  <p>Learn more about using this mixin <a href="http://unrealnavigation.com/blog/responsive-tables" target="_blank">on my blog</a></p>
  
<table id="rwd-table">
  <thead>
    <tr>
      <th>Heading Col 1</th>
      <th>Heading Col 2</th>
      <th>Heading Col 3</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Data Col 1a</td>
      <td>Data Col 2a</td>
      <td>Data Col 3a</td>
    </tr>
    <tr>
      <td>Data Col 1b</td>
      <td>Data Col 2b</td>
      <td>Data Col 3b</td>
    </tr>
    <tr>
      <td>Data Col 1c</td>
      <td>Data Col 2c</td>
      <td>Data Col 3c</td>
    </tr>
    <tr>
      <td>Data Col 1d</td>
      <td>Data Col 2d</td>
      <td>Data Col 3d</td>
    </tr>
    <tr>
      <td>Data Col 1e</td>
      <td>Data Col 2e</td>
      <td>Data Col 3e</td>
    </tr>
    <tr>
      <td>Data Col 1f</td>
      <td>Data Col 2f</td>
      <td>Data Col 3f</td>
    </tr>
  </tbody>
</table>
  
  <p>Use the mixin 'responive-tables-large' and placehold 'responive-tables-large' to apply the styling sooner</p>
 
<table id="rwd-table-large">
  <thead>
    <tr>
      <th>Heading Col 1</th>
      <th>Heading Col 2</th>
      <th>Heading Col 3</th>
      <th>Heading Col 4</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Data Col 1a</td>
      <td>Data Col 2a</td>
      <td>Data Col 3a</td>          
		<td>Data Col 4a</td>
    </tr>
    <tr>
      <td>Data Col 1b</td>
      <td>Data Col 2b</td>
      <td>Data Col 3b</td>
      <td>Data Col 4b</td>
    </tr>
    <tr>
      <td>Data Col 1c</td>
      <td>Data Col 2c</td>
      <td>Data Col 3c</td>
      <td>Data Col 4c</td>
    </tr>
    <tr>
      <td>Data Col 1d</td>
      <td>Data Col 2d</td>
      <td>Data Col 3d</td>
      <td>Data Col 4d</td>
    </tr>
    <tr>
      <td>Data Col 1e</td>
      <td>Data Col 2e</td>
      <td>Data Col 3e</td>
      <td>Data Col 4e</td>
    </tr>
    <tr>
      <td>Data Col 1f</td>
      <td>Data Col 2f</td>
      <td>Data Col 3f</td>
      <td>Data Col 4f Data Col 4f Data Col 4f Data Col 4f</td>
    </tr>
  </tbody>
  </table>   
</main>
              
            
!

CSS

              
                /* Include CSS Normalize */

$primary-color: #008cba;
$gray-color: #ddd;
$medium-up: 600px;
$large-up: 1000px;
$global-radius: 4px;


@mixin heading-font-regular {
	font-family: 'Helvetica', 'Helvetica Neue', 'Arial', sans-serif;;
}


//SUPER BASIC PAGE STYLING
*,*:before,*:after{
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
main {
  padding: 2em;  
  float: left;
  width: 100%;
}

a {
  color: #222;
  font-weight: bold;
  text-decoration: none;
  border-bottom: 2px solid #222;
  
  &:hover {
    color: $primary-color;
  }
}
///BASIC TABLE STYLING
table {
	border-collapse: collapse;
	width: 100%;
	float: left;
   margin: 0 0 2em;
	thead {
		border-bottom: 3px solid $primary-color;
		th {
			padding: 0.35em 0 .35em;
       font-weight: 400;
			text-align: left;
			@include heading-font-regular;
			font-size: 1.25em;
		}
		
	}

	tbody {
		border-bottom: 3px solid $primary-color;
		tr {
			border-bottom: 2px solid #ddd;
       
			td {
				padding: .75em 0;

				a {
					color: $primary-color;
					text-decoration: none;
					display: inline-block;
					margin: 0 .5em 0 0;
					&:hover, &:active, &:focus {
						color: darken($primary-color, 10%);
						border: none;
					}
				}
			}
		}
	}

	tfoot {
		td {
			padding: 0.35em 0 .35em;

			text-align: left;
			@include heading-font-regular;
			font-size: 1.25em;
		}
	}
}

@media screen and (min-width: $large-up) {
  table {
		width: 100%;

		thead {
			border-bottom: 3px solid $primary-color;
			th {
			}
			
		}

		tbody {
			tr {
				border-bottom: 1px solid #ddd;
				td {
					
				}
			}
		}
	}
}

///RWD MIXIN BELOW
@mixin rwd-first {
	display: block;
  

  tbody {
    border: none;
  }
		tbody, th, td, tr, tfoot {
			display: block; 
		}

		thead {
			display: none;
		}
		tr {
      float: left;
      width: 100%;
      margin: 0 0 1em;
       border: 1px solid $gray-color;
			box-shadow: 0px 2px 5px 0px $gray-color;
			border-radius: $global-radius;
			border-top: 5px solid $primary-color;

			td {
				padding: .5em .5em .5em 50%;
				float:left;
       		width: 100%;
				&:before {
					width: 100%;
					display: block;
					float: left;
					padding: .5em .5em .5em 0;
					clear: both;
					margin: -.5em 0 0 -100%;
					@include heading-font-regular;
					font-size: 1.125em;

				}
			}
		}

		tr:nth-of-type(even) {
			//background: $gray-color;
			td {
				
				&:before {
					
				}
			}
		}
}

@mixin rwd-second {
	display: table;
	border: none;

  tbody {
    border-bottom: 3px solid $primary-color;
  }
	th, td {
		display: table-cell; 
	}

	tr {
		display: table-row;
		border: none;
		border-bottom: 1px solid #eee;
    float: none;
    margin: 0;
		box-shadow: none;

		td {
			padding: .75em 0 0.75em .25em;
      float: none;
      width: auto;

			&:before {
				padding: 0 !important;
			}
		}
	}

	thead {
		display: table-header-group;
	}

	tbody,tfoot {
		display: table-row-group;
	}

	tr:nth-of-type(even) {
		background:none;
		td {
			
			&:before {
				
			}
		}
	}
}

%responive-tables {
	@include rwd-first;

	@media screen and (min-width: $medium-up) { 
		@include rwd-second;
		
	}
}

%responive-tables-large {
	@include rwd-first;

	@media screen and (min-width: $large-up) { 
		@include rwd-second;
		
	}
}

@mixin responive-tables($headings...) {
	$list: $headings;

	@each $list-headings in $list {
		$i: index($list, $list-headings);
		tbody tr td:nth-of-type(#{$i}):before { 
			content: $list-headings; 
		}
		
		@media screen and (min-width: $medium-up) { 
			tbody tr td:nth-of-type(#{$i}):before { 
				content: ''; 
			}
		}

	}
}

@mixin responive-tables-large($headings...) {
	$list: $headings;

	@each $list-headings in $list {
		$i: index($list, $list-headings);
		tbody tr td:nth-of-type(#{$i}):before { 
			content: $list-headings; 
		}
		
		@media screen and (min-width: $large-up) { 
			tbody tr td:nth-of-type(#{$i}):before { 
				content: ''; 
			}
		}

	}
}

#rwd-table {
	@extend %responive-tables;
	@include responive-tables('Heading Col 1', 'Heading Col 2', 'Heading Col 3');
}

#rwd-table-large {
	@extend %responive-tables-large;
	@include responive-tables-large('Heading Col 1', 'Heading Col 2', 'Heading Col 3','Heading Col 4');
}

              
            
!

JS

              
                
              
            
!
999px

Console