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

              
                <div class="content">

	<h1>Javascript-Based Column Widths Test Cases</h1>

	<div class="table js">
		<ul class="header">
			<li class="col-1">Space</li>
			<li class="col-2">Size</li>
			<li class="col-3">Term</li>
			<li class="col-4">Rate</li>
			<li class="col-5">Space Use</li>
			<li class="col-6">Condition</li>
			<li class="col-7">Available</li>
		</ul>
		<ul>
			<li class="col-1">1st Floor - Ste 160</li>
			<li class="col-2">6,063sf</li>
			<li class="col-3">3&ndash;<wbr>5 Years</li>
			<li class="col-4">$42.00/sf/yr</li>
			<li class="col-5">Office</li>
			<li class="col-6">N/A</li>
			<li class="col-7">Now <a href="#" class="details"><b>Details</b></a></li>
		</ul>
		<ul>
			<li class="col-1">1st Floor - Ste 190</li>
			<li class="col-2">13,299sf</li>
			<li class="col-3">3&ndash;<wbr>5 Years</li>
			<li class="col-4">$42.00/sf/yr</li>
			<li class="col-5">Office</li>
			<li class="col-6">Partial Build-Out</li>
			<li class="col-7">60 Days <a href="#" class="details"><b>Details</b></a></li>
		</ul>
		<ul>
			<li class="col-1">2nd Floor - Ste 260</li>
			<li class="col-2">23,509sf</li>
			<li class="col-3">3&ndash;<wbr>5 Years</li>
			<li class="col-4">$42.00/sf/yr</li>
			<li class="col-5">Office</li>
			<li class="col-6">Partial Build-Out</li>
			<li class="col-7">Now <a href="#" class="details"><b>Details</b></a></li>
		</ul>
	</div>

	<div class="table js">
		<ul class="header">
			<li class="col-1">Space</li>
			<li class="col-2">Size</li>
			<li class="col-3">Term</li>
			<li class="col-4">Rate</li>
			<li class="col-5">Space Use</li>
			<li class="col-6">Condition</li>
			<li class="col-7">Available</li>
		</ul>
		<ul>
			<li class="col-1">1st Floor</li>
			<li class="col-2">4,000sf</li>
			<li class="col-3">Negotiable</li>
			<li class="col-4">Upon Request</li>
			<li class="col-5">Office</li>
			<li class="col-6">N/A</li>
			<li class="col-7">30 Days <a href="#" class="details"><b>Details</b></a></li>
		</ul>
		<ul>
			<li class="col-1">2nd Floor</li>
			<li class="col-2">50&ndash;<wbr>8,000sf</li>
			<li class="col-3">Negotiable</li>
			<li class="col-4">Upon Request</li>
			<li class="col-5">Office</li>
			<li class="col-6">Partial Build-Out</li>
			<li class="col-7">30 Days <a href="#" class="details"><b>Details</b></a></li>
		</ul>
		<ul>
			<li class="col-1">3rd Floor</li>
			<li class="col-2">2,400&ndash;<wbr>8,000sf</li>
			<li class="col-3">Negotiable</li>
			<li class="col-4">Upon Request</li>
			<li class="col-5">Office</li>
			<li class="col-6">Partial Build-Out</li>
			<li class="col-7">30 Days <a href="#" class="details"><b>Details</b></a></li>
		</ul>
	</div>

	<div class="table js">
		<ul class="header">
			<li class="col-1">Space</li>
			<li class="col-2">Size</li>
			<li class="col-3">Term</li>
			<li class="col-4">Rate</li>
			<li class="col-5">Space Use</li>
			<li class="col-6">Condition</li>
			<li class="col-7">Available</li>
		</ul>
		<ul>
			<li class="col-1">2nd Floor - Ste 209</li>
			<li class="col-2">200&ndash;<wbr>500sf</li>
			<li class="col-3">Negotiable</li>
			<li class="col-4">$36.00&ndash;<wbr>$48.00/sf/yr</li>
			<li class="col-5">Office</li>
			<li class="col-6">N/A</li>
			<li class="col-7">Now <a href="#" class="details"><b>Details</b></a></li>
		</ul>
		<ul>
			<li class="col-1">2nd Floor - Ste 205</li>
			<li class="col-2">200&ndash;<wbr>1,000sf</li>
			<li class="col-3">Negotiable</li>
			<li class="col-4">$36.00&ndash;<wbr>$48.00/sf/yr</li>
			<li class="col-5">Office</li>
			<li class="col-6">N/A</li>
			<li class="col-7">Now <a href="#" class="details"><b>Details</b></a></li>
		</ul>
		<ul>
			<li class="col-1">2nd Floor - Ste 228</li>
			<li class="col-2">200&ndash;<wbr>1,200sf</li>
			<li class="col-3">Negotiable</li>
			<li class="col-4">$36.00&ndash;<wbr>$48.00/sf/yr</li>
			<li class="col-5">Office</li>
			<li class="col-6">N/A</li>
			<li class="col-7">TBD <a href="#" class="details"><b>Details</b></a></li>
		</ul>
	</div>

	<div class="table js">
		<ul class="header">
			<li class="col-1">Space</li>
			<li class="col-2">Size</li>
			<li class="col-3">Term</li>
			<li class="col-4">Rate</li>
			<li class="col-5">Space Use</li>
			<li class="col-6">Condition</li>
			<li class="col-7">Available</li>
		</ul>
		<ul>
			<li class="col-1">2nd Floor - Ste 209</li>
			<li class="col-2">200&ndash;<wbr>500sf</li>
			<li class="col-3">Negotiable</li>
			<li class="col-4">$36.00&ndash;<wbr>$48.00/sf/yr</li>
			<li class="col-5">Office/<wbr>Retail</li>
			<li class="col-6">Partial Build-Out</li>
			<li class="col-7">Now <a href="#" class="details"><b>Details</b></a></li>
		</ul>
		<ul>
			<li class="col-1">2nd Floor - Ste 205</li>
			<li class="col-2">200&ndash;<wbr>1,000sf</li>
			<li class="col-3">Negotiable</li>
			<li class="col-4">$36.00&ndash;<wbr>$48.00/sf/yr</li>
			<li class="col-5">Office</li>
			<li class="col-6">N/A</li>
			<li class="col-7">30 Days <a href="#" class="details"><b>Details</b></a></li>
		</ul>
		<ul>
			<li class="col-1">2nd Floor - Ste 211</li>
			<li class="col-2">200&ndash;<wbr>1,000sf</li>
			<li class="col-3">Negotiable</li>
			<li class="col-4">$36.00&ndash;<wbr>$48.00/sf/yr</li>
			<li class="col-5">Office</li>
			<li class="col-6">N/A</li>
			<li class="col-7">30 Days <a href="#" class="details"><b>Details</b></a></li>
		</ul>
	</div>
	
