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="book">
<div class="Wrapper">
<div class="cardCont">
<div class="cardFront" id="page1"><h1>Page 1</h1></div>
<div class="cardBack" id="page2"><h1>Page 2</h1></div>
</div>
<div class="cardCont">
<div class="cardFront" id="page3"><h1>Page 3</h1></div>
<div class="cardBack" id="page4"><h1>Page 4</h1></div>
</div>
<div class="cardCont">
<div class="cardFront" id="page5"><h1>Page 5</h1></div>
<div class="cardBack" id="page6"><h1>Page 6</h1></div>
</div>
</div>
</div>
body {
background: #e3dfd8;
overflow: hidden;
}
.book {
width: 72vw;
height: 24vw;
background: #e3dfd8;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.Wrapper {
width: 72vw;
height: 24vw;
position: relative;
position: absolute;
cursor: pointer;
-webkit-font-smoothing: antialiased;
}
.cardCont {
width: 36vw;
height: 24vw;
left: 0%;
position: absolute;
pointer-events: none;
}
.cardFront,
.cardBack {
pointer-events: all;
position: absolute;
left: 100%;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
backface-visibility: hidden;
width: 36vw;
height: 24vw;
overflow: hidden;
background: hsla(0, 0%, 100%, 1);
}
.cardFront {
border-top-right-radius: 1%;
border-bottom-right-radius: 1%;
}
.cardBack {
border-top-left-radius: 1%;
border-bottom-left-radius: 1%;
left: 0%;
}
#page1:before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0);
z-index: 2;
pointer-events: none;
}
#page2:before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.2);
z-index: 2;
pointer-events: none;
}
#page3:before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0);
z-index: 2;
pointer-events: none;
}
#page4:before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.2);
z-index: 2;
pointer-events: none;
}
#page5:before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0);
z-index: 2;
pointer-events: none;
}
#page6:before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.2);
z-index: 2;
pointer-events: none;
}
.cardBack h1,
.cardFront h1 {
margin: 0px;
font-size: 30px;
padding: 10px 0px 10px 10px;
border-bottom: solid 6px #aaa;
border-top: solid 6px #aaa;
background-color: black;
color: white;
}
.cardBack h1 {
border-color: #91e600;
}
//CSSPlugin.defaultTransformPerspective = 5000;
var numberOfPages = $('.Wrapper').children().length;
var hoverTarget; //stores currently hovered page, will only remove the hover effect if it hasn't been turned.
var PagesMoving = false; //prevents the pages getting out of order with multiple page clicks running simultaneously
//set the 3d perspective and initiate the back pages so it's rotated to the correct position
TweenLite.set(".book", {
transformStyle: "preserve-3d"
});
TweenLite.set(".Wrapper", {
transformStyle: "preserve-3d",
transformPerspective: 7000,
transformOrigin: '50% 0%',
rotationX: 12
});
TweenLite.set(".cardCont", {
transformStyle: "preserve-3d",
transformPerspective: 7000
});
TweenMax.set(".cardBack", {
transformStyle: "preserve-3d",
transformOrigin: '100% 50%',
transformPerspective: 7000,
rotationY: 180
});
TweenMax.set(".cardFront", {
transformStyle: "preserve-3d",
transformPerspective: 5000,
transformOrigin: '0% 50%'
});
// functions that set the z-index after a page has been moved
function setZIndexLeft(element, index) {
element.css('z-index', (index + 1));
}
function setZIndexRight(element, index) {
element.css('z-index', (numberOfPages - index) + 1);
}
//function that runs on completion of a page move
function pageTurnComplete() {
PagesMoving = false;
}
//set initial z-index
var pages = $('.Wrapper').children();
pages.each(function(i) {
var page = $(this);
page.css('z-index', (numberOfPages - i) + 1);
});
// turn pages on click - needs a function for the front of a page (i.e. one on the right hand side) and the back (on the left hand side)
$('.cardFront').click(function() {
if (PagesMoving != true) {
PagesMoving = true;
var frontCard = $(this),
backCard = $(this).parent(".cardCont").children(".cardBack"),
element = $(this).parent(".cardCont"),
parentPage = $(this).parent(".cardCont"),
indexOf = (2 * (parentPage.index()+1) - 1),
indexOf2 = indexOf + 1,
tl = new TimelineMax({
paused: false
});
var pageName = "#page" + indexOf + ":before",
pageName2 = "#page" + indexOf2 + ":before",
pageToDim = CSSRulePlugin.getRule(pageName),
pageToDim2 = CSSRulePlugin.getRule(pageName2);
hoverTarget = -1;
console.log(hoverTarget);
tl
.to(frontCard, 1.4, {
rotationY: -180,
ease: Power1.easeInOut
}, 'start')
.to(pageToDim, 0.65, {
cssRule: { background: 'rgba(0, 0, 0, 0.2)' },
ease: Power1.easeInOut
}, 'start')
.to(pageToDim2, 0.65, {
cssRule: { background: 'rgba(0, 0, 0, 0.0)' },
ease: Power1.easeInOut,
onComplete: pageTurnComplete
}, 'start+=0.75')
.to(backCard, 1.4, {
rotationY: 0,
ease: Power1.easeInOut,
onComplete:setZIndexLeft,
onCompleteParams :[parentPage,parentPage.index()]
}, 'start');
}
});
// turn pages on click - needs a function for the back (on the left hand side) and the front of a page (i.e. one on the right hand side)
$('.cardBack').click(function() {
if (PagesMoving != true) {
PagesMoving = true;
console.log("back clicked");
var frontCard = $(this).parent(".cardCont").children(".cardFront"),
backCard = $(this),
element = $(this).parent(".cardCont"),
parentPage = $(this).parent(".cardCont"),
indexOf = (2 * (parentPage.index()+1) - 1),
indexOf2 = indexOf + 1,
tl = new TimelineMax({
paused: false
});
var pageName = "#page" + indexOf + ":before",
pageName2 = "#page" + indexOf2 + ":before",
pageToDim = CSSRulePlugin.getRule(pageName),
pageToDim2 = CSSRulePlugin.getRule(pageName2);
hoverTarget = -1;
console.log(hoverTarget);
tl
.to(frontCard, 1.4, {
rotationY: 0,
ease: Power1.easeInOut
}, "start")
.to(pageToDim2, 0.65, {
cssRule: { background: 'rgba(0, 0, 0, 0.2)' },
ease: Power1.easeInOut
}, "start")
.to(pageToDim, 0.65, {
cssRule: { background: 'rgba(0, 0, 0, 0.0)' },
ease: Power1.easeInOut
}, 'start+=0.75')
.to(backCard, 1.4, {
rotationY: 180,
ease: Power1.easeInOut,
onStart:setZIndexRight,
onStartParams :[parentPage,parentPage.index()],
onComplete: pageTurnComplete
}, "start");
}
});
//raise pages on hover, again, one set of functions for the front and back of the pages
$(".cardFront").hover(elOverFront, elOutFront);
function elOverFront()
{
if((!TweenMax.isTweening()) && (PagesMoving == false)) {
var frontCard = $(this),
backCard = $(this).parent(".cardCont").children(".cardBack"),
element = $(this).parent(".cardCont"),
parentPage = $(this).parent(".cardCont"),
indexOf = (2 * (parentPage.index()+1) - 1),
tl = new TimelineMax({
paused: false
}),
pageName = "#page" + indexOf + ":before",
pageToDim = CSSRulePlugin.getRule(pageName);
hoverTarget = indexOf;
console.log(hoverTarget);
tl
.to(frontCard, 0.4, {
rotationY: -10,
ease: Power1.easeInOut
})
.to(pageToDim, 0.4, {
cssRule: { background: 'rgba(0, 0, 0, 0.05)' },
ease: Power1.easeInOut
}, 0);
}
}
function elOutFront()
{
if((!TweenMax.isTweening()) && (PagesMoving == false)) {
var frontCard = $(this),
backCard = $(this).parent(".cardCont").children(".cardBack"),
element = $(this).parent(".cardCont"),
parentPage = $(this).parent(".cardCont"),
indexOf = (2 * (parentPage.index()+1) - 1);
if (hoverTarget == indexOf) {
var tl = new TimelineMax({
paused: false
}),
pageName = "#page" + indexOf + ":before",
pageToDim = CSSRulePlugin.getRule(pageName);
tl
.to(frontCard, 0.4, {
rotationY: 0,
ease: Power1.easeInOut
})
.to(pageToDim, 0.4, {
cssRule: { background: 'rgba(0, 0, 0, 0.0)' },
ease: Power1.easeInOut
}, 0);
}
}
}
//raise pages on hover, again, one set of functions for the front and back of the pages
$(".cardBack").hover(elOverBack, elOutBack);
function elOverBack()
{
if((!TweenMax.isTweening()) && (PagesMoving == false)) {
var frontCard = $(this).parent(".cardCont").children(".cardFront"),
backCard = $(this),
element = $(this).parent(".cardCont"),
parentPage = $(this).parent(".cardCont"),
indexOf = 2 * (parentPage.index()+1),
tl = new TimelineMax({
paused: false
}),
pageName = "#page" + indexOf + ":before",
pageToDim = CSSRulePlugin.getRule(pageName);
hoverTarget = indexOf;
console.log(hoverTarget);
tl
.to(backCard, 0.4, {
rotationY: 10,
ease: Power1.easeInOut
})
.to(pageToDim, 0.4, {
cssRule: { background: 'rgba(0, 0, 0, 0.05)' },
ease: Power1.easeInOut
}, 0);
}
}
function elOutBack()
{
if((!TweenMax.isTweening()) && (PagesMoving == false)) {
var frontCard = $(this).parent(".cardCont").children(".cardFront"),
backCard = $(this),
element = $(this).parent(".cardCont"),
parentPage = $(this).parent(".cardCont"),
indexOf = 2 * (parentPage.index()+1);
if (hoverTarget == indexOf) {
var tl = new TimelineMax({
paused: false
}),
pageName = "#page" + indexOf + ":before",
pageToDim = CSSRulePlugin.getRule(pageName);
tl
.to(backCard, 0.4, {
rotationY: 0,
ease: Power1.easeInOut
})
.to(pageToDim, 0.4, {
cssRule: { background: 'rgba(0, 0, 0, 0.0)' },
ease: Power1.easeInOut
}, 0);
}
}
}
Also see: Tab Triggers