Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              <div class="container">
	<div class="page-header">
		<h1>Super Simple Column Resizing</h1>
	</div>
	
	<p class="lead"><b>Click &amp; drag</b> column headers to resize columns. <b>Double click</b> table head to reset column widths.</p>
	
	<table class="table table-striped table-bordered table-resizable">
	  <thead>
		 <tr>
			<th>Name</th>
			<th>Profession</th>
			<th>Address</th>
			<th>Allergies</th>
		 </tr>
	  </thead>
	  <tbody>
		 <tr>
			<td>Nitro Cowabunga</td>
			<td>Magician</td>
			<td>1600 Pennsylvania Ave, Washington DC</td>
			<td>Poison</td>
		 </tr>
		  <tr>
			<td>Bandolier Uppercuts</td>
			<td>Pokemon Trainer</td>
			<td>1 Infinite Loop, Cupertino, California</td>
			<td>NKDA</td>
		 </tr>
		  <tr>
			<td>Corgi Nyquist</td>
			<td>Sea Captain</td>
			<td>245819637.001 Popcicle Circle Apartment 54634354, Hastings, Nebraska</td>
			<td>Tigers</td>
		 </tr>
		  <tr>
			<td>Kombucha Bonzai</td>
			<td>Baby</td>
			<td>3051 Van Brunt Boulevard, Kansas City, Missouri</td>
			<td>Plutonium</td>
		 </tr>
	  </tbody>
	</table>
	
	<hr>
	
	<p>Based on <a href="http://stackoverflow.com/a/6157119">http://stackoverflow.com/a/6157119</a></p>
</div>

            
          
!

CSS

            
              .table-resizable {
	&.resizing {
		cursor: col-resize;
		user-select: none;
	}
	
	th {
		position: relative;

		// Show resize curson when hovering over column borders
		&::before {
			@extend .table-resizable.resizing;
			content: '';
			display: block;
			height: 100%;
			position: absolute;
			right: 0;
			top: 0;
			width: 1em;
		}

		&:last-of-type::before {
			display: none;
		}
	}

	// Add `th` to the selector below to allow shrinking a column all the way
	td {
		max-width: 0;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
}
            
          
!

JS

            
              $(function() {
	var startX,
		 startWidth,
		 $handle,
		 $table,
		 pressed = false;
	
	$(document).on({
		mousemove: function(event) {
			if (pressed) {
				$handle.width(startWidth + (event.pageX - startX));
			}
		},
		mouseup: function() {
			if (pressed) {
				$table.removeClass('resizing');
				pressed = false;
			}
		}
	}).on('mousedown', '.table-resizable th', function(event) {
		$handle = $(this);
		pressed = true;
		startX = event.pageX;
		startWidth = $handle.width();
		
		$table = $handle.closest('.table-resizable').addClass('resizing');
	}).on('dblclick', '.table-resizable thead', function() {
		// Reset column sizes on double click
		$(this).find('th[style]').css('width', '');
	});
});
            
          
!
999px

Console