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.

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 Periodic Table
article.info
	h2
		a(href="#")#name
	p#summary
	ul
		li
			span.bold Discovered by:  
			span#discovered-by
		li
			span.bold Named by:
			span#name-given-by
		li
			span.bold Atomic mass:
			span#atomic-mass
		li
			span.bold Density:
			span#density
              
            
!

CSS

              
                $grid-size: 2.5rem; 
$grid-x: 18;
$grid-y: 5;

$heading: #59656F;
$metal: #C2CC8B;
$metalloid: #9CC4B2;
$nonmetal: #7CE577;
$transition: #E1B07E;
$noble: #ECDCB0;
$alkaline: #B9E28C;
$alkali: #A0CCDA;
$lanthanide: #CC8B8C;
$actinide: #F1C8DB;

* {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

body {
	margin: 0;
	padding: 4rem 2rem;
	min-height: 100vh;
	
	display: flex;
	flex-direction: column; 
	align-items: center;
	justify-content: flex-start;
	
	background: linear-gradient(to right, rgb(3, 20, 68), rgb(86, 73, 97));
	font-family: Open Sans;
}

main, .info {
	padding: 1rem;
}

main {
	display: grid;
	grid-template-columns: repeat($grid-x, 1fr);
	grid-template-rows: repeat($grid-y, 1fr);
	grid-gap: .5rem;
	
	h1 {
		height: 100%;	width: 100%;
		margin: 0;
		
		grid-row: 1 / span 2;
		grid-column: 4 / span 8;
		
		display: flex;
		justify-content: center;
		align-items: center;
		
		background: $heading;
		color: white;
		box-shadow: 0 3px 8px rgba(black, .3);
	}
	
	abbr {
		width: $grid-size;
		height: $grid-size;
		grid-row: 1;
		grid-column: 2;
		padding: .5rem;
		
		display: flex;
		justify-content: center;
		align-items: center;
		
		border: 4px solid white;
		box-shadow: 0 9px 5px -4px rgba(0, 0, 0, 0.3);
		font-weight: bold;
		transition: .1s all ease;
		cursor: default;
		background: $heading;
		color: white;
		
		&:hover, &.focus {
			transform: scale(1.25);
			box-shadow: 0 19px 15px rgba(0, 0, 0, 0.7);
		}
		
		&.metal { border-color: $metal; }
		&.metalloid {	border-color: $metalloid;	}
		&.transition { border-color: $transition;	}
		&.noble {	border-color: $noble;	}
		&.nonmetal { border-color: $nonmetal;	}
		&.alkali { border-color: $alkali;	}
		&.alkaline { border-color: $alkaline;	}
		&.lanthanide { border-color: $lanthanide;	}
		&.actinide { border-color: $actinide;	}
	}
}

.info {
	margin-top: 1rem;
	width: 18 * $grid-size + 10rem;
	height: auto;
	
	display: grid;
	grid-template-rows: 2rem auto;
	grid-template-columns: 8fr 5fr;
	grid-column-gap: 2rem;
	
	background: $heading;
	box-shadow: 0 3px 8px rgba(black, .3);
	color: white;
	font-weight: 300;
	transition: .5s height ease-in-out;
	
	p {
		grid-row: 2 / span 1;
		grid-column: 1 / span 1;
		line-height: 1.3;
	}
	
	ul {
		grid-row: 2 / span 1;
		grid-column: 2 / span 1;
		line-height: 1.3;
		list-style: none;
		
		li {
			display: flex;
			justify-content: space-between;
				
			span {
				text-align: right;
				min-width: 120px;
				
				&.bold {
					font-weight: bold;
					text-align: left;
				}
			}
		}
	}
	
	a:link,
	a:visited,
	a:hover,
	a:active {
		color: inherit;
		text-decoration: none;
	}
}
              
            
!

JS

              
                const main = document.querySelector('main')
const categories = ['metal', 'metalloid', 'nonmetal', 'noble', 'alkali', 'alkaline', 'transition', 'lanthanide', 'actinide']
let activeElement = null

loadElements().then(outputElements)

// Load the elements of the periodic table
// JSON data is provided by the Periodic Table JSON GitHub Repo
// https://github.com/Bowserinator/Periodic-Table-JSON
function loadElements () {
	return new Promise((resolve, reject) => {
		let req = new XMLHttpRequest()
		let url = 'https://tyrandus.github.io/static/periodic-table/data.json'
		req.open('GET', url)
		req.onload = function () {
			console.log(JSON.parse(req.response))
			resolve(JSON.parse(req.response).elements)
		}
		req.send()
	})
}

// Output one <abbr> per element
function outputElements (elements) {
	let abbreviations = []
	
	elements.forEach(elem => {
		let abbr = document.createElement('abbr')
		abbr.textContent = elem.symbol
		abbr.style.gridColumn = elem.xpos
		abbr.style.gridRow = elem.ypos
		
		abbr.classList.add(elem.category
			.split(/[ ,]/)
			.filter(c => {
				let ind = categories.indexOf(c)
				return ind >= 0
			})[0])
		
		abbr.addEventListener('click', () => {
			if (activeElement) activeElement.classList.remove('focus')
			abbr.classList.add('focus')
			activeElement = abbr
			showInfo(elem)
		})
		main.appendChild(abbr)
		abbreviations.push(abbr)
	})
	
	let i = Math.floor(Math.random() * abbreviations.length)
	abbreviations[i].click()
}
 
const elName = document.getElementById('name')
const elSummary = document.getElementById('summary')
const elDiscoveredBy = document.getElementById('discovered-by')
const elNameGivenBy = document.getElementById('name-given-by')
const elAtomicMass = document.getElementById('atomic-mass')
const elDensity = document.getElementById('density')

// Show detailed information regarding one element
function showInfo (element) {
	elName.textContent = element.number + ' ' + element.name
	elName.href = element.source
	
	elSummary.textContent = element.summary
	elDiscoveredBy.textContent = u(element.discovered_by)
	elNameGivenBy.textContent = u(element.named_by)
	elAtomicMass.textContent = u(element.atomic_mass) + ' u'
	elDensity.textContent = u(element.density) + ' g/L'
	
	// Replace null by "Unknown"
	function u (s) {
		return s ? s : 'Unknown'
	}
}
              
            
!
999px

Console