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 id="myTable">
<tr>
<th>Head col 1</th>
<th>Head col 2</th>
</tr>
<tr>
<td>first row col1</td>
<td>first row col2</td>
</tr>
<tr>
<td>row #2 col1</td>
<td>row #2 col2</td>
</tr>
<tr>
<td>row #3 col1</td>
<td>row #3 col2</td>
</tr>
<tr>
<td>row #4 col1</td>
<td>row #4 col2</td>
</tr>
<tr>
<td>row #5 col1</td>
<td>row #5 col2</td>
</tr>
<tr>
<td>row #6 col1</td>
<td>row #6 col2</td>
</tr>
<tr>
<td>row #7 col1</td>
<td>row #7 col2</td>
</tr>
<tr>
<td>row #8 col1</td>
<td>row #8 col2</td>
</tr>
<tr>
<td>row #9 col1</td>
<td>row #9 col2</td>
</tr>
<tr>
<td>row #10 col1</td>
<td>row #10 col2</td>
</tr>
<tr>
<td>row #11 col1</td>
<td>row #11 col2</td>
</tr>
</table>
* {
margin: 0;
padding: 0;
text-align:center;
}
body {
background-color: #fafafa;
}
table {
color: #333;
font-size: .9em;
font-weight: 300;
line-height: 40px;
border-collapse: separate;
border-spacing: 0;
border: 2px solid #ed1c40;
width: 500px;
margin: 50px auto;
box-shadow: 0 4px 8px 0 rgba(0,0,0,.16);
border-radius: 2px;
}
th {
background: #ed1c40;
color: #fff;
border: none;
}
tr:hover:not(th) {background-color: rgba(237,28,64,.1);}
input[type="button"] {
transition: all .3s;
border: 1px solid #ddd;
padding: 8px 16px;
text-decoration: none;
border-radius: 5px;
font-size: 15px;
}
input[type="button"]:not(.active) {
background-color:transparent;
}
.active {
background-color: #ff4d4d;
color :#fff;
}
input[type="button"]:hover:not(.active) {
background-color: #ddd;
}
/* =================================
** ==== Simple Table Controller ====
** =================================
**
**
** With Pure JavaScript ..
**
**
** No Libraries or Frameworks needed!
**
**
** fb.com/bastony
**
*/
// get the table element
var $table = document.getElementById("myTable"),
// number of rows per page
$n = 5,
// number of rows of the table
$rowCount = $table.rows.length,
// get the first cell's tag name (in the first row)
$firstRow = $table.rows[0].firstElementChild.tagName,
// boolean var to check if table has a head row
$hasHead = ($firstRow === "TH"),
// an array to hold each row
$tr = [],
// loop counters, to start count from rows[1] (2nd row) if the first row has a head tag
$i,$ii,$j = ($hasHead)?1:0,
// holds the first row if it has a (<TH>) & nothing if (<TD>)
$th = ($hasHead?$table.rows[(0)].outerHTML:"");
// count the number of pages
var $pageCount = Math.ceil($rowCount / $n);
// if we had one page only, then we have nothing to do ..
if ($pageCount > 1) {
// assign each row outHTML (tag name & innerHTML) to the array
for ($i = $j,$ii = 0; $i < $rowCount; $i++, $ii++)
$tr[$ii] = $table.rows[$i].outerHTML;
// create a div block to hold the buttons
$table.insertAdjacentHTML("afterend","<div id='buttons'></div");
// the first sort, default page is the first one
sort(1);
}
// ($p) is the selected page number. it will be generated when a user clicks a button
function sort($p) {
/* create ($rows) a variable to hold the group of rows
** to be displayed on the selected page,
** ($s) the start point .. the first row in each page, Do The Math
*/
var $rows = $th,$s = (($n * $p)-$n);
for ($i = $s; $i < ($s+$n) && $i < $tr.length; $i++)
$rows += $tr[$i];
// now the table has a processed group of rows ..
$table.innerHTML = $rows;
// create the pagination buttons
document.getElementById("buttons").innerHTML = pageButtons($pageCount,$p);
// CSS Stuff
document.getElementById("id"+$p).setAttribute("class","active");
}
// ($pCount) : number of pages,($cur) : current page, the selected one ..
function pageButtons($pCount,$cur) {
/* this variables will disable the "Prev" button on 1st page
and "next" button on the last one */
var $prevDis = ($cur == 1)?"disabled":"",
$nextDis = ($cur == $pCount)?"disabled":"",
/* this ($buttons) will hold every single button needed
** it will creates each button and sets the onclick attribute
** to the "sort" function with a special ($p) number..
*/
$buttons = "<input type='button' value='<< Prev' onclick='sort("+($cur - 1)+")' "+$prevDis+">";
for ($i=1; $i<=$pCount;$i++)
$buttons += "<input type='button' id='id"+$i+"'value='"+$i+"' onclick='sort("+$i+")'>";
$buttons += "<input type='button' value='Next >>' onclick='sort("+($cur + 1)+")' "+$nextDis+">";
return $buttons;
}
Also see: Tab Triggers