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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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.
.letter-grid
@import "compass/css3";
.letter-grid {
height: 100%;
left: 0;
overflow: hidden;
position: absolute;
text-align: center;
top: 0;
width: 100%;
z-index: -1;
span {
background-color: transparent;
color: rgba(0,0,0,.25);
display: block;
float: left;
font-size: 10px;
opacity: 0;
padding: 10px;
text-transform: uppercase;
transition: background-color .75s, color .75s, opacity .75s, transform .5s;
user-select: none;
visibility: hidden;
width: 10px;
height: 10px;
&:hover {
background-color: orange;
color: white;
cursor: default;
}
&:nth-child(5n+1) {
color: orange;
font-weight: bold;
transform: rotate(45deg);
}
&:nth-child(10n+1) {
transform: rotate(-45deg);
}
&:nth-child(5n+1){
&:hover {
color: white;
}
}
}
}
.js-show-letters span{
opacity: 1;
visibility: visible;
}
(function(){
// setup
var grid = document.querySelector('.letter-grid');
var gridWidth;
var gridHeight;
var letterWidth = 30; // @todo: make this dynamic
var letterHeight = 30; // @todo: make this dynamic
var totalLetters;
var letterArray = [];
var currentLetters = 0;
var resizeCount = 0;
// the unicode values that we want to loop through (A-Z)
// http://www.codingforums.com/showpost.php?s=ca38992f8716f43d325c12be6fc0198b&p=843844&postcount=3
var charCodeRange = {
start: 65,
end: 90
};
// get the grid's width and height
function getDimensions(){
var gridRect = grid.getBoundingClientRect();
gridWidth = gridRect.width;
gridHeight = gridRect.height;
console.log('Grid width: '+gridWidth, '\nGrid height: '+gridHeight);
}
// get the total possible letters needed to fill the grid
// and store that in totalLetters
function getTotalLetters(){
var multiplierX = gridWidth / letterWidth;
var multiplierY = gridHeight / letterHeight;
totalLetters = Math.round((multiplierX * multiplierY));
console.log('multiplierX: '+multiplierX, '\nmultiplierY: '+multiplierY, '\ntotalLetters: '+totalLetters);
}
// loop through the unicode values and push each character into letterArray
function populateLetters() {
for (var i = charCodeRange.start; i <= charCodeRange.end; i++) {
letterArray.push(String.fromCharCode(i));
}
console.log('letterArray: '+letterArray, '\nletterArray.length: '+letterArray.length);
}
// a function to loop a given number of times (value), each time
// appending a letter from the letter array to the grid
function drawLetters(value){
var text;
var span;
var count = 0;
for (var letter=0; letter <= value; letter++) {
text = document.createTextNode(letterArray[count]);
span = document.createElement('span');
span.appendChild(text);
grid.appendChild(span);
count++;
// if our count equals the length of our letter array, then that
// means we've reached the end of the array (Z), so we set count to
// zero again in order to start from the beginning of the array (A).
// we keep looping over the letter array 'value' number of times.
if (count === letterArray.length) {
count = 0;
}
// if our for counter var (letter) equals the passed in value argument
// then we've finished our loop and we throw a class onto the grid element
if (letter === value) {
grid.classList.add('js-show-letters');
}
}
}
// get the length of the grid.find('span') jQuery object
// essentially the current number of letters in the grid at this point
function getCurrentLetters(){
currentLetters = grid.querySelectorAll('span').length;
console.log('currentLetters: '+currentLetters);
}
function init() {
populateLetters();
getDimensions();
getTotalLetters();
drawLetters(totalLetters);
getCurrentLetters();
}
function onResize() {
console.log('\nresizeCount: '+resizeCount+'\n');
resizeCount++;
getDimensions();
getTotalLetters();
// here we're looking to see if the current number of letters in the grid
// (currentLetters) is less than the total possible letters
// if so, we figure out how many need to be added to fill it up, then draw them
if (currentLetters < totalLetters) {
var difference = totalLetters - currentLetters;
drawLetters(difference);
}
// update currentLetters with the current number of letters in the grid
getCurrentLetters();
}
init();
// do everything we've done so far, except on window resize using debounce to
// ensure that resize isn't going nuts firing all this code constantly
window.addEventListener('resize', _.debounce(onResize, 100));
})();
Also see: Tab Triggers