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.
<main class='main'>
<section class='section section--one' id='section1'>
<div class='section__bg'></div>
<button class='button--close'>x</button>
<div class='section__content'>
<div class='section__bg image'></div>
<h2 class="section__title">Cras ornare tristique elit</h2>
<div class="section__content__body">
<p>Curabitur quis odio neque. Nulla ac ipsum felis. Suspendisse arcu libero, consequat id varius sed, suscipit non ipsum. Vivamus nec feugiat turpis, sed luctus metus. Vivamus vel libero id augue tempus aliquet. Vestibulum facilisis ante quis consectetur commodo. Praesent molestie odio vel varius rutrum. Proin eget magna a sapien accumsan bibendum et ac augue. Vivamus sed justo a nulla posuere eleifend. Duis ut vulputate risus. Proin mauris arcu, malesuada at dictum ut, pharetra sit amet orci. Donec rutrum porta libero nec aliquet. Vivamus dignissim tortor ut ipsum tempor, in fermentum ipsum rhoncus.</p>
</div>
</div>
</section>
<section class='section section--two is-active' id='section2'>
<div class='section__bg'></div>
<button class='button--close'>x</button>
<div class='section__content'>
<div class='section__bg image'></div>
<h2 class="section__title">Ut aliquam sollicitudin leo</h2>
<div class="section__content__body">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed fermentum molestie nisl. Aliquam suscipit sed ante a egestas. Suspendisse mi elit, porttitor id suscipit id, convallis ac massa. Nulla tincidunt, felis in tincidunt fermentum, ligula risus aliquet dolor, id vestibulum augue augue eu lacus. Mauris ornare ante erat, id pretium nisl faucibus vel. Praesent pellentesque dolor at porta consectetur. Pellentesque eget lacus scelerisque mauris volutpat maximus vel auctor nibh. Suspendisse quis lacus at orci ornare varius. Pellentesque tincidunt id ex sed fermentum. Cras eget urna ac arcu auctor tempor. Cras malesuada convallis faucibus.</p>
</div>
</div>
</section>
<section class='section section--three' id='section3'>
<div class='section__bg'></div>
<button class='button--close'>x</button>
<div class='section__content'>
<div class='section__bg image'></div>
<h2 class="section__title">Cras iaculis ultricies nulla</h2>
<div class="section__content__body">
<p>Cras nec ante in augue bibendum bibendum. Praesent pellentesque leo porttitor elementum gravida. Phasellus felis sem, interdum eu metus tempus, lacinia venenatis ligula. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus facilisis, ante sed efficitur porta, leo odio tempor erat, ac rhoncus sapien orci a tortor. Maecenas porttitor, mauris in vestibulum pharetra, tellus urna finibus lorem, id condimentum mi magna id erat. Nunc laoreet, neque nec varius aliquet, enim tortor facilisis magna, at dignissim nibh mi eu massa. Aliquam ultricies purus in lacus egestas, sit amet maximus lacus luctus. Pellentesque a nulla sed massa lacinia condimentum. Praesent sagittis venenatis nisi sit amet consequat. In venenatis purus risus, a tempus ligula euismod et. Fusce eu molestie quam, at vehicula massa. Praesent commodo risus sit amet nisi lacinia sagittis.</p>
</div>
</div>
</section>
<section class='section section--four' id='section4'>
<div class='section__bg'></div>
<button class='button--close'>x</button>
<div class='section__content'>
<div class='section__bg image'></div>
<h2 class="section__title">Vivamus molestie gravida turpis</h2>
<div class="section__content__body">
<p>Etiam nibh felis, malesuada nec nisi nec, luctus mattis risus. Vivamus id ipsum lacus. Morbi sed ligula id quam faucibus maximus vel nec ante. Donec sem risus, interdum a massa bibendum, accumsan dapibus felis. Vivamus non sem ullamcorper, pellentesque libero ut, maximus felis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec volutpat tincidunt dapibus. Sed et nunc cursus, pulvinar urna a, consectetur erat. Ut dignissim felis lobortis, consequat nibh ac, sagittis sem. Quisque id sodales tortor. Praesent lobortis elit ante, id bibendum lorem ornare eu. Duis quis mi sed velit interdum maximus. Nam venenatis libero quis arcu sagittis efficitur. Donec euismod mauris nec lacus ultrices sollicitudin. Suspendisse egestas purus vel scelerisque luctus.</p>
</div>
</div>
</section>
</main>
//---------------------------
// SECTIONS
//---------------------------
* {
box-sizing: border-box;
}
html {
background-color: #333;
}
body {
margin: 0 auto;
overflow: hidden;
}
$total-sections: 4;
$section-rotate: 11;
.clipped {
height: 100vh;
background-color: red;
background-image: url(https://images.pexels.com/photos/165875/pexels-photo-165875.jpeg?w=940&h=650&auto=compress&cs=tinysrgb);
-webkit-clip-path: polygon(25% 0%, 100% 0%, 75% 100%, 0 100%);
clip-path: polygon(25% 0%, 100% 0%, 75% 100%, 0 100%);
width: 25%;
float: left;
}
html {
font-size: 16px;
}
body {
overflow: hidden;
min-width: 1200px;
background-color: black;
font-family: 'Playfair Display', serif;
}
.main {
overflow: hidden;
position: relative;
height: 100vh;
display: flex;
flex-flow: row nowrap;
width: 100vw;
transition: all 0.05s ease-out;
}
.section {
flex: 1;
position: relative;
width: 100%;
overflow: hidden;
z-index: 1;
height: 100vh;
//transform: skewX(#{$section-rotate}deg) translateZ(0);
margin-right: -1px;
cursor: pointer;
transition: all 0.3s ease-out;
-webkit-clip-path: polygon(100px 0%, 100% 0%, 100% 100%, 0 100%);
clip-path: polygon(100px 0%, 100% 0%, 100% 100%, 0 100%);
margin-left: -11%;
&:first-child {
-webkit-clip-path: none;
}
&:last-child {
margin-right: -11%;
}
&__bg {
content: "";
position: absolute;
background-position: center;
background-size: auto 100%;
width: 100%;
left: 0;
height: 100vh;
width: 100%;
@media screen and (min-width: 1500px) {
background-size: cover;
}
}
&__content {
padding: 2rem;
width: 80%;
width: 20vw;
height: 100%;
z-index: 1;
display: flex;
flex-direction: column;
//align-items: center;
justify-content: center;
margin: auto;
position: absolute;
top: 0;
left: 18%;
color: black;
opacity: 0;
background: rgba(255,255,255,0.75);
&__body {
padding-left: calc(40% + 50px);
font-size: 18px;
line-height: 1.8;
padding-right: 50px;
}
}
&--one {
.section__bg {
background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/180245/food1.jpeg");
}
}
&--two {
.section__bg {
background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/180245/food2.jpeg");
}
}
&--three {
.section__bg {
background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/180245/food3.jpeg");
}
}
&--four {
.section__bg {
background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/180245/food4.jpeg");
}
}
&__title {
font-family: 'Cookie', cursive;
font-size: 100px;
text-align: left;
padding-left: 30%;
color: black;
text-shadow: 0px 0px 10px rgba(255,255,255,0.7);
margin: 0 0 30px;
}
}
.button {
&--close {
position: absolute;
top: 15px;
left: 15px;
background-color: transparent;
color: black;
border: none;
cursor: pointer;
z-index: 10;
padding: 10px;
transition: all 0.15s ease-out;
outline: 0;
&:hover,
&:focus {
transform: scale(1.2);
}
}
}
.image {
z-index: -1;
clip-path: polygon(10% 20%, 40% 20%, 40% 80%, 10% 80%);
}
// -------- on page load, hide content -------- //
$(document).ready(function() {
$('.section__content').fadeOut();
});
// -------- HOVERS -------- //
$(".section").mouseover(function() {
var $this = $(this);
var mouseOver = new TimelineMax();
mouseOver
.to($this, 0.15, {
css: {
flex: 1.3
},
ease: Linear.easeOut
})
}).mouseout(function() {
var $this = $(this);
var mouseOut = new TimelineMax();
mouseOut
.to($this, 0.15, {
css: {
flex: 1
},
ease: Linear.easeOut
})
});
// -------- CLICK TO EXPAND -------- //
$(".section").click(function(e) {
var button = $('.button--close');
if (!button.is(e.target)) {
$(this).removeClass('is-inactive').addClass('is-active').siblings().removeClass('is-active').addClass('is-inactive');
var $this = $(this),
$bg = $(this).find('.section__bg'),
$content = $(this).find('.section__content'),
$siblings = $(this).siblings(),
$main = $('.main');
$this.find('.button--close').fadeIn();
$content.fadeIn();
var activate = new TimelineMax();
activate
.to($siblings, 0.3, {
css: {
flex: 0,
},
ease: Linear.easeOut
}, 0)
.to($content, 0.3, {
css: {
width: '100%',
left: '0'
},
ease: Linear.easeOut
}, 0)
.to($content, 0.3, {
css: {
opacity: 1
},
ease: Linear.easeOut
}, 0.35)
.to($this, 0, {
css: {
position: 'static'
},
ease: Linear.easeOut
}, 0.45);
}
});
// -------- CLICK TO CLOSE -------- //
$(".button--close").click(function(e) {
var $this = $(this),
$sections = $('.section'),
$content = $('.section__content'),
$bg = $('.section__bg');
$this.fadeOut();
$content.fadeOut();
var deActivate = new TimelineMax();
deActivate
.to($sections, 0.3, {
css: {
flex: 1
},
ease: Linear.easeOut
}, 0)
.to($sections, 0.3, {
css: {
position: 'relative'
},
ease: Linear.easeOut
}, 0.15)
.to($content, 0.3, {
css: {
width: '20vw',
left: '18%'
},
ease: Linear.easeOut
}, 0.3)
.to($content, 0.25, {
css: {
opacity: 0
},
ease: Linear.easeOut
}, 0);
});
Also see: Tab Triggers