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.
<main>
<section id="home">
<h2>CLI - Command Line Interface Simulation</h2>
<p>A fun experiment for displaying simple info in a geeky manner.</p>
<p><span>Type 'help' + <kbd>Enter</kbd> -- for available commands.</span></p>
</section>
<section id="about">
<h2><span>»About</span></h2>
<p>This is an experiment built by <a href="http://syndicatefx.com" target="_blank">Paulo Nunes</a> for showcasing a user profile or cv in an unusual but original way by simulating a command line interface. It's nothing more than the usual hidden elements triggered by some JS to show/hide each section of content, based on input values.</p>
</section>
<section id="usage">
<h2><span>»Usage</span></h2>
<p>Using it is pretty straight forward. Create several(as much as you need) divs or «section» elements each with it's unique id to hold your content. Make sure to have an error section (id="error") with some information to warn the user when he/she mistypes a command or if there is no section with that name, think of it as a 404 page.</p>
<p>A section with id="help" is also required so you can list all the available sections and let your users know what words to write to access that particular content.</p>
<p>The input field must be a standalone element and must not be placed inside any of the content divs or sections, and make sure you give it a classname "command", if you want to name it anything else you need to edit the app.js and change all instances of .command in the script to match your chosen classname.</p>
<p>In short, just view the source code of this demo, copy/modify it to your liking making sure you include the error and help sections.</p>
</section>
<section id="download">
<h2><span>»Download</span></h2>
<p>Download/fork the source code: <a href="https://github.com/syndicatefx/cli">Github</a><br>
License: MIT</p>
</section>
<section id="error">
<p>Command not found!<p>
<p><span>Type 'help' + <kbd>Enter</kbd> -- for available commands.</span></p>
</section>
<section id="help">
<h2><span>»Help?</span></h2>
<p><span>Type [command] + <kbd>Enter</kbd></span></p>
<ul>
<li>'home' -- Thats obvious!</li>
<li>'about' -- What's this for</li>
<li>'usage' -- How to</li>
<li>'download' -- Download + license</li>
<li>'help' -- displays this list</li>
</ul>
</section>
<span class="command">syndicatefx:/$<input type="text"></span>
</main>
@import url(https://fonts.googleapis.com/css?family=Inconsolata:400,700);
html {
background: #fff;
overflow-y: scroll;
}
body {
font: .875em/1.6 'Inconsolata', monospace;
color: #181818;
font-weight: 400;
max-width: 28em;
padding: 1em;
margin: 5% 0;
}
::selection{
background: #eee
}
::-webkit-selection{
background: #eee
}
::-moz-selection{
background: #eee
}
a{
color: #181818;
}
a:hover,a:focus{
background: #181818;
color:#fff;
}
h2{
font-size: 1em;
font-weight: 400;
}
p{
margin-bottom:2em;
}
abbr{
cursor: help;
}
ul{
list-style: none;
padding: 0;
}
li{
margin:1em 0 0;
}
span{
display: block;
color:#999;
line-height:1;
}
kbd{
font-family: 'Inconsolata', monospace;
border:1px solid #999;
text-transform: uppercase;
padding:0 .2em;
}
input[type="text"]{
max-width: 10em;
border: none;
font-family: inherit;
background: #fff;
padding:0 .5em;
}
input[type="text"]:focus{
background: #fff;
color: #000;
outline:none;
}
.command{
display: none;
max-width: 20em;
color: #181818;
font-weight: 700;
margin: 2em 0;
}
section{
display: none;
}
.open{
display: block;
}
/*!
* CLI
* Simulating a command line interface with vanilla JS
*
* @version : 1.2.0
* @author : Paulo Nunes (http://syndicatefx.com)
* @demo : https://codepen.io/syndicatefx/pen/jPxXpz
* @license: MIT
*/
/*
Modified/adapted from the original script by:
https://github.com/ckm100/typeWriter.js
*/
document.addEventListener("DOMContentLoad", typeWriter, false);
var typeWriter = function (selector, type, interval) {
var el = document.querySelectorAll(selector), // Getting elements in the DOM
i = 0,
len = el.length, // Length of element on the page
list = [], // List of elements on the page in the DOM
a,
all,
text,
start,
end,
nextText,
sectionId = selector.replace(/^#/, ''),
targetSection = document.getElementById(sectionId),
sections = document.getElementsByTagName("section")[0],
targetSiblings = [].slice.call(sections.parentNode.children).filter(function(v) { return v !== targetSection }),
cmd = document.querySelector(".command"),
clear;
for (; i < len; i++) {
list.push(el[i]); // Pushing the element in the list array
}
for (a in list) {
all = list[a]; // List of all element
text = all.innerHTML; // InnerHTML of the elements
start = 0; // Start index of the text in the elements
end = 0; // End index of the text in the elements
//Setting the default interval to 100 when interval is not set by the user
if (typeof interval === "undefined") {
interval = 100;
}
if (arguments[1] === "true") {
setTimeout(function() {
targetSection.classList.add("open");
}, 200);
for(var i = 0;i < targetSiblings.length;i++) {
targetSiblings[i].classList.remove("open");
}
clear = setInterval(function () { // Animation start
var newText = text.substr(start, end);
all.innerHTML = newText;
end = end + 1; //loops through the text in the element
if (newText === text) {
clearInterval(clear); // Animation end
cmd.classList.add("open");
input.focus();
}
}, interval);
}
return all;
}
}
var input = document.querySelector("input"),
block = document.getElementsByTagName("section");
window.onload = function() {
typeWriter("#home","true",10);
var sectionArray = [];
for(var i = 0;i < block.length;i++) {
sectionArray.push(block[i].id);
}
//console.log(sectionArray);
input.addEventListener('keyup', function(e) {
if((e.keyCode || e.which) == 13) {// ENTER key pressed
var targetValue = input.value;
var destination = "#" + targetValue;
typeWriter(destination,"true",10);
input.value = "";
if(sectionArray.includes(targetValue) == false) {
typeWriter("#error","true",10);
}
}
});
};
Also see: Tab Triggers