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.
<!--
/======== A L O V I N G L Y C R A F T E D ============================\
\ __ __ __ __ __ ______ ______ __ /
/ /\ `-.\ \ /\ \ /\ `-./ \ /\ __ \ /\ __ \ /\ \ \
\ \ \ \-. \\ \ \\ \ \-./\ \\ \ __< \ \ __ \\ \ \___ /
/ \ \_\\`\_\\ \_\\ \_\-\ \_\\ \_____\\ \_\ \_\\ \____\ _| _ _. _ _ \
\ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/ \/_/\/_/ \/____/ (_|(-_)|(_)| ) /
/================================================================ _) ===\
\============================================ http://nickbrombal.com ===/
-->
<div id="wrapper">
<h1>A Game of Dabs</h1>
<table id="card">
<tr>
<td id="cell0"></td>
<td id="cell1"></td>
<td id="cell2"></td>
<td id="cell3"></td>
<td id="cell4"></td>
</tr>
<tr>
<td id="cell5"></td>
<td id="cell6"></td>
<td id="cell7"></td>
<td id="cell8"></td>
<td id="cell9"></td>
</tr>
<tr>
<td id="cell10"></td>
<td id="cell11"></td>
<td id="cell12"></td>
<td id="cell13"></td>
<td id="cell14"></td>
</tr>
<tr>
<td id="cell15"></td>
<td id="cell16"></td>
<td id="cell17"></td>
<td id="cell18"></td>
<td id="cell19"></td>
</tr>
<tr>
<td id="cell20"></td>
<td id="cell21"></td>
<td id="cell22"></td>
<td id="cell23"></td>
<td id="cell24"></td>
</tr>
</table>
<div id="menu">
<div id="scoreboard">
<p class="title">ROWS</p>
<p class="score"><span id="scoreRow">0</span>/5</p>
<p class="title">COLUMNS</p>
<p class="score"><span id="scoreCol">0</span>/5</p>
<p class="title">DIAGONALS</p>
<p class="score"><span id="scoreDiag">0</span>/2</p>
</div>
<button class="cardFunction" id="newCard">NEW CARD</button>
<button class="cardFunction" id="cleanCard">CLEAR DABS</button>
<div id="palette">
<p>DAB COLOR</p>
<button class="dabSelect" id="dabRed"></button>
<button class="dabSelect" id="dabBlue"></button>
<button class="dabSelect" id="dabYellow"></button>
<button class="dabSelect" id="dabGreen"></button>
<button class="dabSelect" id="dabPurple"></button>
<button class="dabSelect" id="dabOrange"></button>
<button class="dabSelect" id="dabBlack"></button>
<button class="dabSelect" id="dabRandom">?</button>
</div>
</div>
<div id="credit"><a href="http://nickbrombal.com/">A Nimbal Design, 2013</a></div>
</div>
@import "compass/css3";
@import url(https://fonts.googleapis.com/css?family=Roboto:400,700);
* { margin: 0; padding: 0; border: 0; outline: 0; }
body {
background: #444444 url("http://nickbrombal.com/images/bg_pixel-grey.jpg") repeat fixed;
}
#wrapper {
margin: 0 auto;
width: 560px;
}
h1 {
margin-top: 10px;
font: 30px roboto;
text-align: center;
color: #FFF;
}
#card {
position: absolute;
margin: 0 auto;
border-spacing: 10px;
border-collapse: separate;
text-align: center;
color: #FFF;
td {
padding: 10px;
height: 80px;
width: 80px;
background: #777;
font: 14px arial;
cursor: pointer;
&:hover {
@include box-shadow(inset 0 0 35px #BBB);
@include transition-duration(.25s);
}
}
.dabbedRed { background: #FF0000; }
.dabbedBlue { background: #0000FF; }
.dabbedYellow { background: #E6E607; }
.dabbedGreen { background: #008000; }
.dabbedPurple { background: #800080; }
.dabbedOrange { background: #FFA500; }
.dabbedBlack { background: #000000; }
}
#menu {
position: relative;
left: 560px;
width: 100px;
height: 540px;
margin-top: 10px;
#scoreboard {
height: 200px;
width: 100px;
background: rgba(34,34,34,0.6);
font: 12px roboto;
text-align: center;
color: #FFF;
.title { padding-top: 9px; letter-spacing: 1px; }
.score { font-size: 30px; }
}
.cardFunction {
margin-top: 10px;
height: 45px;
width: 100px;
background: rgba(34,34,34,0.6);
font: 12px/45px roboto;
color: #FFF;
&:hover {
background: rgba(34,34,34,1);
@include transition-duration(.25s);
}
}
#palette {
margin-top: 10px;
height: 220px;
background: rgba(34,34,34,0.6);
font: 12px/28px roboto;
text-align: center;
color: white;
.dabSelect {
float: left;
border-radius: 24px;
margin: 0 0 4px 4px;
height: 44px;
width: 44px;
vertical-align: top;
&:hover { border: 3px solid #FFF; }
}
#dabRed { background: #FF0000; }
#dabBlue { background: #0000FF; }
#dabYellow { background: #E6E607; }
#dabGreen { background: #008000; }
#dabPurple { background: #800080; }
#dabOrange { background: #FFA500; }
#dabBlack { background: #000000; }
#dabRandom { background: #FFFFFF; font: 20px roboto; }
.dabActive { border: 3px solid #AAA; }
}
}
#credit {
margin-top: 10px;
width: 100%;
font: 12px roboto;
letter-spacing: 2px;
text-shadow: -1px -1px #888;
text-align: center;
a {
text-decoration: none;
color: #111;
&:hover { text-shadow: 1px 1px #888; }
}
}
$(document).ready(function() {
// Array containing all of the potential square content and their descriptions, separated by "::".
var squares = [
"Filler00::Filler content for testing purposes",
"Filler01::Filler content for testing purposes",
"Filler02::Filler content for testing purposes",
"Filler03::Filler content for testing purposes",
"Filler04::Filler content for testing purposes",
"Filler05::Filler content for testing purposes",
"Filler06::Filler content for testing purposes",
"Filler07::Filler content for testing purposes",
"Filler08::Filler content for testing purposes",
"Filler09::Filler content for testing purposes",
"Filler10::Filler content for testing purposes",
"Filler11::Filler content for testing purposes",
"Filler12::Filler content for testing purposes",
"Filler13::Filler content for testing purposes",
"Filler14::Filler content for testing purposes",
"Filler15::Filler content for testing purposes",
"Filler16::Filler content for testing purposes",
"Filler17::Filler content for testing purposes",
"Filler18::Filler content for testing purposes",
"Filler19::Filler content for testing purposes",
"Filler20::Filler content for testing purposes",
"Filler21::Filler content for testing purposes",
"Filler22::Filler content for testing purposes",
"Filler23::Filler content for testing purposes",
"Filler24::Filler content for testing purposes"
];
var randomDab = ['dabbedRed','dabbedBlue','dabbedYellow','dabbedGreen','dabbedPurple','dabbedOrange','dabbedBlack'];
var isDabbed = ['cell12'];
var bingoRow = [];
var bingoCol = [];
var bingoDiag = [];
var dabColor;
// Function to shuffle/randomize array content
function shuffle(v) {
for (var j, x, i = v.length; i; j = parseInt(Math.random() * i, 10), x = v[--i], v[i] = v[j], v[j] = x);
return v;
}
// Function to clear all dabs from the card
function cleanCard() {
$('td').removeClass();
isDabbed = [];
bingoRow = [];
bingoCol = [];
bingoDiag = [];
$('#scoreRow').html(bingoRow.length);
$('#scoreCol').html(bingoCol.length);
$('#scoreDiag').html(bingoDiag.length);
}
// Function to fill the card with randomized square entries
function fillCard() {
cleanCard();
shuffle(squares);
for ( i = 0; i < 25; i++ ) {
var squareName = squares[i].substr(0,squares[i].indexOf("::"));
var squareDesc = squares[i].substr(squares[i].indexOf("::")+2,squares[i].length);
$('#cell'+i).html(squareName).attr('title', squareDesc);
}
}
// Function to give the customary free center dab
function freeDab() {
isDabbed.push('cell12');
if ( dabColor == 'random' ) {
$('#cell12').addClass(randomDab[Math.floor(Math.random()*randomDab.length)]).html('Freebie!').attr('title', "");
} else {
$('#cell12').addClass(dabColor).html('Freebie!').attr('title', "");
}
}
// Function to check for multiple values within an array
function containsAll(needles, haystack) {
for (var i = 0 , len = needles.length; i < len; i++) {
if ($.inArray(needles[i], haystack) == -1) return false;
}
return true;
}
// Function to check for bingos (by searching the isDabbed array for the right sequences of cells) then save them to the bingo array
function bingoCheck() {
// Check rows (cells 0-4, 5-9, 10-14, 15-19, and 20-24)
for ( i = 0; i < 21; i += 5 ) {
// If all of a row's cells are in the isDabbed array, and if that row isn't already in the bingo array, add it
if (containsAll(["cell"+i,"cell"+(i+1),"cell"+(i+2),"cell"+(i+3),"cell"+(i+4)], isDabbed)) {
if ($.inArray("row"+i,bingoRow) == -1) {
bingoRow.push("row"+i);
$('#scoreRow').html(bingoRow.length);
alert("BINGO! You scored a row! Don't stop now!");
}
// If all of a row's cells are no longer in the isDabbed array, and if that row is already in the bingo array, remove it
} else {
if ($.inArray("row"+i,bingoRow) !== -1) {
bingoRow.splice( $.inArray("row"+i,bingoRow), 1 );
$('#scoreRow').html(bingoRow.length);
}
}
}
// Check columns (cells 0-20, 1-21, 2-22, 3-23, and 4-24)
for ( i = 0; i < 5; i++ ) {
// If all of a column's cells are in the isDabbed array, and if that column isn't already in the bingo array, add it
if (containsAll(["cell"+i,"cell"+(i+5),"cell"+(i+10),"cell"+(i+15),"cell"+(i+20)], isDabbed)) {
if ($.inArray("col"+i,bingoCol) == -1) {
bingoCol.push("col"+i);
$('#scoreCol').html(bingoCol.length);
alert("BINGO! You scored a column! Keep it up!");
}
// If all of a column's cells are no longer in the isDabbed array, and if that column is already in the bingo array, remove it
} else {
if ($.inArray("col"+i,bingoCol) !== -1) {
bingoCol.splice( $.inArray("col"+i,bingoCol), 1 );
$('#scoreCol').html(bingoCol.length);
}
}
}
// Check forward diagonal (cells 0, 6, 12, 18, and 24)
if (containsAll(["cell0","cell6","cell12","cell18","cell24"], isDabbed)) {
if ($.inArray("diag0",bingoDiag) == -1) {
bingoDiag.push("diag0");
$('#scoreDiag').html(bingoDiag.length);
alert("Bingo! You scored a diagonal! Nice moves!");
}
} else {
if ($.inArray("diag0",bingoDiag) !== -1) {
bingoDiag.splice( $.inArray("diag0",bingoDiag), 1 );
$('#scoreDiag').html(bingoDiag.length);
}
}
// Check backward diagonal (cells 4, 8, 12, 16, and 20)
if (containsAll(["cell4","cell8","cell12","cell16","cell20"], isDabbed)) {
if ($.inArray("diag4",bingoDiag) == -1) {
bingoDiag.push("diag4");
$('#scoreDiag').html(bingoDiag.length);
alert("BINGO! You scored a diagonal! Nice moves!");
}
} else {
if ($.inArray("diag4",bingoDiag) !== -1) {
bingoDiag.splice( $.inArray("diag4",bingoDiag), 1 );
$('#scoreDiag').html(bingoDiag.length);
}
}
// Check for a full bingo of all 12 row/column/diagonal combinations
if ((bingoRow.length == 5) && (bingoCol.length == 5) && (bingoDiag.length == 2)) {
alert("CONGRATULATIONS - you're a WINNER!");
}
}
// Function to switch the active dabbing color
function switchDab(color, id) {
dabColor = color;
$('.dabSelect').removeClass('dabActive');
$(id).addClass('dabActive');
}
// When clicking a 'td' element, (1) add/remove the 'dabbed' class, (2) add/remove its id to/from the isDabbed array, and (3) run a check for bingos
$('td').click(function() {
if ( $.inArray(this.id,isDabbed) !== -1 ) {
isDabbed.splice( $.inArray(this.id,isDabbed), 1 );
$(this).removeClass();
} else {
isDabbed.push(this.id);
if ( dabColor == 'random' ) {
$(this).addClass(randomDab[Math.floor(Math.random()*randomDab.length)]);
} else {
$(this).addClass(dabColor);
}
}
bingoCheck();
});
// Refill the card when clicking the "#newCard" button
$('#newCard').click(function() {
fillCard();
freeDab();
});
// Clear all dabs from the card when clicking the "#cleanCard" button
$('#cleanCard').click(function() {
cleanCard();
});
// Switch the dabbing color to red
$('#dabRed').click(function() {
switchDab('dabbedRed', this);
});
// Switch the dabbing color to blue
$('#dabBlue').click(function() {
switchDab('dabbedBlue', this);
});
// Switch the dabbing color to green
$('#dabYellow').click(function() {
switchDab('dabbedYellow', this);
});
// Switch the dabbing color to yellow
$('#dabGreen').click(function() {
switchDab('dabbedGreen', this);
});
// Switch the dabbing color to purple
$('#dabPurple').click(function() {
switchDab('dabbedPurple', this);
});
// Switch the dabbing color to orange
$('#dabOrange').click(function() {
switchDab('dabbedOrange', this);
});
// Switch the dabbing color to black
$('#dabBlack').click(function() {
switchDab('dabbedBlack', this);
});
// Switch the dabbing color to random
$('#dabRandom').click(function() {
switchDab('random', this);
});
// Initialize the card on page load
switchDab('dabbedRed', '#dabRed');
fillCard();
freeDab();
});
Also see: Tab Triggers