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.
<table>
<tr>
<th></th>
<th>Lugnuts</th>
<th>Rutabegas</th>
<th>Dumptrucks</th>
<th>Saturns</th>
</tr>
<tr>
<th>
<p>Alabama</p>
</th>
<td>
16,000,000
</td>
<td>
8,000,000
</td>
<td>
4,000,000
</td>
<td>
90,000,000
</div>
</tr>
<tr>
<th>
<p>Arkansas</p>
</th>
<td>
1,000,000
</td>
<td>
100,000,000
</td>
<td>
88,000,000
</td>
<td>
9,000,000,000
</div>
</tr>
<tr>
<th>
<p>Montana</p>
</th>
<td>
44,000,000
</td>
<td>
91,000,000
</td>
<td>
43,000,000
</td>
<td>
10,000,000
</div>
</tr>
<tr>
<th>
<p>New Jersey</p>
</th>
<td>
44,000,000
</td>
<td>
16,000,000
</td>
<td>
33,000,000
</td>
<td>
80,000,000
</div>
</tr>
</table>
$max_columns: 10;
* {
box-sizing: border-box;
}
table {
width: 100%;
}
tr {
width: 100%;
display: block;
clear: both;
}
tr > * {
float: left;
height: 50px;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
position: relative;
border: solid black 1px;
border-collapse: collapse;
p {
width: 100%;
display: flex;
justify-content: center;
margin: 0;
&.value {
display: none;
}
&.item {
display: none;
}
}
@for $i from 1 to $max_columns {
@include exactly($i) {
$column-count: $i;
width: calc(100% / #{$column-count});
}
}
}
th {
font-weight: bold;
cursor: auto;
}
@media screen and (max-width: 720px) {
table {
display: flex;
flex-wrap: wrap;
}
tr:first-child{
display: none;
}
tr:not(:first-child) {
> * {
@for $i from 1 to $max_columns {
@include exactly($i) {
$column-count: $i;
width: calc(100% / calc( 1 + calc(#{$column-count} / 2)));
@if ($i%2!=0) {
width: calc(100% / calc( 1 + calc(calc(#{$column-count} - 1) / 2)));
}
}
}
&:nth-child(1) {
height: 100px;
}
p {
&.item, &.value {
display: flex;
justify-content: center;
}
}
}
td {
&:hover {
cursor: pointer;
background: rgb(115,115,115);
color: white;
}
&.selected {
background: rgb(175, 175, 175);
color: white;
cursor: auto;
&:hover {
background: rgb(175, 175, 175);
cursor: auto;
}
}
}
}
}
$(document).ready(function(){
// We want this to work for every table on the page
$('table').each(function(){
const table = $(this);
// Get all of the table headings
const topCells = table.find('tr:first-child th');
// Get the bottom rows
const bottomRows = table.find('tr:not(:first-child)');
// We need to insert a label in each cell of a column, so we start from the heading
topCells.each(function(index){
// We don't care about the top-left cell—it doesn't label the cells beneath it
if (index != 0) {
const headerCell = $(this)
const headerIndex = index;
// Get the item name from the cell
const itemName = headerCell.text();
// Set the cell's data-item to the item name (useful later)
$(this).data('item', itemName);
// Now we need to label the appropriate cell on each line
bottomRows.each(function(index){
// Find the right cell (the index is one lower because of the <th> at the start)
const cell = $($(this).find('td')[headerIndex - 1]);
// Set that cell's data-item to the same item name
cell.data('item', itemName);
// Create an HTML element with the item name
const itemEntry = `<p class="item">${itemName}</p>`
// Append it to the cell (we hide it with CSS)
cell.append(itemEntry);
});
}
})
// Find the heading of each row
const rowHeads = bottomRows.find('th');
rowHeads.each(function(){
// Add an empty <p> that we'll populate later
$(this).append('<p class="value"></p>');
});
})
// Event handler for clicking on cells
$('td').click(function(){
// Unselect everything
$('td').removeClass('selected');
// Select this cell
$(this).addClass('selected');
// Find the item this cell represents
const itemName = $(this).data('item');
// Find the cell's parent table
const table = $(this).closest('table');
// Find that table's bottom rows
const bottomRows = table.find('tr:not(:first-child)');
bottomRows.each(function(){
const row = $(this);
// Find all the cells in the row
const itemCells = row.find('td');
itemCells.each(function(){
// Find the cell in question's item
const thisItem = $(this).data('item');
// If it's the same as the item we clicked
if (thisItem == itemName) {
// Select it
$(this).addClass('selected');
// Set the row's value label to that amount
const thisValue = $(this).text();
row.find('.value').text(thisValue);
}
});
});
});
});
Also see: Tab Triggers