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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<body>
<div class="container-fluid text-center">
<div class="row"> <!-- for title
<h1> Title goes here </h1>
-->
</div> <!-- end title -->
<!-- MAIN -->
<div class="row"> <!-- for main -->
<!-- Right below is an image of the sun -->
<img class="responsive-img" id="sun" src="http://orig02.deviantart.net/5786/f/2013/025/7/1/free_sun_stock_image_by_lyra_elante-d5spggh.png" alt="this is a sun">
<!-- Insert the 'earth' on the next line -->
<div id='earth-orbit'>
<img id="earth" src="http://img11.deviantart.net/8762/i/2014/247/3/2/earth___europe_by_mystica_264-d7xwrs5.png" alt="this is the earth">
</div>
<!-- Insert 'jupiter' on the next line -->
<div id='jupiter-orbit'>
<img id="jupiter"
src="https://2.bp.blogspot.com/-grGCMQsVb5U/UJurAJLCJhI/AAAAAAAAABc/iXmLFh-PVdw/s1600/planet-jupiter-large.gif" alt="this is the jupiter planet">
</div>
<!-- -->
<div id='mars-orbit'>
<img id="mars" src="http://img3.wikia.nocookie.net/__cb20130916161813/factfinder/images/c/c5/Mars-1-.png">
</div>
<!-- Look α spacecraft!-->
<div id=''>
<img id="spacecraft" src="https://upload.wikimedia.org/wikipedia/commons/9/94/Rosetta_spacecraft_(transparent_bg).png" alt="this is α spacecraft">
</div>
<!--The astronaut is moving -->
<div id="container">
<div class='a'><img class="random-astro"
src="http://www.immediateentourage.com/ie/wp-content/uploads/2011/10/Astronaut+by+NASA+cropped+by+Immediate+Entourage2.png" alt="this is an astronaut-1"></div>
<div class='b'><img class="random-astro"
src="http://www.clipartqueen.com/image-files/astronaut.png" alt="this is an astronaut-2"></div>
<div class='c'><img class="random-astro"
src="http://www.clipartqueen.com/image-files/astronaut.png" alt="this is an astronaut-3"></div>
</div>
</div> <!-- end main -->
<!-- FOOTER -->
<div class="row text-center"> <!-- for footer -->
<h5><a href="http://www.eleftheriabatsou.com" target="_blank">Eleftheria </a> | <a href="https://codepen.io/EleftheriaBatsou" target="_blank">Projects</a> | <a href="https://www.youtube.com/channel/UCC-WwYv3DEW7Nkm_IP6VeQQ" target="_blank"> Coding videos </a></h5>
</div> <!-- end footer -->
</div> <!-- end class container-fluid -->
</body>
a:link {color:#B24900; text-decoration:none}
a:visited {color:#B24900; text-decoration:none}
a:hover {color:#FF8633; text-decoration:underline} /* Yellow */
/* ----------------------------- */
html, body {
/* The universe takes up all available space */
width: 100%;
height: 100%;
background-image: url("https://static.pexels.com/photos/110854/pexels-photo-110854-medium.jpeg");
/* image in the container */
background-size: contain;
background-attachment: fixed;
/* The universe is black */
background-color: black;
}
#sun {
position: absolute;
/* Positions the top-left corner of the image to be *
/* in the middle of the box */
top: 50%;
left: 50%;
/* Play with these numbers to see what it does */
height: 400px;
width: 400px;
margin-top: -230px;
margin-left: -200px;
}
#earth {
/* Style my earth */
position: absolute;
top: 0;
left: 50%;
height: 40px;
width: 40px;
margin-left: -25px;
margin-top: -25px;
}
#earth-orbit {
position: absolute;
/* make a centered circle*/
top: 50%;
left: 50%;
/* how small/big the movement is going to be*/
width: 320px;
height: 320px;
margin-top: -180px;
margin-left: -160px;
/* draw a circle
border-width: 2px;
border-style: dotted;
border-color: red;
border-radius: 50%;
*/
/* It will rotate my orbit 360 degrees continuously. */
-webkit-animation: spin-right 10s linear infinite;
-moz-animation: spin-right 10s linear infinite;
-ms-animation: spin-right 10s linear infinite;
-o-animation: spin-right 10s linear infinite;
animation: spin-right 10s linear infinite;
}
/* ******************* | jupiter | ********************* */
#jupiter{
width: 70px;
height: 70px;
}
#jupiter-orbit{
position: absolute;
/* make a centered circle*/
top: 50%;
left: 50%;
/* how small/big the movement is going to be*/
width: 600px;
height: 600px;
margin-top: -300px;
margin-left: -290px;
/* draw a circle
border-width: 2px;
border-style: dotted;
border-color: red;
border-radius: 50%;
*/
/* It will rotate my orbit 360 degrees continuously. */
-webkit-animation: spin-right 12s linear infinite;
-moz-animation: spin-right 12s linear infinite;
-ms-animation: spin-right 12s linear infinite;
-o-animation: spin-right 12s linear infinite;
animation: spin-right 12s linear infinite;
}
/* ******************* | mars | ********************* */
#mars{
width: 25px;
height: 25px;
}
#mars-orbit{
position: absolute;
/* make a centered circle*/
top: 50%;
left: 50%;
/* how small/big the movement is going to be*/
width: 450px;
height: 450px;
margin-top: -230px;
margin-left: -230px;
/* draw a circle
border-width: 2px;
border-style: dotted;
border-color: green;
border-radius: 50%;
*/
/* It will rotate my orbit 360 degrees continuously. */
-webkit-animation: spin-right 8s linear infinite;
-moz-animation: spin-right 8s linear infinite;
-ms-animation: spin-right 8s linear infinite;
-o-animation: spin-right 8s linear infinite;
animation: spin-right 8s linear infinite;
}
/* ******************** | spinning | ********************** */
/*custom css animation for spinning */
@-webkit-keyframes spin-right {
100% {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes spin-right {
100% {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
/* ************* | spacecraft | **************** */
#spacecraft{
width: 420px;
height: 200px;
margin-top: -60px;
margin-left: 40%;
/*in order to bounce */
-webkit-animation: bounce 2s infinite ease-in-out;
}
/* spacecraft bouncing*/
@-webkit-keyframes bounce {
0%, 20%, 60%, 100% { -webkit-transform: translateY(0); }
40% { -webkit-transform: translateY(-20px); }
80% { -webkit-transform: translateY(-10px); }
}
/* **************** | astronaut | **************** */
.random-astro{
width: 30px;
height: 50px;
}
div#container {height:500px;width:100%;}
div.a , .b, .c{
position:fixed;
}
/*
js code for the astronauts inspired by: http://jsfiddle.net/j2PAb/
*/
$(document).ready(function() {
animateDiv($('.a'));
animateDiv($('.b'));
animateDiv($('.c'));
});
function makeNewPosition($container) {
// Get viewport dimensions (remove the dimension of the div)
var h = $container.height() - 20;
var w = $container.width() - 20;
var nh = Math.floor(Math.random() * h);
var nw = Math.floor(Math.random() * w);
return [nh, nw];
}
function animateDiv($target) {
var newq = makeNewPosition($target.parent());
var oldq = $target.offset();
var speed = calcSpeed([oldq.top, oldq.left], newq);
$target.animate({
top: newq[0],
left: newq[1]
}, speed, function() {
animateDiv($target);
});
};
function calcSpeed(prev, next) {
var x = Math.abs(prev[1] - next[1]);
var y = Math.abs(prev[0] - next[0]);
var greatest = x > y ? x : y;
var speedModifier = 0.1;
var speed = Math.ceil(greatest / speedModifier);
return speed;
}
Also see: Tab Triggers