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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<h1>Flourish popup</h1>
<p>Mouse over the box below. The popup bubble should always remain within the box, and the arrow be pointing in one of the eight compass directions.</p>
<div class="test" id="test1"></div>
<p>This tests the behaviour when there is a lot of text in the popup. When the mouse is near the middle of the box, the bubble cannot be accommodated completely within it. The arrow should again always point in one of the eight compass directions, and the bubble should never overlap the box horizontally, only vertically.</p>
<div class="test" id="test2"></div>
<p>This tests the behaviour when there is so much text in the popup that it cannot be accommodated within the container at all. In this case the box should protrude outside the box vertically but not horizontally, and the arrow should slide along the edges of the box to fit it in as well as possible.</p>
<div class="test" id="test3"></div>
<p>This is the same as the previous test, except that the box should protrude horizontally but not vertically.</p>
<div class="test" id="test4"></div>
<p>This popup box should always point upwards.</p>
<div class="test" id="test5"></div>
<p>This popup box should always point to the right.</p>
<div class="test" id="test6"></div>
<p>This popup box should always point down.</p>
<div class="test" id="test7"></div>
<p>This popup box should always point left.</p>
<div class="test" id="test8"></div>
<p>This popup box should point right or left.</p>
<div class="test" id="test9"></div>
<p>This popup should point within the smaller box.</p>
<div class="test" id="test10">
<div class="inner"></div>
</div>
<p>This popup should have a black background and white text.</p>
<div class="test" id="test11"></div>
<p>This popup should be translucent.</p>
<div class="test" id="test12"></div>
body { width: 800px; margin: auto; font-family: sans-serif; }
.test { height: 300px; width: 600px; border: 1px solid red; margin: 24px; cursor: crosshair; }
.flourish-popup { pointer-events: none; }
#test10 { position: relative; }
#test10 .inner { position: absolute; left: 50px; right: 50px; top: 50px; bottom: 50px; background: #ccc; }
#flourish-popup-11 .flourish-popup-svg g { fill: rgba(0,0,0,0.9); }
#flourish-popup-11 .flourish-popup-content { color: white; }
#flourish-popup-12 .flourish-popup-svg g { opacity: 0.6; }
function test(id, text_template, callback) {
var el = document.getElementById(id);
if (!el) return console.error("Element not found: #" + id);
var popup = Popup().container(el);
if (callback) callback(popup);
el.onmousemove = function(e) {
var x = e.clientX, y = e.clientY;
popup.point(x, y).html(text_template(x, y)).draw();
};
el.onmouseout = function(e) {
popup.hide();
};
}
function muchText(n) {
var much_text = "";
for (var i = 0; i < n; i++) {
much_text += "This is some additional text to fill up the bubble. ";
}
return function(x, y) {
return "Mouse at (" + x + "," + y + "). " + much_text;
};
}
var much0 = muchText(0), much4 = muchText(4),
much8 = muchText(8), much15 = muchText(15);
test("test1", much0);
test("test2", much8, function(popup) {
popup.maxWidth("60%");
});
test("test3", much15);
test("test4", much15, function(popup) {
popup.fallbackFit("vertical");
});
test("test5", much15, function(popup) {
popup.directions(["bottomFlexible"]);
});
test("test6", much15, function(popup) {
popup.directions(["leftFlexible"]);
});
test("test7", much15, function(popup) {
popup.directions(["topFlexible"]);
});
test("test8", much15, function(popup) {
popup.directions(["rightFlexible"]);
});
test("test9", much15, function(popup) {
popup.directions(["leftFlexible", "rightFlexible"]);
});
test("test10", much8, function(popup) {
popup.container(
document.querySelector("#test10 .inner")
);
});
test("test11", much4);
test("test12", much4, function(popup) {
popup.directions(["right"]);
});
Also see: Tab Triggers