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.
<header>
<h1>CSS3 PONG!</h1>
</header>
<div role="main">
<div id="court">
<input id="rd0" type="radio" name="set" checked>
<input id="rd1" type="radio" name="set">
<input id="rd2" type="radio" name="set">
<input id="rd3" type="radio" name="set">
<input id="rd4" type="radio" name="set">
<input id="rd5" type="radio" name="set">
<div id="horizontal">
<div id="ball"> </div>
<div id="player2"> </div>
</div>
<ul id="pl1"><!-- Player 1 score (Tip: um... it never changes ;) ) -->
<li>0</li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>WINNER!</li>
</ul>
<ul id="pl2"><!-- Player 2 score -->
<li>0</li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>WINNER!</li>
</ul>
</div>
<p>Click ball to serve</p>
<p>Currently best viewed in Chrome</p>
</div>
<footer>
<p><a href="http://www.sitepoint.com/css3-pong-insane-things-to-do-with-css/">SitePoint.com 2013 - Alex Walker</a></p>
</footer>
@import "compass/css3";
@import url('https://fonts.googleapis.com/css2?family=Montserrat+Alternates:wght@500&display=swap');
/**
* Playable Pong *
*/
$speed: 1.5; /* 1=fast 10=slow*/
$updown-speed:(1.9s*$speed);
$leftright-speed:(2.7s*$speed);
body {
overflow: hidden;
font-family: 'Montserrat Alternates', sans-serif;
background: #000;
margin: 0;
padding: 0;
color: #0f0;
text-align: center;
text-transform: uppercase;
}
body:before { /* scanline effect - full screen */
content: "";
position: absolute;
margin: 0;
padding: 0;
background-image: linear-gradient(transparent 50%, rgba(0, 40, 40, 0.25) 50%);
background-size: 100% 4px;
width: 100%;
height: 100%;
z-index: 999;
pointer-events: none;
top: 0;
left: 0; }
body * { /* blur glow */
text-shadow: 0px 0px 3px rgba(90, 255, 90, 0.9), 0px 0px 3px rgba(90, 255, 90, 0.9), 0px 0px 7px rgba(90, 255, 90, 0.9); }
h1 {
text-align: center;
font: 400 60px 'Impact';
letter-spacing: 5px;
font-family: 'Montserrat Alternates', sans-serif;
line-height: 1em;
color: #0afa0a;
font-weight: bold;
font-size: 70px;
text-shadow: 0px 0px 0 #35bb35, 0px 1px 0 #47a947, 0px 2px 0 #589858, 0px 3px 0 #6a866a, 0px 4px 0 #7b757b, 0px 5px 0 #8c648c, 0px 6px 5px rgba(0, 0, 0, 0.25), 0px 6px 1px rgba(0, 0, 0, 0.5), 0px 0px 5px rgba(0, 0, 0, 0.2); }
p {
text-align: center;
font: 400 24px'';
font-family: 'Montserrat Alternates', sans-serif;}
footer p {
font-size: 12px; }
#court {
margin: 29px auto;
width: 600px;
height: 301px;
position: relative;
border: 4px dotted #3f3;
text-shadow: 0px 0px 7px rgba(90, 255, 90, 0.9), 0px 0px 7px rgba(90, 255, 90, 0.9);
cursor: url(https://i.imgur.com/OGNRZH1.gif), text;}
#court:before { /* net */
left: 50%;
content: "";
width: 10px;
height: 300px;
position: absolute;
border-left: 4px dashed #3f3;
}
/* ------ ball components ------- */
#ball {
position: absolute;
width: 20px;
height: 20px;
display: block;
background: #3f3;
border-radius: 50%;
cursor: url(https://i.imgur.com/OGNRZH1.gif), text;
box-shadow: 0px 0px 7px rgba(90, 255, 90, 0.9), 0px 0px 7px rgba(90, 255, 90, 0.9);
animation: fadein 2s 1 linear;
transform: translate3d(10px, 0, 0); }
#horizontal {
position: absolute;
width: 100%;
height: 20px;
top: 45%;
cursor: url(https://i.imgur.com/OGNRZH1.gif), text;}
#player2 {
/* player 2 */
background: #3f3;
position: absolute;
width: 7px;
height: 44px;
right: 4px;
margin-top: -12px; }
/* ------ ball animation ------- */
input:checked + input:hover ~ #horizontal #ball {
/* ready: pulse ball */
animation: pulse 0.5s infinite; }
input:hover:checked ~ #horizontal {
animation: updown $updown-speed infinite linear; }
input:hover:checked ~ #horizontal #ball {
animation: leftright $leftright-speed infinite linear;
background: cyan; }
input:hover:checked ~ #horizontal #player2 {
animation: twitchy $leftright-speed infinite linear; }
/* ------ The Scoring System------- */
ul {
position: absolute;
right: 30%;
list-style: none;
height: 40px;
width: 80px;
overflow: hidden;
font-size: 40px;
padding: 0;
margin: 0;
top: 20px;
text-align: center; }
ul li {
position: absolute;
top: -50px;
width: 80px; }
/* position score lists */
ul#pl1 {
left: 25%; }
ul#pl2 {
left: 64%;
width: 180px;
text-align: left;
}
ul#pl1 li:nth-of-type(1) {
top: 0px;
}
input:nth-of-type(1):checked ~ ul#pl2 li:nth-of-type(1),
input:nth-of-type(2):checked ~ ul#pl2 li:nth-of-type(2),
input:nth-of-type(3):checked ~ ul#pl2 li:nth-of-type(3),
input:nth-of-type(4):checked ~ ul#pl2 li:nth-of-type(4),
input:nth-of-type(5):checked ~ ul#pl2 li:nth-of-type(5),
input:nth-of-type(6):checked ~ ul#pl2 li:nth-of-type(6),
input:nth-of-type(2):hover:checked ~ ul#pl2 li:nth-of-type(1),
input:nth-of-type(3):hover:checked ~ ul#pl2 li:nth-of-type(2),
input:nth-of-type(4):hover:checked ~ ul#pl2 li:nth-of-type(3),
input:nth-of-type(5):hover:checked ~ ul#pl2 li:nth-of-type(4),
input:nth-of-type(6):hover:checked ~ ul#pl2 li:nth-of-type(5) {
top: 0px;
/* show the score (LI) associated with each input */
transition: top 0.75s;
}
input:nth-of-type(1):hover:checked ~ ul#pl2 li:nth-of-type(1),
input:nth-of-type(2):hover:checked ~ ul#pl2 li:nth-of-type(2),
input:nth-of-type(3):hover:checked ~ ul#pl2 li:nth-of-type(3),
input:nth-of-type(4):hover:checked ~ ul#pl2 li:nth-of-type(4),
input:nth-of-type(5):hover:checked ~ ul#pl2 li:nth-of-type(5),
input:nth-of-type(6):hover:checked ~ ul#pl2 li:nth-of-type(6) {
top: -50px;
/* delay the next score offscreen WHILE the hover is active */ }
/* ------ Scoring switches ------- */
input {
/* hide all */
width: 0px;
height: 0px;
overflow: hidden;
appearance: none;
position: absolute;
top: -100px;
left: -10px;
cursor: url(https://i.imgur.com/OGNRZH1.gif), text; }
input:checked + input {
left: -20px;
top: 36%;
width: 70px;
height: 50px;
z-index: 99; }
input:hover:checked {
/* uncomment the next line to get an idea how we're faking collision detection with CSS hover - yes it's a huge hack ;) */
/*background: rgba(0, 0, 200, 0.3);*/
left: -20px;
top: 36%;
width: 100px;
height: 100px;
outline: 0px none;
animation:
updown $updown-speed infinite linear,
targetzone $leftright-speed infinite linear;
z-index: 99;
}
input:hover:checked + input {
/* keep the NEXT targetzone hidden till previous hover state ends */
left: 0px;
top: -100px;
width: 50px;
height: 50px; }
/* ------ reset score button ------- */
input#rd0 {
/* reset scores*/
left: 550px;
appearance: normal;
width: 50px;
height: 50px; }
input#rd0:hover:checked {
animation: none; }
input#rd0:before {
/* reset scores*/
content: "Reset";
color: white;
font-size: 12px;
height: 25px; }
/* ------ The Animations ------- */
@keyframes updown {
0%, 50%, 100% {
/* the middle */
transform: translate3d(0, 0, 0); }
25% {
/* the top */
transform: translate3d(0, 142px, 0); }
75% {
/* the bottom */
transform: translate3d(0, -136px, 0); } }
@keyframes leftright {
0%, 100% {
/* left side */
transform: translate3d(10px, 0, 0);
width: 10px;
/*squash ball*/
height: 25px; }
5%, 48%, 55%, 99% {
/* unsquash ball */
width: 20px;
height: 20px; }
50% {
/* right side */
transform: translate3d(580px, 0, 0);
width: 10px;
/*squash ball*/
height: 35px; } }
@keyframes targetzone {
/* ball in general play */
0%, 96% {
width: 800px;
height: 700px;
margin: -50% 0 0 -50%; }
/* ball about to pass player 1's baseline */
96.1%, 100% {
width: 150px;
height: 100px;
top:0;
left:0;
margin: 10% 0 0 -50px;}
}
@keyframes pulse {
/* pulse the ball -- 'READY!' */
0%, 100% {
opacity: .2; }
90% {
opacity: 1; } }
@keyframes fadein {
/* fades new ball in after each point */
0% {
height: 0; }
90% {
height: 0; }
100% {
height: 20px; } }
@keyframes twitchy {
/* make player twitch like a real player */
0%,
100% {
transform: translate3d(0, 40px, 0); }
20% {
transform: translate3d(0, -25px, 0); }
44% {
transform: translate3d(0, 25px, 0); }
46% {
transform: translate3d(0, -15px, 0); }
48% {
transform: translate3d(0, 15px, 0); }
50% {
transform: translate3d(0, 0, 0); }
70% {
transform: translate3d(0, 60px, 0); }
85% {
transform: translate3d(0, -30px, 0); }
}
/* nothing to see here... */
Also see: Tab Triggers