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.
<h1>3D Carousel</h1>
<div class="carousel_wrapper">
<div class="carousel">
<div class="slide one">
<img src="http://nasa-images.com/wp-content/uploads/2011/05/392.jpg" />
</div>
<div class="slide two">
<img src="https://images.unsplash.com/photo-1487235829740-e0ac5a286e1c" />
</div>
<div class="slide three">
<img src="https://images.unsplash.com/photo-1473813585561-ec87eac91e39" />
</div>
<div class="slide four">
<img src="http://nasa-images.com/wp-content/uploads/2011/05/261.jpg" />
</div>
<div class="slide five">
<img src="http://hdwallpaperfun.com/wp-content/uploads/2014/08/Outer-Space-Wallpaper-Background-HQ.jpg" />
</div>
<div class="slide six">
<img src="https://images.unsplash.com/photo-1479409286066-c0b2f4f4a332" />
</div>
<div class="slide seven">
<img src="http://cdn.wonderfulengineering.com/wp-content/uploads/2014/04/space-wallpaper-4.jpg" />
</div>
<div class="slide eight">
<img src="http://shareyourwallpapers.com/upload/wallpaper/3d-and-digital-art/3d-space/3d-space_f48db6ca.jpg" />
</div>
<div class="slide nine">
<img src="https://images.unsplash.com/photo-1446776709462-d6b525c57bd3" />
</div>
</div><!-- / .carousel -->
</div><!-- / .carousel_wrapper -->
<!--
SUN IMAGE HERE: https://chivethebrigade.files.wordpress.com/2012/03/sun-920-32.jpg
-->
*, *::before, *::after {
box-sizing: border-box; /* Too much math below to be concerned with standard CSS Box Model element dimensions calculations. Let's not have to account for padding/margins/borders on anything here. */
}
body {
margin: 0;
background-image: url('http://www.desktopwallpaperhd.net/wallpapers/18/d/andromeda-space-background-computer-images-187549.jpg');
background-attachment: fixed;
background-size: cover;
}
h1 {
margin: 0 0 30px 0;
padding: 20px;
background-color: rgba(20,20,20,0.9);
color: #fff;
text-align: center;
font-family: Arial;
text-transform: uppercase;
box-shadow: 0 0 20px -1px #efefef;
}
.carousel_wrapper {
position: relative;
width: 320px;
margin: 100px auto 0 auto;
perspective: 1000px;
}
.carousel {
position: absolute;
width: 100%;
height: 100%;
transform-style: preserve-3d;
transform: rotateY(-360deg) translateZ(-412px); /* add reverse transformation from the slides */
animation: swirl 40s steps(10000, end) infinite; /* run `swirl` animation (defined at end of CSS) infitely, with animation lasting 40 seconds, and 10,000 steps between the FROM and TO values in the animation for a smooth rotation */
}
.slide {
position: absolute;
top: 10px;
left: 10px;
width: 300px;
height: 187px;
}
.slide img {
width: 280px;
height: 175px;
border: 3px inset rgba(47, 115, 201, 0.75);
box-shadow: 0 0 15px 3px rgba(110, 72, 221, 0.9);
}
/*
9 Slides total: 360 Degrees (full circle) --> 360/9 = 40 --> our increment for rotation
Some math. Consider how the carousel will be set up. It's going to be a 3D circle, like an orbit. The orientation will be such that it would be like setting a ring down on a table, then bending down and looking at the ring head on from the edge of the table. The main "front" image will be entirely front-facing. The other images will be rotated slightly to make a full circle. You could sketch this out in 2D from a bird's eye view, and you'd end up with a picture like the following:
https://cl.ly/image/2P3E1U0W0c29
Each triangle/piece would be a slide, hence 9 pieces. That being said, let's do some calculations, but we'll use the dimensions of our elements rather than those in the picture.
So, we're rotating all the slides in 40º increments relative to each other, because 360º makes a full circle, and we have 9 elements: 360/9 = 40
In the picture above, we want to find the radius of the circle (which isn't exactly a circle because it's made up of triangles). So we can cut each triangle in half and solve for `r` (radius). We can solve for `r` using some geometry and our own elements' dimensions.
The width of the slides is 300px. We're going to split those triangles in half and use the TANGENT function in geometry/trigonemty to solve for `r`. And since we're splitting each of the 9 triangles (the slides) in half for this, we need to account for the fact that our key angle is now going to be 20º and not 40º. We can solve for `r` by taking our smaller triangles' width (150px) and dividing by the tangent of 20º (in degrees, not radians). So:
150
r = -----------
tan(20º)
Here's a screenshot of me doing the calculations in JavaScript, right in the browser console!
Math things: https://cl.ly/image/1t0j1V2Y2l2Z
So, `r` is (about) 412px long! This means we need to TRANSLATE the slides in the Z 3-dimensional plane by 412px. This should be done AFTER the rotateY transformation.
*/
.slide.one {
transform: rotateY(0deg) translateZ(412px);
}
.slide.two {
transform: rotateY(40deg) translateZ(412px);
}
.slide.three {
transform: rotateY(80deg) translateZ(412px);
}
.slide.four {
transform: rotateY(120deg) translateZ(412px);
}
.slide.five {
transform: rotateY(160deg) translateZ(412px);
}
.slide.six {
transform: rotateY(200deg) translateZ(412px);
}
.slide.seven {
transform: rotateY(240deg) translateZ(412px);
}
.slide.eight {
transform: rotateY(280deg) translateZ(412px);
}
.slide.nine {
transform: rotateY(320deg) translateZ(412px);
}
/*
CSS3 ANIMATION
-------------------
Simply rotates the carousel around the Y axis by using rotateY and starting at initial value, -360º, and going to final value 0º, then resetting.
*/
@keyframes swirl {
from {
transform: rotateY(-360deg);
}
to {
transform: rotateY(0deg);
}
}
// NOPE!
Also see: Tab Triggers