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 id="container">
<h1 class="with-pointer">This is a Title</h1>
<h1 class="with-pointer pointer-top">This is a Different Pointer Title</h1>
<h1>This is a Title Without a Pointer</h1>
<h2 class="with-pointer">Yeah, you can use with (almost) any tag</h1>
<div class="with-pointer">Of Course!</div>
<h3 class="with-pointer">Another Title</h3>
<h1 class="with-pointer">Also works with long titles without any problem</h3>
<h1 class="with-pointer pointer-top">Also works with long titles with .pointer-top class</h3>
<p class="with-pointer">Feel free to use/fork. But don't forget to thank <a href="https://www.behance.net/dilaraedipbalkir" target="_blank">Dilara</a> for this idea.</p>
</div>
html {
font-size: 10px;
height: 100%;
}
body {
font-family: 'Open Sans Condensed', sans-serif;
margin: 0;
color: #efefef;
background: #232323;
font-size: 1.33rem;
display: flex;
align-items: center;
justify-content: center;
height: 100%;
min-height: 40rem;
}
h1 {
text-transform: uppercase;
font-size: 4rem;
}
h2 {
font-size: 3rem;
}
h3 {
font-size: 2rem;
}
h1,h2,h3,h4,h5 {
font-weight: normal;
}
#container {
width: 51rem;
height: 35rem;
overflow: auto;
padding-left: 2rem;
border-left: 1px solid white;
}
.transition {
transition: .33s ease-out;
}
.with-pointer > .pointer {
position: absolute;
border-radius: .8rem;
width: 1.5rem;
height: 1.5rem;
left: 0;
top: 0;
box-sizing: border-box;
border: .4rem solid rgba(255, 255, 255, .5);
background: #fff;
background-clip: padding-box;
transition-property: transform;
will-change: top, left;
}
.pointer:hover {
transform: scale(1.33);
cursor: pointer;
}
.pointer.init {
transform: scale(0);
}
a:link, a:visited {
color:white;
font-weight: bold;
text-decoration: none;
font-size: 1.5rem
}
/* I really like to use rem values, don't I? */
$(document).ready(function(e) {
/*
Variables
*/
var FS = parseFloat($('html').css('font-size')),
container = $('#container'),
withPointers = $('.with-pointer'),
pointerTop = 0,
pointerLeft = 0,
pointerBottom = 0;
/*
Functions
*/
// This updates the limit values for the pointers
function calculatePointerVariables() {
pointerTop = container.offset().top;
pointerBottom = container.offset().top + container.outerHeight();
pointerLeft = container.offset().left;
withPointers.each(function(i) {
handlePointerPosition($(this), true, i);
});
}
// This moves a pointer (elm),
// and removes .init if this is for the initial positioning (isInıt)
// and uses pointer's index number (idx, not required)
function handlePointerPosition(elm, isInit, idx) {
var pointer = elm.children('.pointer'),
outerH = pointer.get(0).offsetHeight,
outerW = pointer.get(0).offsetWidth,
atTop = elm.hasClass('pointer-top');
// If there is no idx, find it for this elm pointer.
if(idx == undefined) idx = withPointers.index(elm);
// Calculate maximum points and new top value (and if this has a .pointer-top move it up a little bit)
var thisMaxTop = pointerTop + (idx * (outerH + FS / 3)),
thisMaxBottom = pointerBottom - ((withPointers.length - 1 - idx) * (outerH + FS / 3) + outerH),
newTop = elm.offset().top + (!atTop ? elm.height() / 2 - outerH / 2 : outerH);
// Clamp the new top value between max top/bottom values
newTop = Math.clamp(newTop, thisMaxTop, thisMaxBottom);
pointer.css({
'top': newTop,
'left': pointerLeft - outerW/2
});
// So, you say, all these calculations were for the initial position? OK, let me handle that, so you can see the pointers (with a little effect)
if(isInit) {
setTimeout(function() {
pointer.removeClass('init');
}, (idx * 67) + 10);
}
}
/*
Events
*/
// Yeah, the pointers will be updated on scrolling
container.on('scroll', function(e) {
withPointers.each(function() {handlePointerPosition($(this));});
});
// Resize? No problemo! This'll take care of everything.
$(window).on('resize', function() {
// First, set pointers to theirs .init
withPointers.children('.pointer').addClass('init');
// Then, calculate new values
setTimeout(function() {calculatePointerVariables();}, 555);
});
// Listen for a .pointer click to scroll to it's parent.
$(this).on('click', '.pointer', function() {
var t = $(this),
parent = t.closest('.with-pointer');
container.animate({
scrollTop: parent.position().top - container.position().top + container.scrollTop() + parseInt(parent.css('margin-top'))
});
});
/*
Init
*/
// Prepare .with-pointers' pointers
withPointers.renderPointer();
// Just wait a little for the init
setTimeout(function(){calculatePointerVariables();}, 195);
});
// This looks so cool!
$.fn.renderPointer = function() {
this.each(function() {
var t = $(this);
if(t.find('.pointer').length == 0) {
t.prepend('<div class="pointer transition init" title="' + t.text() + '"></div>');
}
});
};
/*
Clamping function
*/
(function() {
Math.clamp = function(a, b, c) {
return Math.max(b, Math.min(c, a));
}
})();
Also see: Tab Triggers