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="wrapper" id="wrapper">
<div class="cover page" id="cover">
<h1>Recipes Shmecipes</h1>
<h2>Mary Berrys, Banana Bread</h2>
<p>A warming banana loaf recipe, made using the ripest bananas. This deliciously moist loaf cake, best served in thick slices, is one of Mary Berry's most popular recipes.</p>
</div>
<img class="image" src="https://i.pinimg.com/564x/a5/f0/2b/a5f02b5d0feacbd33d382bd979ac92ea.jpg" alt="yummy">
<div class="intro" id="intro">
<h3>Intro</h3>
<p>This is a lovely, moist loaf, which really doesn’t need to be buttered. It freezes extremely well. Any bananas left in the fruit bowl are ideal for this cake - the riper they are, the better.</p>
<ul class="stats">
<li class="level stat">Level: <span>Easy</span></li>
<li class="prep stat">Prep Time: <span>15min</span></li>
<li class="cook stat">Cook Time: <span>1hr</span></li>
<li class="total stat">Total time: <span>1.15hr</span></li>
</ul>
</div>
<div class="ingredients" id="ingredients">
<h3>Ingredients</h3>
<div class="ingredient">
<p class="ingredient--amount">100g</p>
<p>butter, softend</p>
</div>
<div class="ingredient">
<p class="ingredient--amount">175g</p>
<p>caster sugar</p>
</div>
<div class="ingredient">
<p class="ingredient--amount">2</p>
<p>eggs</p>
</div>
<div class="ingredient">
<p class="ingredient--amount">2</p>
<p>ripe bananas, mashed</p>
</div>
<div class="ingredient">
<p class="ingredient--amount">1 tsp</p>
<p>baking powder</p>
</div>
</div>
<div class="kit" id="kit">
<h3>Essential Kit</h3>
<p>You will need a 900g (2lb) loaf tin, 17 x 9 x 9cm (6½ x 3½ x 3½in) base measurement.</p>
</div>
<div class="instructions " id="instructions">
<h3>Instructions</h3>
<p class="step step--1">Lightly grease the loaf tin and line it with non-stick baking parchment. Pre-heat the oven to 180°C/350°F/Gas Mark 4. Measure all the ingredients into a mixing bowl and beat for about 2 minutes, until well blended; an electric mixer is best for this but of course you can also beat by hand with a wooden spoon.</p>
<p class="step step--2">Spoon the mixture into the prepared tin and level the surface. Bake for about 1 hour, until well risen and golden brown. A fine skewer inserted in the centre of the cake should come out clean.</p>
<p class="step step--3">Leave the cake to cool in the tin for a few minutes, then loosen with a small palette knife and turn the cake out. Remove the lining paper and leave on a wire rack to cool completely. Slice thickly to serve.</p>
</div>
</div>
body {
background: #ee9ca7; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #ffdde1, #ee9ca7); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #ffdde1, #ee9ca7); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
height: 100vh;
font-family: 'Rubik', sans-serif;
}
.wrapper {
width: 375px;
height: 600px;
background: white;
overflow: hidden;
margin: 4em auto;
position: relative;
box-shadow: 15px 14px 12px -12px rgba(77,76,77,1);
}
h3 {
font-family: "Abril Fatface", cursive;
}
.page {
position: absolute;
z-index: 2;
padding: 0 2em;
top: 0;
height: 600px;
max-width:100%;
}
h3 {
padding-bottom: 1em;
border-bottom: 4px solid rgba(143, 215, 229, 1);
}
.cover {
z-index: 1;
display: flex;
align-items: flex-end;
background: linear-gradient(to bottom, transparent 70%, rgba(143, 215, 229, 0.75) 45%);
h1 {
font-family: "Abril Fatface", cursive;
position: absolute;
top: 0;
display: flex;
width: 100%;
justify-content: center;
}
h2 {
display: block;
position: absolute;
bottom: 20%;
color: white;
padding: 0.3em 0;
margin-bottom: 0;
}
p {
margin-top: - 20px;
color: white;
}
}
.image {
position: absolute;
width: 100%;
top: 0;
}
.intro {
height: 110%;
background: white;
padding-top: 20px;
}
.stats {
margin-top: 2em;
padding: 0;
}
.stat {
list-style: none;
display: grid;
align-items: center;
margin-bottom: 20px;
grid-template-columns: 0.1fr 0.7fr 1fr;
justify-content: left;
font-weight: 600;
color: rgba(143, 215, 229, 1);
padding-bottom: 1em;
padding-top: 1em;
span {
font-weight: 400;
color: black;
}
&::before {
height: 25px;
width: 25px;
content: '';
display: inline-block;
margin-right: 1em;
}
}
.level {
&::before {
content: url('https://img.icons8.com/color/25/000000/chef-hat.png');
}
}
.prep {
&::before {
content: url('https://img.icons8.com/dusk/25/000000/knife.png');
}
}
.cook {
&::before {
content: url('https://img.icons8.com/ultraviolet/25/000000/cooker.png');
}
}
.total {
&::before {
content: url('https://img.icons8.com/ultraviolet/25/000000/time.png');
}
}
.ingredients {
background: white;
width: 100%;
padding: 0;
h3 {
margin: 2em;
}
.ingredient {
display: grid;
grid-template-columns: 0.3fr 1fr;
grid-column-gap: 3em;
margin: 0 2em;
p {
align-self: center;
}
&--amount {
background-color: #90d7e5;
padding: 0.5em;
display: flex;
align-items: center;
text-align: center;
font-weight: 800;
display: inline-block;
border-radius: 15px;
color: white;
}
}
}
.kit {
background: white;
h3 {
margin: 2em 0;
}
}
.instructions {
background: white;
h3 {
margin: 2em 0;
}
}
const pages = ["cover", "intro", "ingredients", "kit", "instructions"];
const element = document.getElementById("wrapper");
document.onclick = inputChange;
function inputChange(e) {
const pageWidth = element.clientWidth;
const leftHand = pageWidth / 2;
const clickLocation = e.clientX;
const currentPage = pages.find(function(element, index) {
if (document.getElementById(element).matches(".page")) {
return element
}
});
const nextPage = pages.indexOf(currentPage) + 1;
const previousPage = pages.indexOf(currentPage) - 1;
if (clickLocation >= leftHand) {
if(pages.indexOf(currentPage) < pages.length - 1) {
document.getElementById(currentPage).classList.remove('page')
document.getElementById(pages[nextPage]).classList.add('page')
}
console.log("Right Click");
}
else if (clickLocation < leftHand) {
console.log("Left");
if(pages.indexOf(currentPage) > 0 ) {
document.getElementById(currentPage).classList.remove('page')
document.getElementById(pages[previousPage]).classList.add('page')
}
}
}
// pages.some(function(element, index) {
// if (document.getElementById(element).matches(".page")) {
// if (index < pages.length - 1 ) {
// document.getElementById(element).classList.remove('page')
// document.getElementById(pages[index + 1]).classList.add('page')
// console.log(element, 'ran')
// }
// else {
// console.log('end')
// }
// }
// });
Also see: Tab Triggers