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 class="healthy-development">
<div class="things-container">
<div class="things-needed">
Picture
</div>
<div class="things-needed">
Name of the game
</div>
<div class="things-needed">
What you use to play the game
</div>
<div class="game-letter">a</div>
<div class="answered-targets game-name">
<div id="Racing" class="answered-buttons">
Racing
</div>
</div>
<div class="answered-targets game-tool">
<div id="Hurdles" class="answered-buttons">
Hurdles
</div>
</div>
<div class="game-letter">b</div>
<div class="game-box game-name"></div>
<div class="game-box game-tool"></div>
<div class="game-letter">c</div>
<div class="game-box game-name"></div>
<div class="game-box game-tool"></div>
<div class="game-letter">d</div>
<div class="game-box game-name"></div>
<div class="game-box game-tool"></div>
<div class="game-letter">e</div>
<div class="game-box game-name"></div>
<div class="game-box game-tool"></div>
<div class="game-letter">f</div>
<div class="game-box game-name"></div>
<div class="game-box game-tool"></div>
</div>
<div class="game-answers">
<div id="Hula" class="game-things games">
Hula hoop
</div>
<div id="Swimming" class="game-things games">
Swimming
</div>
<div id="Singing" class="game-things games">
Singing game
</div>
<div id="Football" class="game-things games">
Football
</div>
<div id="Somersault" class="game-things games">
Somersault
</div>
<div id="Handkerchief" class="game-things tools">
Handkerchief
</div>
<div id="Ball" class="game-things tools">
Ball
</div>
<div id="Hoop" class="game-things tools">
Hoop
</div>
<div id="Floaters" class="game-things tools">
Floaters
</div>
<div id="Mattress" class="game-things tools">
Mattress
</div>
</div>
</div>
pale-teal = #D5F6F6
light-teal = #A4D8D8
child-yellow = #efab2b
dark-teal = #157678
dark-green = #0B3F3F
marker-purple = #7e57c2
theme-red = #EB664D
correct-green = #528620
.healthy-development
display flex
position relative
flex 0 1 100%
flex-wrap wrap
justify-content center
height 65vh
.things-container
width 80%
display grid
grid-template-columns:0.3fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr 1fr 1fr 1fr 1fr ;
height 30em
border 2px solid dark-green
border-bottom 0
.game-box, .game-letter, .things-needed, .answered-targets
padding 0.4em 0 0.3em
font-size 1.4em
text-align center
border 2px solid dark-green
background-color rgba(pale-teal, 0.8)
.answered-buttons
width 5em
height 1.5em
font-family: "Poppins-Semi-Bold", sans-serif
font-size 1em
color white
background-color correct-green
margin-left 0.25em
padding 0.25em 1.2em 0.2em 0
border-radius 0.5em
box-shadow 0px 7px 15px rgba(0,0,0,0.5)
.answered-targets
padding 0
.addRed
background-color rgb(248, 164, 164)
.occupied
background-color #91db4a
.things-needed
color white
background-color dark-teal
.game-answers
display flex
flex 0 1 100%
height 3.5em
flex-wrap wrap
justify-content space-around
height 15vh
.game-things
width 7.5em
height 1.5em
font-family: "Poppins-Light", sans-serif
font-size 1.3em
color light-navy
background-color white
margin 0.4em
padding 0.25em 1.5em 0.25em 0.75em
border-radius 0.75em
box-shadow 0px 7px 15px rgba(0,0,0,0.5)
#Ball
width 2em
#Hoop
width 2.5em
#Love
width 2.5em
#Racing
width 4em
#Football, #Floaters, #Mattress
width 4.5em
#Swimming, #Hula, #Television
width 5.5em
#Somersault
width 6em
#Handkerchief
width 7em
.dragging-it
background-color child-yellow
font-family "Poppins-Bold", sans-serif
color light-navy
.thats-correct
background-color correct-green
font-family "Poppins-Semi-Bold", sans-serif
color white
.connected
background-color child-yellow
// -------------------------------------------------------------
let childrenGames = {
"Racing": "Hurdles",
"Football": "Ball",
"Hula hoop": "Hoop",
"Singing game": "Handkerchief",
"Somersault": "Mattress",
"Swimming": "Floaters"
}
/* Dragging buttons function */
// The drag-n-drop targets
let targets = $(".game-box"); // Table targets
// The drag-n-drop buttons
var buttons = $(".game-things"); // drag buttons
// ------------------------------------------------------------
$.each(buttons, function(i, e) {
var position = $(e).offset();
e.originalLeft = position.left;
e.originalTop = position.top - 160;
});
$.each(buttons, function(i, e) {
TweenMax.set(e, {
position: "absolute",
left: e.originalLeft,
top: e.originalTop
});
});
let neededThings = 0;
var overlapThreshold = "50%";
Draggable.create(buttons, {
bounds: ".healthy-development",
edgeResistance: 0.65,
type: "x,y",
// throwProps: true,
onDragStart: function() {
if (this.target.targetAttachedTo) this.target.targetAttachedTo.removeClass("occupied");
},
// changes the colour of the targets whilst dragging to give feedback that a
// dragged object is going to snap to it
onDrag: function() {
for (let i = 0; i < targets.length; i++) {
if (this.hitTest(targets[i], overlapThreshold)) {
$(targets[i]).addClass("addRed");
} else {
$(targets[i]).removeClass("addRed");
}
}
$(this.target).addClass("dragging-it");
},
onDragEnd() {
let theDragged = this.target;
let theSpot = document.querySelector(".addRed");
let isHitting = false;
if (theSpot && this.hitTest(theSpot, overlapThreshold)) {
isHitting = true;
}
$(theDragged).removeClass("dragging-it");
if (isHitting) {
if ($(theDragged).hasClass("games") && $(theSpot).hasClass("game-name") ||
$(theDragged).hasClass("tools") && $(theSpot).hasClass("game-tool")) {
// if the tool is the one used for the game || if the game is the one that played with the tool
let p = $(theSpot).position();
// tween onto target
TweenLite.to(theDragged, 0.1, {
left: p.left,
top: p.top,
x: 0,
y: -5
});
$(theSpot).addClass("occupied");
theDragged.targetAttachedTo = theSpot;
snapMade = true;
$(theDragged).addClass("thats-correct");
neededThings++;
if (neededThings == 9) {
setTimeout(() => {
functions.challengeFinished.play();
}, 2000);
}
} else if ($(theDragged).hasClass("games") && $(theSpot).hasClass("game-tool") ||
$(theDragged).hasClass("tools") && $(theSpot).hasClass("game-name")) {
TweenLite.to(theDragged, 0.1, {
x: 0,
y: 0,
top: theDragged.originalTop,
left: theDragged.originalLeft
});
notCorrect.play();
}
} else {
TweenLite.to(theDragged, 0.1, {
x: 0,
y: 0,
top: theDragged.originalTop,
left: theDragged.originalLeft
});
}
}
});
Also see: Tab Triggers