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.
<div id="app" class="app">
<section class="quiz" id="quiz">
<div v-if="!isIdle" class="progress">{{currentIndex+1}} / {{total}}
</div>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/74321/darts.svg" width="120" alt=""/>
<h1>Well-aimed?</h1>
<transition name="fade" mode="out-in">
<div v-if="isIdle" key="s1">
<p>Your task is to decide whether a given selector targets <strong>all and only</strong> the elements marked on the right.</p>
<button type="button" @click="start">Let's Start</button>
</div>
<question v-else :key="currentIndex" :v="v" :q="proposal" @answered="go" :disabled="disabled" :correct="answer"></question>
</transition>
<transition name="fade">
<button v-show="shouldShowNext" type="button" @click="displayNext">Next</button>
</transition>
<transition name="fade">
<button v-show="allDone" type="button" @click="showResults">Results</button>
</transition>
</section>
<v-style v-if="!isIdle">.page-doc {{selector}} {
border: 3px solid ;}
</v-style>
<v-style v-if="!isIdle && disabled">.page-doc {{proposal}} {
box-shadow: inset 0 0 0 3px #ff7058;}
</v-style>
<pagedoc></pagedoc>
<transition name="fade2">
<section class="score" v-if="askedForResults">
<h1>Your Result is</h1>
<finalresults :finalpercentage="finalPercentage"></finalresults>
<button type="button" @click="playAgain">Play Again</button>
<p>Play <a href="https://codepen.io/pehaa/pen/OYLwGW" target="_blank" rel="noopener">Specifity Count</a> or <a href="https://codepen.io/pehaa/pen/dEpvXN" target="_blank" rel="noopener">Specifity Wars</a></p>
</section>
</transition>
</div>
<script type="text/x-template" id="finalresults">
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 40" width="300px">
<title>Results Board</title>
<path fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="2px" class="cls-1" d="M15.93,13H2V38.5H49V13H35.07" transform="translate(-0.5 0)"/><path fill="#fff" class="cls-2" d="M21,6.65a.15.15,0,0,0-.12-.11l-2.21-.3-1-2.16a.16.16,0,0,0-.28,0l-1,2.16-2.21.3a.16.16,0,0,0-.12.11.15.15,0,0,0,0,.16L15.66,8.5l-.44,2.31a.17.17,0,0,0,.06.16.15.15,0,0,0,.16,0L17.5,9.9,19.56,11l.07,0a.14.14,0,0,0,.09,0,.17.17,0,0,0,.06-.16L19.34,8.5,21,6.81A.15.15,0,0,0,21,6.65Zm16,0a.15.15,0,0,0-.12-.11l-2.21-.3-1-2.16a.16.16,0,0,0-.28,0l-1,2.16-2.21.3a.16.16,0,0,0-.12.11.15.15,0,0,0,0,.16L31.66,8.5l-.44,2.31a.17.17,0,0,0,.06.16.15.15,0,0,0,.16,0L33.5,9.9,35.56,11l.07,0a.14.14,0,0,0,.09,0,.17.17,0,0,0,.06-.16L35.34,8.5,37,6.81A.15.15,0,0,0,37,6.65ZM30,3.41a.19.19,0,0,0-.16-.14L27,2.88,25.68.1a.21.21,0,0,0-.36,0L24,2.88l-2.83.39a.19.19,0,0,0-.16.14.21.21,0,0,0,0,.21l2.08,2.17-.57,3a.21.21,0,0,0,.07.21.2.2,0,0,0,.21,0L25.5,7.59,28.15,9l.09,0a.19.19,0,0,0,.12,0,.21.21,0,0,0,.07-.21l-.56-3,2.07-2.17A.21.21,0,0,0,30,3.41Z" transform="translate(-0.5 0)"/>
<text style="font-size:12px" x="12.5" y="30" fill="#fff" textLength="25" lengthAdjust="spacing" small>{{finalpercentage}}</text> </svg>
</script>
<script type="text/x-template" id="page-doc">
<div class="page-doc">
<header data-content1="<header>" data-content2="</header>">
<h1 data-content1="<h1>" data-content2="</h1>">…</h1>
<p class="intro" data-content1='<p class="intro">' data-content2="</p>">…</p>
</header>
<main data-content1="<main>" data-content2="</main>">
<section id="section1" data-content1='<section id="section1">' data-content2="</section>">
<h2 data-content1="<h2>" data-content2="</h2>">…</h2>
<p data-content1="<p>" data-content2="</p>">…</p>
<p data-content1="<p>" data-content2="</p>">…</p>
</section>
<p class='out' data-content1='<p class="out">' data-content2="</p>">…</p>
</main>
<footer data-content1='<footer>' data-content2="</footer>">
<div class="widget widget1" data-content1='<div class="widget widget1">' data-content2="</div>"><p data-content1="<p>" data-content2="</p>">…</p></div>
<div class="widget widget2" data-content1='<div class="widget widget2">' data-content2="</div>">
<div data-content1="<div>" data-content2="</div>"></div>
</div>
<div class="widget widget3" data-content1='<div class="widget widget3">' data-content2="</div>">
<div class="out" data-content1='<div class="out">' data-content2="</div>">…</div>
</div>
</footer>
</div>
</script>
:root {
--red: #ff7058;
--black: rgb(64, 89, 107);
}
*, *:before, *:after {
box-sizing: border-box;
}
html {
font-family: Poppins;
line-height: 1.5;
color: var(--black);
}
a {
color: inherit;
}
h1 {
font-family: Modak;
font-weight: 400;
font-size: 3rem;
font-size: calc(3rem + .25vw + .5vh);
margin: 2rem 0 0;
}
.app {
min-height: 100vh;
}
.quiz {
text-align: center;
position: fixed;
right: 40%;
left:0;
}
.quiz img {
margin-top: -3rem;
}
.quiz p {
font-size: calc(1rem + .25vw + .5vh);
padding: 0 1.5rem;
}
strong {
color: var(--red);
}
pre {
font-family: "Anonymous Pro", monospace;
font-size: calc(1.5rem + .25vw + .5vh);
color: var(--red);
}
.page-doc {
background: #ff705855;
position: relative;
margin-left: 60%;
padding: 0 .25rem;
min-height: 100vh;
display: flex;
flex-direction: column;
}
.quiz {
align-items: center;
}
.progress {
position: fixed;
top: 0;
left: 0;
background: var(--red);
color: white;
padding: 0.25rem 1rem;
font-family: monospace;
}
button {
font-family: inherit;
text-transform: uppercase;
margin: 1.5rem;
border: 2px solid;
padding: 1rem 2rem 0.9375rem;
border-radius: .5rem;
color: var(--red);
background: transparent;
letter-spacing: 2px;
font-weight: 800;
cursor: pointer;
transition: .1s;
font-size: calc(1rem + .25vw + .5vh);
}
button:hover {
color: white;
background: var(--red);
border-color: var(--red);
}
.score button {
color: white;
background: transparent;
}
.score button:hover {
color: var(--red);
background: white;
border-color: white;
}
.correct {
color: #1698d0;
}
.wrong {
color: var(--red);
}
.checked.correct {
animation: yay 1.5s ease-in-out infinite both;
}
@keyframes yay {
from {
transform: scale(1);
transform-origin: center center;
animation-timing-function: ease-out;
}
50% {
transform: scale(1.3);
animation-timing-function: ease-out;
}
}
.checked.wrong {
animation: shake-horizontal 0.8s cubic-bezier(0.455, 0.030, 0.515, 0.955) both;
}
@keyframes shake-horizontal {
0%,
100% {
transform: translateX(0);
}
10%,
30%,
50%,
70% {
transform: translateX(-10px);
}
20%,
40%,
60% {
transform: translateX(10px);
}
80% {
transform: translateX(8px);
}
90% {
transform: translateX(-8px);
}
}
.label-ctnr {
display: flex;
align-items: center;
justify-content: center;
}
.label-ctnr label {
position: relative;
left: -.75rem;
padding: 0.5rem 1rem 0.5rem 1.5rem;
border-radius: 5px;
font-weight: 700;
text-transform: uppercase;
font-size: calc(1.5rem + .25vw + .5vh);
display: flex;
align-items: center;
transition: .3s;
}
.label-ctnr label span {
position: absolute;
left: 0;
}
.label-ctnr:not(.disabled) label:hover {
cursor: pointer;
}
.label-ctnr:not(.disabled) label:hover {
transform: scale(1.1);
}
.label-ctnr input {
opacity: 0;
position: absolute;
}
.label-ctnr svg {
width: 1.5rem;
display: block;
}
.path {
stroke-dasharray: 1000;
stroke-dashoffset: 0;
}
.path.line {
stroke-dashoffset: 1000;
animation: dash 1s .15s ease-in-out forwards;
}
.path.line+.path.line {
animation: dash .9s .35s ease-in-out forwards;
}
.path.check {
stroke-dashoffset: -100;
animation: dash-check .9s .35s ease-in-out forwards;
}
@keyframes dash {
0% {
stroke-dashoffset: 1000;
}
100% {
stroke-dashoffset: 0;
}
}
@keyframes dash-check {
0% {
stroke-dashoffset: -100;
}
100% {
stroke-dashoffset: 900;
}
}
.fade-enter-active, .fade-leave-active {
transition: opacity .5s;
}
.fade-enter, .fade-leave-to {
opacity: 0;
}
.fade2-enter-active, .fade2-leave-active {
transition: all 1s 0s ;
transform: scale(1);
}
.fade2-enter, .fade2-leave-to {
opacity: 0;
transform: scale(.5);
}
.score {
position: fixed;
background: var(--red);
color: white;
top: 0;
bottom: 0;
left: 0;
right:0;
z-index: 100;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
//Forked By https://codepen.io/pehaa/pen/ROapJZ
Vue.config.devtools = true
const questions = [
{
'selector' : 'p.out',
'proposal': 'p.out',
'answer': 'yes'
},
{
'selector' : 'h2 ~ p',
'proposal': 'h2 + p',
'answer': 'no'
},
{
'selector' : 'h2 ~ p',
'proposal': 'h2 ~ p',
'answer': 'yes'
},
{
'selector' : '#section1',
'proposal': '[id="section1"]',
'answer': 'yes'
},
{
'selector' : 'h2 + p',
'proposal': 'h2 + p',
'answer': 'yes'
},
{
'selector' : 'section p:first-of-type',
'proposal': 'section p:first-child',
'answer': 'no'
},
{
'selector' : 'section p:first-of-type',
'proposal': 'section p:first-of-type',
'answer': 'yes'
},
{
'selector' : 'main > *',
'proposal': 'main *',
'answer': 'no'
},
{
'selector' : 'main > *',
'proposal': 'main > *',
'answer': 'yes'
},
{
'selector' : 'main p',
'proposal': 'h2 ~ p',
'answer': 'no'
},
{
'selector' : 'main > p',
'proposal': 'main p',
'answer': 'no'
},
{
'selector' : 'main > p',
'proposal': 'main > p',
'answer': 'yes'
},
{
'selector' : 'footer div',
'proposal': 'footer div',
'answer': 'yes'
},
{
'selector' : 'footer > div',
'proposal': 'footer > div',
'answer': 'yes'
},
{
'selector' : 'footer > :nth-child(n)',
'proposal': 'footer > :nth-child(n)',
'answer': 'yes'
},
{
'selector' : 'footer > div',
'proposal': 'footer div',
'answer': 'no'
},
{
'selector' : 'footer > :nth-child(2n+1)',
'proposal': 'footer > :nth-child(2n+1)',
'answer': 'yes'
},
{
'selector' : 'footer > :nth-child(2n+1)',
'proposal': 'footer :nth-child(2n+1)',
'answer': 'no'
},
{
'selector' : ':empty',
'proposal': ':empty',
'answer': 'yes'
},
{
'selector' : '[class*="widget"]',
'proposal': '[class*="widget"]',
'answer': 'yes'
},
{
'selector' : '.widget > *',
'proposal': '.widget > *',
'answer': 'yes'
},
{
'selector' : '.widget.widget1',
'proposal': '.widget.widget1',
'answer': 'yes'
},
{
'selector' : 'div.widget1',
'proposal': 'div.widget1',
'answer': 'yes'
},
{
'selector' : '[class^="widget"]',
'proposal': '[class^="widget"]',
'answer': 'yes'
},
{
'selector' : 'section :first-of-type',
'proposal': 'section :first-of-type',
'answer': 'yes'
}
]
Vue.component( 'question', {
props: ['v', 'q', 'disabled', 'correct'],
data() {
return {
answer: '',
a: []
}
},
computed: {
checked: {
get() {
return this.v
},
set(val) {
this.a = val
}
},
displaySelector() {
return `${this.q} {…}`
}
},
template: `<div>
<pre class="code">{{displaySelector}}</pre>
<div :class="['label-ctnr', disabled ? 'disabled': '']"><label :class="[ feedbackClass(item), checkedClass(item)]" v-for="(item, i) in ['yes', 'no']">
<span v-if="disabled && isChecked(item)">
<svg v-if="isCorrectChecked(item)" version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 130.2 130.2">
<polyline class="path check" fill="none" stroke="#1698d0" stroke-width="20" stroke-linecap="round" stroke-miterlimit="10" points="100.2,40.2 51.5,88.8 29.8,67.5 "/>
</svg>
<svg v-else version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 130.2 130.2">
<line class="path line" fill="none" stroke="#ff7058" stroke-width="20" stroke-linecap="round" stroke-miterlimit="10" x1="34.4" y1="37.9" x2="95.8" y2="92.3"/>
<line class="path line" fill="none" stroke="#ff7058" stroke-width="20" stroke-linecap="round" stroke-miterlimit="10" x1="95.8" y1="38" x2="34.4" y2="92.2"/>
</svg>
</span>
<input @change="answerChecked" type="radio" :id="item" :value="item" v-model="checked" :disabled="disabled"/>{{item}}</label></div>
<button v-if="answer" type="button" @click="submitAnswer">Answer</button>
</div>`,
methods: {
answerChecked() {
this.$emit('answered', this.a )
},
checkedClass(item) {
return this.isChecked(item) ? 'checked' : 'not-checked'
},
isChecked(item) {
return item === this.checked
},
isCorrectChecked(item) {
return item === this.checked && item === this.correct
},
feedbackClass(item) {
if (!this.disabled) {
return
}
return item === this.correct ? 'correct' : 'wrong'
}
}
}
)
Vue.component('v-style', {
render: function (createElement) {
return createElement('style', this.$slots.default)
}
});
Vue.component( 'finalresults', {
props: [ 'finalpercentage'],
template: "#finalresults"
});
Vue.component('pagedoc', {
template: '#page-doc',
data() {
return {}
}
});
new Vue({
el: '#app',
data() {
return {
currentIndex: 0,
checkedAnswers: [],
v: [],
score: 0,
questions: [],
isIdle: true,
askedForResults: false
}
},
computed: {
total() {
return this.questions.length
},
finalPercentage() {
return `${Math.round(this.score/this.total*100)}%`
},
proposal() {
return this.questions[this.currentIndex].proposal
},
selector() {
return this.questions[this.currentIndex].selector
},
answer() {
return this.questions[this.currentIndex].answer
},
isAnswered() {
return this.v.length !== 0
},
disabled() {
return this.v.length !== 0
},
isFinished() {
return this.currentIndex === this.total - 1
},
shouldShowNext() {
return this.isAnswered && !this.isFinished
},
allDone() {
return this.isAnswered && this.isFinished
}
},
methods: {
start() {
this.questions = questions.sort(function(a, b){return 0.5 - Math.random()})
this.isIdle = false
},
go(r) {
this.v = r
if (this.checkAnswer(r)) {
this.score++
}
this.disabled = true
this.isAnswered = true
},
checkAnswer(r) {
return r === this.questions[this.currentIndex].answer
},
resetStep() {
this.isAnswered = false
this.disabled = false
this.v = []
},
displayNext() {
this.currentIndex++
this.resetStep()
},
playAgain() {
this.score = 0
this.start()
this.currentIndex = 0
this.askedForResults = false
this.resetStep()
},
showResults() {
this.askedForResults = true
this.isIdle = true
}
}
})
Also see: Tab Triggers