css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <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>
            
          
!
            
              /* 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');
}

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console