</div>
              
            
!

CSS

              
                html {
  box-sizing: border-box;
}
*, *:before, *:after {
  box-sizing: inherit;
}

body {
	font: 18px "Helvetica Neue", sans-serif;
	margin: 0;
	padding: 48px;
}

a {
	color: #0559b3;
	text-decoration: none;
}

.content {
	margin: 0 auto;
	max-width: 1280px;
}

h1 {
	font-size: 18px;
	margin: 0 0 48px;
	padding: 0;
}

.table {
	margin: 0 0 48px;
	width: 100%;
	min-width: 800px;
}

.table.css {
	display: table;
}

.table ul {
	align-items: center;
	border-bottom: 1px solid #ddd;
	clear: both;
	display: flex;
	justify-content: space-between;
	list-style: none;
	margin: 0;
	padding: 0;
}

.table.css ul {
	display: table-row;
}

.table li {
	margin: 0;
	padding: 12px 16px 12px 0;
}

.table li:first-child {
	padding-left: 16px;
}

.table li:last-child {
	padding-right: 32px;
}

.js.table ul {
	border-right: 1px solid #ddd;
	border-left: 1px solid #ddd;
}

.js.table ul:last-child {
	border-bottom-right-radius: 4px;
	border-bottom-left-radius: 4px;
}

