HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
figure
.figure-content
.element-info
.initials
span.text-color [
span Kr
span.text-color ]
.name Kripton
sup.text-fade 36
.latin.text-fade Krypton
#Atom
.nucleus
.electrospheres
script.
window.addEventListener('load', () => {
kripton = new Atom(36)
function renderElectronicLayers(selector, atom)
{
const element = document.querySelector(selector)
const html = document.createElement('div')
for(const index in atom.electronicDiagram)
{
const layer = atom.electronicDiagram[index]
const layerLength = atom.shells[index]
const electrosphere = document.createElement('div')
electrosphere.classList.add('electrosphere', `layer-${index}`)
if(layerLength)
electrosphere.style.setProperty('--length', layerLength)
else
electrosphere.classList.add('empty-layer')
for(let i = 0; i < layerLength; i++)
{
const electron = document.createElement('div')
electron.classList.add('electron')
electron.style.setProperty('--index', i)
electrosphere.appendChild(electron)
}
html.appendChild(electrosphere)
}
element.innerHTML = html.innerHTML
}
renderElectronicLayers("#Atom .electrospheres", kripton)
})
.figure-content
overflow: hidden
background-color: #212121
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='49' viewBox='0 0 28 49'%3E%3Cg fill-rule='evenodd'%3E%3Cg fill='%23242424' fill-rule='nonzero'%3E%3Cpath d='M13.99 9.25l13 7.5v15l-13 7.5L1 31.75v-15l12.99-7.5zM3 17.9v12.7l10.99 6.34 11-6.35V17.9l-11-6.34L3 17.9zM0 15l12.98-7.5V0h-2v6.35L0 12.69v2.3zm0 18.5L12.98 41v8h-2v-6.85L0 35.81v-2.3zM15 0v7.5L27.99 15H28v-2.31h-.01L17 6.35V0h-2zm0 49v-8l12.99-7.5H28v2.31h-.01L17 42.15V49h-2z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E")
.element-info
position: absolute
margin: 15px 0 0 20px
color: #FFF
font-size: 24px
.text-color
color: #09F
.text-fade
color: #9E9E9E
.initials
font-size: 2em
font-weight: bold
.name
margin-top: 5px
font-size: 1em
.latin
font-size: .8em
font-style: italic
#Atom
width: 300px
height: 300px
margin: 25px 0 0 200px
display: flex
justify-content: center
align-items: center
.electrospheres
width: 300px
height: 300px
display: flex
justify-content: center
align-items: center
.electrosphere
border: 2px solid #757575
border-radius: 50%
animation: 60s infinite linear
&:nth-child(odd)
animation-name: rotateA
&:nth-child(even)
animation-name: rotateB
@keyframes rotateA
from
transform: rotate(360deg)
@keyframes rotateB
from
transform: rotate(-360deg)
@for $i from 0 through 6
&.layer-#{$i}
width: 90px + 35px * $i
height: 90px + 35px * $i
position: absolute
&.empty-layer
opacity: 1.9 - .3 * $i
.electron
width: calc(100% + 2px)
height: calc(100% + 2px)
margin: -1px
position: absolute
text-align: center
transform: rotate(calc(360deg * var(--index) / var(--length)))
&::after
content: ''
width: 10px
height: 10px
margin: -8px
border-radius: 50%
border: 3px solid #212121
background-color: #09F
position: absolute
.nucleus
width: 40px
height: 40px
background-color: #09F
border-radius: 50%
box-shadow: 0 0 100px 50px #242424
position: absolute
// Page layout 📰
body
height: 100vh
background: #111
// font-family: 'Roboto', sans-serif
overflow: hidden
display: flex
flex-direction: column
justify-content: center
align-items: center
.figure-content
width: 600px
height: 350px
border: 1px solid #222
border-radius: 2px
user-select: none
cursor: default
class Atom
{
constructor (atomic)
{
this.atomic = atomic
this.buildElectronicDiagram()
this.distributeElectrons()
}
// Creates a non-linear 2D array as the Aufbau principle
// to later distribute the values over the structure.
// This generates an array with the following aspect:
// S P D F
// 1(K) - [0] : : :
// 2(L) - [0, 0] : :
// 3(M) - [0, 0, 0] :
// 4(N) - [0, 0, 0, 0]
// 5(O) - [0, 0, 0, 0]
// 6(P) - [0, 0, 0] :
// 7(Q) - [0, 0] : :
buildElectronicDiagram ()
{
// Definition of the matrix with 7 lines,
// followed by an compreension loop that will
// define the number of columns of each line.
this.electronicDiagram = new Array(7)
.fill()
.map((_, x) =>
{
// Variable that determines the number of columns of each row.
// f(x) = 4.5 -|x - 3.5|
// (0 <= x <= 6) {1, 2, 3, 4, 4, 3, 2}
const length = 4.5 - Math.abs(x - 3.5)
return new Array(length).fill(0)
})
}
distributeElectrons ()
{
// Variable that records the count of electrons.
let electrons = this.atomic
// Variables that selects the row(layer) and column(sublevel)
// from the starting point of each step.
let layer = 0
let sublevel = 0
// Loop that performs the distribution process
// until all electrons have been distributed.
while(electrons > 0)
{
// Variables that select the row(x) and column(y) of the array.
let x = layer
let y = sublevel
// Loop that shifts the iteration pointer from the array,
// from the starting point and moving to the previous column
// of the next line, as a diagonal move, until you reach column 0 or line 6.
for(; y >= 0 && x <= 6; x++, y--)
{
// Variable that defines a limit of electrons
// that can be iterated in certain point of the matrix,
// influenced by the pointed column(y)...
// f(x) = 4x + 2
// (0 <= x <= 3) {2, 6, 10, 14}
const maxDecay = 2 + 4 * y
// If the number of electrons is lower than the column boundary,
// the decay will be the total number of electrons.
const decay = Math.min(electrons, maxDecay)
this.electronicDiagram[x][y] = decay
electrons -= decay
}
// It makes the offset of the starting point alternating in each step
// between moving to the next line and moving to the next column.
if(layer === sublevel) layer++
else sublevel++
}
}
// Returns the total number of electrons disposed in each layer.
get shells ()
{
const result = []
this.electronicDiagram.forEach((layer) =>
{
const total = layer.reduce((a, b) => a + b)
result.push(total)
})
return result
}
}
Also see: Tab Triggers