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="slideContainer">
<div class="bubble"></div>
<div class="slider">
<div class="slide-viewer">
<div class="slide-group">
<div class="slide slide-1"><h3>Lorem ipsum</h3></div>
<div class="slide slide-2"><h3>dolor sit amet,</h3></div>
<div class="slide slide-3"><h3>consectetuer</h3></div>
<div class="slide slide-4"><h3>adipiscing elit</h3></div>
</div>
</div>
<div class="slide-buttons"></div>
</div>
</div>
body, html{
margin: 0px;
background: #ccc;
}
.slideContainer{
position: relative;
left: 25px;
top: 25px;
width: 500px;
height: 300px;
}
.slider {
position: absolute;
width: 400px;
height: 200px;
border: 2px solid black;
border-radius: 10px;
overflow: hidden;
z-index: 0;
}
.slide-viewer {
position: relative; /* needed for IE7 */
overflow: hidden;
height: 200px;
}
.slide-group {
width: 100%;
height: 100%;
position: relative;
}
.slide {
width: 100%;
height: 100%;
display: none;
position: absolute;
background: white;
}
.slide:first-child {
display: block;
}
.slide-buttons {
text-align: center;
}
.slide-btn {
position: relative;
bottom: 190px;
border: none;
background: none;
color: #ccc;
font-size: 200%;
line-height: 0.5em;
}
.slide-btn.active, .slide-btn:hover {
color: #000;
cursor: pointer;
}
h3{
position: relative;
text-align: center;
font: bold 64px 'Dancing Script';
}
.bubble{
position: absolute;
top: 20px;
left: 20px;
width: 400px;
height: 200px;
background: black;
border-radius: 10px;
}
.bubble:before{
content:"";
position: relative;
top: 274px;
left: 200px;
width: 0px;
height: 0px;
border-top: 75px solid black;
border-left: 75px solid transparent;
}
.bubble:after{
content:"";
position: relative;
z-index: 999 !important;
top: 256px;
left: 120px;
width: 0px;
height: 0px;
border-top: 75px solid white;
border-left: 75px solid transparent;
}
$('.slider').each(function() { // For every slider
var $this = $(this); // Current slider
var $group = $this.find('.slide-group'); // Get the slide-group (container)
var $slides = $this.find('.slide'); // Create jQuery object to hold all slides
var buttonArray = []; // Create array to hold navigation buttons
var currentIndex = 0; // Hold index number of the current slide
var timeout; // Sets gap between auto-sliding
function move(newIndex) { // Creates the slide from old to new one
var animateLeft, slideLeft; // Declare variables
advance(); // When slide moves, call advance() again
// If it is the current slide / animating do nothing
if ($group.is(':animated') || currentIndex === newIndex) {
return;
}
buttonArray[currentIndex].removeClass('active'); // Remove class from item
buttonArray[newIndex].addClass('active'); // Add class to new item
if (newIndex > currentIndex) { // If new item > current
slideLeft = '100%'; // Sit the new slide to the right
animateLeft = '-100%'; // Animate the current group to the left
} else { // Otherwise
slideLeft = '-100%'; // Sit the new slide to the left
animateLeft = '100%'; // Animate the current group to the right
}
// Position new slide to left (if less) or right (if more) of current
$slides.eq(newIndex).css( {left: slideLeft, display: 'block'} );
$group.animate( {left: animateLeft}, function() { // Animate slides and
$slides.eq(currentIndex).css( {display: 'none'} ); // Hide previous slide
$slides.eq(newIndex).css( {left: 0} ); // Set position of the new item
$group.css( {left: 0} ); // Set position of group of slides
currentIndex = newIndex; // Set currentIndex to the new image
});
}
function advance() { // Used to set
clearTimeout(timeout); // Clear previous timeout
timeout = setTimeout(function() { // Set new timer
if (currentIndex < ($slides.length - 1)) { // If slide < total slides
move(currentIndex + 1); // Move to next slide
} else { // Otherwise
move(0); // Move to the first slide
}
}, 4000); // Milliseconds timer will wait
}
$.each($slides, function(index) {
// Create a button element for the button
var $button = $('<button type="button" class="slide-btn">•</button>');
if (index === currentIndex) { // If index is the current item
$button.addClass('active'); // Add the active class
}
$button.on('click', function() { // Create event handler for the button
move(index); // It calls the move() function
}).appendTo('.slide-buttons'); // Add to the buttons holder
buttonArray.push($button); // Add it to the button array
});
advance(); // Script is set up, advance() to move it
});
Also see: Tab Triggers