.js.table ul.header {
	border-right: 1px solid #666;
	border-left: 1px solid #666;
	border-top-right-radius: 4px;
	border-top-left-radius: 4px;
}

.table ul.header {
	background: #666;
	border-bottom: none;
}

.table ul.header li {
	color: #fff;
	text-transform: uppercase;
}

.table.css li {
	border-bottom: 1px solid #ddd;
	display: table-cell;
	float: none;
	width: auto;
}

.details {
	display: inline-block;
	float: right;
	margin-left: 16px;
	position: relative;
}
.details:hover {
	background: #E0EFFF;
	border-radius: 4px;
	padding: 6px 26px 6px 6px;
	margin: -6px -26px -6px -6px;
}
.details:after {
	content: "";
	position: absolute;
	width: 8px;
	height: 8px;
	border-top: 2px solid #0559b3;
	border-right: 2px solid #0559b3;
	transform: rotate(135deg);
	top: 6px;
	right: -16px;
}
.details:hover:after {
	right: 10px;
	top: 12px;
}
.details b {
	font-weight: 500;
}

.details-content {
	border: 1px solid #ddd;
	padding: 12px 16px;
}
.details-content p {
	margin: 0 0 12px;
	padding: 0;
}

@media (max-width: 1280px) {
	body {
		font-size: 16px;
	}
	.details {
		width: 16px;
	}
	.details:after {
		top: 4px;
	}
	.details:hover:after {
		top: 10px;
	}
	.details:hover {
		padding: 6px 24px 6px 4px;
		margin: -6px -26px -6px -6px;
	}
	.details b {
		visibility: hidden;
	}
}

@media (max-width: 1024px) {
	body {
		font-size: 14px;
	}
}
              
            
!

JS

              
                // To-do
// Set threshold for long strings?
// Re-run when breakpoints are triggered


// Function to count pixel widths of text

$.fn.textWidth = function (text, font, transform) {
    if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('<span>').hide().appendTo(document.body);
    $.fn.textWidth.fakeEl.text(text || this.val() || this.text())
        .css('font', font || this.css('font'))
        .css('text-transform', transform || this.css('text-transform'));
    return $.fn.textWidth.fakeEl.width();
};


// Loop through tables to get max content widths and  then set column widths

$(".js").each(function() {

	cols = $("ul:first-child li").length;

	maxCountTotal = 0;

	// Make a pass to get the max count total
	for (i=1; i <=cols; i++) {

		maxCount = 0;

		$("ul", this).each(function(j) {

			row = j+1;

			pxCount = $("li:nth-child(" + i + ")", this).textWidth();
			paddingRightCount = parseFloat($("li:nth-child(" + i + ")", this).css("padding-right"));
			paddingLeftCount = parseFloat($("li:nth-child(" + i + ")", this).css("padding-left"));
			paddingCount = paddingRightCount+paddingLeftCount;
			pxCount = pxCount + paddingCount;

			if(pxCount>maxCount) {
				maxCount = pxCount;
			}

		});

		maxCountTotal = maxCountTotal+maxCount;

	}


	// Make another pass to set the column widths
	for (i=1; i <=cols; i++) {

		maxCount = 0;

		$("ul", this).each(function(j) {

			row = j+1;

			pxCount = $("li:nth-child(" + i + ")", this).textWidth();
			paddingRightCount = parseFloat($("li:nth-child(" + i + ")", this).css("padding-right"));
			paddingLeftCount = parseFloat($("li:nth-child(" + i + ")", this).css("padding-left"));
			paddingCount = paddingRightCount+paddingLeftCount;
			pxCount = pxCount + paddingCount;

			if(pxCount>maxCount) {
				maxCount = pxCount;
			}

		});

		maxCountPercent = (maxCount/maxCountTotal)*100;

		$("ul li:nth-child(" + i + ")", this).css("width", maxCountPercent + "%");

	}
	
});
              
            
!
999px

Console