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 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.
<div class="stage">
<div class="pyramid3d">
<div class="square side1"></div>
<div class="square side2">נ</div>
<div class="square side3">ה</div>
<div class="square side4">ג</div>
<div class="square side5">פ</div>
<div class="square small side1"></div>
<div class="rect side2"></div>
<div class="rect side3"></div>
<div class="rect side4"></div>
<div class="rect side5"></div>
<div class="triangle side2"></div>
<div class="triangle side3"></div>
<div class="triangle side4"></div>
<div class="triangle side5"></div>
</div>
</div>
<div class="instructions">
<p>Use the arrow keys to rotate the dreidel</p>
<ul class="arrows">
<li>↑</li>
<li>←</li>
<li>↓</li>
<li>→</li>
</ul>
</div>
<footer>
<small>heavily based on <a href="http://www.khemissi.com/examples/css3/010-3D-pyramid/">css3 pyramid</a><br>
by SelimKhemissi</small>
</footer>
/* pyramid author : Selim Khemissi http://www.khemissi.com
http://www.khemissi.com/examples/css3/010-3D-pyramid/
*/
.stage {
position:relative;
top: 300px;
width: 150px;
height: 320px;
margin:auto;
perspective:1200px;
perspective-origin:50% 50%;
}
.pyramid3d {
position:relative;
width:200px;
height:200px;
margin:0 auto;
transition: transform 1s ease-out;
transform-style: preserve-3d;
transform: rotateX(50deg) rotateY(0deg) rotate(45deg);
}
.triangle,
.square {
transform-style:preserve-3d;
transform-origin: left top;
transition: transform 200ms ease-out;
}
.triangle {
width:0;
height:0;
background:none;
}
/* note that border dimension includes border set in '.side' CSS Class */
.triangle:before{
content:"";
position: absolute;
height: 0;
width: 0;
border-style: solid;
/* border-color: rgba(50, 50, 50, 0.7) transparent transparent transparent; */
border-width: 176px 100px 0 100px;
}
.square {
position:absolute;
width: 200px;
height: 200px;
background: rgba(black, 0.5);
font-size:8em;
color:#fff;
text-align: center;
font-family: alef, arial;
font-weight: bold;
&.small {
width: 20px;
height: 20px;
}
}
.rect {
width: 20px;
height: 100px;
position: absolute;
background: rgba(black, 0.5);
}
/* note that translation includes border set in '.side' CSS Class */
.side1 {
/* square */
transform: translatez(200px);
background:rgba(0, 0, 0, 0.7);
&.small {
transform: translatez(300px) translatex(90px) translatey(90px);
}
}
.side2 {
/* triangle */
transform: translatex(0) rotatey(-125deg) rotatez(90deg);
&.square {
background: rgba(black, 0.5);
transform: translatex(0) translatez(200px) rotatey(-90deg) rotatez(90deg);
}
&.rect {
background: rgba(20, 20, 20, 0.3);
transform: translatex(80px) translatey(50px) translatez(250px) rotatey(90deg) rotatez(90deg);
}
}
.side3 {
/* triangle */
transform: translatex(200px) rotatez(90deg) rotatex(-55deg);
&.square {
background: rgba(yellow, 0.5);
transform: translatex(200px) translatez(200px) translatey(200px) rotatez(-90deg) rotatex(-90deg); }
&.rect {
background: rgba(20, 20, 20, 0.3);
transform: translatex(100px) translatez(250px) translatey(50px) rotatez(-90deg) rotatex(-90deg);
}
}
.side4 {
/* triangle */
transform: translatez(0) rotatex(-55deg);
&.square {
background: rgba(blue,0.5);
transform: translatez(200px) rotatex(-90deg) rotatey(-180deg) translatex(-200px);
}
&.rect {
transform: translatez(250px) translatey(40px) rotatex(90deg) translatex(90px);
}
}
.side5 {
/* triangle */
transform: translatey(200px) rotatex(-125deg);
&.square {
background: rgba(red, 0.5);
transform: translatey(200px) translatez(200px) rotatex(-90deg);
}
&.rect {
transform: translatey(60px) translatex(90px) translatez(250px) rotatex(-90deg);
}
}
.side2:before,
.side3:before{ border-color: rgba(20, 20, 20, 0.3) transparent transparent transparent; }
.side4:before,
.side5:before{ border-color: rgba(40, 40, 40, 0.6) transparent transparent transparent; }
.instructions {
position: absolute;
bottom: 10px;
left: 10px;
background: beige;
padding: 10px;
border: 1px solid #999;
border-radius: 3px;
}
.arrows {
list-style-type: none;
padding: 0;
text-align: center;
li {
width: 30px;
height: 30px;
line-height: 30px;
border-radius:3px;
border: 1px solid #ddd;
text-align: center;
display: inline-block;
background: #fff;
box-shadow: 1px 2px 0 rgba(black, 0.05);
&:first-child {
display: block;
margin: 0 auto 5px;
}
}
}
footer {
position: absolute;
right: 10px;
bottom: 10px;
width: 200px;
}
a {
color: #048;
}
/* @author Selim Khemissi http://www.khemissi.com */
(function($) {
$.cssprefix = function(property) {
var cssProp = property;
if($.browser.webkit || $.browser.chrome) {
cssProp = '-webkit-'+property;
} else if($.browser.mozilla) {
cssProp = '-moz-'+property;
} else if($.browser.msie) {
cssProp = '-ms-'+property;
} else if($.browser.opera) {
cssProp = '-o-'+property;
}
return cssProp;
}
var SekKeyboard = {
stdAngle : 45,
xAngle : 75,
angleStep : 40,
scale : 1,
scaleStep : 0.2,
initialized:false,
element:null,
init:function(element) {
var self = SekKeyboard;
if(self.initialized) {
return;
}
self.element = element;
self.initialized = true;
$('body').keydown(function(evt) {
switch(evt.keyCode) {
case 37: // arrow left
case 100: // 4 pad
evt.preventDefault();
self.stdAngle -= self.angleStep;
break;
case 38: // arrow up
case 104: // 8 numeric pad
evt.preventDefault();
self.xAngle += self.angleStep;
break;
case 39: // arrow right
case 102: // 6 numeric pad
evt.preventDefault();
self.stdAngle += self.angleStep;
break;
case 40: // arrow down
case 98: // 2 numeric pad
evt.preventDefault();
self.xAngle -= self.angleStep;
break;
case 107: // + numeric pad
evt.preventDefault();
self.scale += self.scaleStep;
break;
case 109: // - numeric pad
evt.preventDefault();
self.scale -= self.scaleStep;
break;
};
$.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
});
$('#button_grid_rotation_standard_left').click(function() {
var self = SekKeyboard;
self.stdAngle -= self.angleStep;
$.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
})
$('#button_grid_rotation_standard_right').click(function() {
var self = SekKeyboard;
self.stdAngle += self.angleStep;
$.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
})
$('#button_grid_rotation_3dx_up').click(function() {
var self = SekKeyboard;
self.xAngle += self.angleStep;
$.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
})
$('#button_grid_rotation_3dx_down').click(function() {
var self = SekKeyboard;
self.xAngle -= self.angleStep;
$.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
})
$('#button_grid_zoom_out').click(function() {
var self = SekKeyboard;
self.scale -= self.scaleStep;
$.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
})
$('#button_grid_zoom_in').click(function() {
var self = SekKeyboard;
self.scale += self.scaleStep;
$.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
})
},
}
$.fn.keyboard_controls = function() {
// KEYBOARD COMMAND - GRID VIEW ORIENTATION
SekKeyboard.init(this);
}
$.rotate3d = function(element, xAngle, stdAngle, scale) {
element.attr('style', $.cssprefix('transform')+': rotateX('+xAngle+'deg) rotate('+stdAngle+'deg) scale('+scale+');');
}
})(jQuery);
$(document).ready(function() {
$('.pyramid3d').keyboard_controls();
setTimeout(function() {
$.rotate3d($('.pyramid3d'), 90, 320, 1.2);
}, 1000)
})
Also see: Tab Triggers