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.
<p class="note">This CodePen is copy/pasted compiled code for demo purposes - see the real repo <a href="https://github.com/laras126/myers-briggs">on Github</a>.</p>
<section id="js-app" class="app">
<header class="app-header">
<h1 class="app-title">Myers Briggs for Web People</h1>
<p class="app-tagline">a.k.a. The Unicorn Test</p>
</header>
<div class="question">
<p class="question-text" id="js-question"></p>
<p class="caption question-type" id="js-question-type"></p>
</div>
<div class="answers-container">
<ul class="answers-list" id="js-answers">
<li class="answer" data-score="0">0 <span class="caption answer-caption -first">Don't know/Disagree</span></li>
<li class="answer" data-score="1">1</li>
<li class="answer" data-score="2">2</li>
<li class="answer" data-score="3">3</li>
<li class="answer" data-score="4">4 <span class="caption answer-caption -last">Know well/Strongly agree</span></li>
</ul>
</div>
<div class="bar-container" id="js-bar-container">
<div class="bar" id="bar-template">
<div class="bar-title caption"></div>
<span class="bar-value"></span>
</div>
</div>
</section>
// This is compiled code!
.note {
text-align: center;
background: lemonchiffon;
margin: 0;
padding: 0.8rem;
font-size: 0.8rem;
}
.note a {
font-weight: bold;
color: indianred;
}
.caption {
position: absolute;
top: -1rem;
font-size: 0.75rem;
}
.answers-container {
width: 90%;
max-width: 20rem;
margin: 2rem auto;
}
.answers-list {
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
width: 100%;
position: relative;
padding-left: 0;
}
.answer {
cursor: pointer;
padding: 1rem 2rem;
margin-bottom: 0.2rem;
background-color: paleturquoise;
list-style-type: none;
border: 1px solid paleturquoise;
}
.answer:hover {
border-color: lightslategray;
background-color: lemonchiffon;
}
.answer-caption.-first {
left: -3rem;
}
.answer-caption.-last {
right: -1.4rem;
}
#bar-template {
display: none;
}
.bar-container {
padding-top: 1rem;
width: 80%;
margin: auto;
}
.bar {
margin-top: 2rem;
text-align: left;
position: relative;
background-color: #EEE;
height: 2rem;
}
.bar-title {
display: inline-block;
}
.bar-value {
height: 100%;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: end;
-ms-flex-pack: end;
justify-content: flex-end;
width: 15px;
padding-right: 3px;
}
#backValue {
background-color: lightslategray;
}
#designValue {
background-color: peachpuff;
}
#jsValue {
background-color: lightblue;
}
#frontValue {
background-color: lemonchiffon;
}
/* * {
box-sizing: border-box;
color: var(--color-blue);
} */
body {
color: #444;
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
}
.app {
text-align: center;
max-width: 720px;
margin: auto;
padding-bottom: 2rem;
}
.app-header {
padding-top: 1rem;
padding-bottom: 1rem;
}
.app-title {
font-size: 2rem;
margin-bottom: 0;
}
.app-tagline {
font-style: italic;
border-bottom: 1px solid #EEE;
padding-bottom: 1rem;
}
.question {
position: relative;
}
.question-text {
font-size: 1.2rem;
padding-bottom: 1rem;
padding-top: 1rem;
}
.question-type {
text-align: center;
width: 100%;
color: #AAA;
}
// Compiled code!!
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 3);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ }),
/* 1 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (immutable) */ __webpack_exports__["a"] = createScoresObject;
function createScoresObject(ques) {
let Scores = {};
ques.forEach( qdata => {
if( !Scores.hasOwnProperty(qdata.type) ) {
Scores[qdata.type] = 0;
// Add to UI
let div = document.getElementById('bar-template'),
clone = div.cloneNode(true);
clone.removeAttribute('id');
clone.children[0].innerHTML = qdata.type;
clone.children[1].innerHTML = Scores[qdata.type];
clone.children[1].id = qdata.type + 'Value';
document.querySelector('#js-bar-container').appendChild(clone);
}
});
return Scores;
}
/***/ }),
/* 2 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return questions; });
// Static questions data
let questions = [
{
text: 'I can shard a database.',
type: 'back',
},
{
text: 'I know design tools like Sketch, Adobe Illustrator, or Photoshop well.',
type: 'design',
},
{
text: 'I can write a regex.',
type: 'back',
},
{
text: 'I know the difference between == and ===.',
type: 'js',
},
{
text: 'I know when to use call() vs. apply().',
type: 'js',
},
{
text: 'I understand how the browser paints a webpage.',
type: 'back',
},
{
text: 'I am comfortable recommending server-side caching techniques.',
type: 'back',
},
{
text: 'I enjoy designing page layouts.',
type: 'design',
},
{
text: 'I enjoy architecting a stylesheet.',
type: 'front',
},
{
text: 'I am greatly inspired by the work of Paula Scher, Dieter Rams, and Stefan Sagmeister.',
type: 'design',
},
{
text: 'I am greatly inspired by publications like CSS-Tricks, A List Apart, and Smashing Magazine.',
type: 'front',
},
{
text: 'Bad kerning bothers me.',
type: 'design',
},
{
text: 'I know the difference between the Quick Sort and Merge Sort algorithms.',
type: 'back',
},
{
text: 'I am comfortable referring to a stack trace when debugging my code.',
type: 'back',
},
{
text: 'I gain meaningful information from CSS-Tricks.',
type: 'front',
},
{
text: 'I can style a satisfying-to-click button.',
type: 'front',
},
{
text: 'This bothers me: <IMG SRC=\"\">.',
type: 'front',
},
{
text: 'I enjoy debugging CSS.',
type: 'front',
},
{
text: 'I know how to identify garbage collection using dev tools.',
type: 'js',
},
];
/***/ }),
/* 3 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__css_app_css__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__css_app_css___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__css_app_css__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__questions_js__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__Scores_js__ = __webpack_require__(1);
// Questions array import
const questions = __WEBPACK_IMPORTED_MODULE_1__questions_js__["a" /* questions */],
Scores = __WEBPACK_IMPORTED_MODULE_2__Scores_js__["a" /* createScoresObject */](questions);
// App object
const App = {
el: {
question: document.getElementById('js-question'),
questionType: document.getElementById('js-question-type'),
},
data: {
qIndex: 0,
},
setQuestionText() {
this.el.question.innerHTML = questions[this.data.qIndex].text
this.el.questionType.innerHTML = questions[this.data.qIndex].type;
},
isLastQuestion() {
if( this.data.qIndex == questions.length - 1 ) {
return true;
} else {
return false;
}
},
hasMoreQuestions() {
if( this.data.qIndex <= questions.length ) {
return true;
} else if( this.data.qIndex == questions.length ) {
return false;
}
},
updateBarWidth(el, val) {
let width = el.offsetWidth,
oldWidth = parseInt(width, 10),
newWidth = oldWidth + val*10 + 'px';
if( val !== 0 ) {
el.style.width = newWidth;
}
},
updateQuestion() {
this.data.qIndex++;
if ( this.isLastQuestion() ) {
this.el.question.innerHTML = "No more questions.";
document.querySelector('.answers-list').innerHTML = "Done!";
} else {
this.setQuestionText();
}
},
init() {
this.setQuestionText();
}
}
App.init();
// Use event delegation to handle the click event
document.getElementById('js-answers').addEventListener('click', function(e) {
App.updateQuestion();
if(e.target && e.target.nodeName === 'LI') {
let currentQuestion = questions[App.data.qIndex - 1],
targetScore = currentQuestion.type,
clickVal = +e.target.dataset.score,
targetEl = document.getElementById(targetScore + 'Value');
// Update scores
Scores[targetScore] += clickVal;
targetEl.innerHTML = Scores[targetScore];
App.updateBarWidth(targetEl, clickVal);
console.log(Scores);
}
});
/***/ })
/******/ ]);
Also see: Tab Triggers