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">
<h3>Arrow Box with CSS </br><span style="font-size: 80%; color:#999">(12 positions)</span></h3>
<!-- the boxes -->
<div id="boxContainer"></div>
</div>
@import "nib"
// Some styles besides the box with arrow
@import url(https://fonts.googleapis.com/css?family=Open+Sans);
// Variables
$blue = #3498db
$green = #1abc9c
$orange = #e67e22
$red = #e74c3c
$default-color= $blue
$box-width = 150px
$box-height = 100px
$border-width = 10px
/////////////////////////////////////
// Main styles for box with arrows //
/////////////////////////////////////
.box
width: $box-width
height: $box-height
background-color:$default-color // default background color
position: relative
border-radius: 4px
&:after
content: ""
display: block
border-width: $border-width $border-width 0
border-style: solid
border-color: @background-color transparent transparent
margin-left: - @border-width
position: absolute
bottom: - @border-width
left: 50%
&.arrow-bottom-left,
&.arrow-bottom-right,
&.arrow-top-left,
&.arrow-top-right,
&.arrow-left-top,
&.arrow-left-bottom,
&.arrow-right-top,
&.arrow-right-bottom
&:after
border-width: $border-width * 0.5
margin: 0
// Bottom Arrows
&.arrow-bottom-left,
&.arrow-bottom-right
&:after
border-left-color: @background-color
&.arrow-bottom-left
&:after
left: 0
right: auto
&.arrow-bottom-right
&:after
border-left-color: transparent
border-right-color: @background-color
left: auto
right: 0
// Top Arrows
&.arrow-top-center,
&.arrow-top-left,
&.arrow-top-right
&:after
border-top-color: transparent
border-bottom-color: @background-color
top: - $border-width
bottom: auto
&.arrow-top-center
&:after
border-top-width: 0
border-bottom-width: $border-width
&.arrow-top-left,
&.arrow-top-right
&:after
border-width: $border-width * 0.5
border-left-color: @background-color
&.arrow-top-left
&:after
left: 0
right: auto
&.arrow-top-right
&:after
border-left-color: transparent
border-right-color: @background-color
left: auto
right: 0
// Left Arrows
&.arrow-left-center,
&.arrow-left-top,
&.arrow-left-bottom
&:after
border-width: $border-width
border-left-color: transparent
border-left-width: 0
border-top-color: transparent
border-right-color: @background-color
margin: - $border-width 0 0
left: - $border-width
right: auto
top: 50%
bottom: auto
&.arrow-left-top,
&.arrow-left-bottom
&:after
border-width: $border-width * 0.5
margin: 0
&.arrow-left-top
&:after
border-top-color: @background-color
top: 0
&.arrow-left-bottom
&:after
border-bottom-color: @background-color
top: auto
bottom: 0
// Right Arrows
&.arrow-right-center,
&.arrow-right-top,
&.arrow-right-bottom
&:after
border-width: $border-width
border-right-width: 0
border-top-color: transparent
border-left-color: @background-color
margin: - $border-width 0 0
left: auto
right: - $border-width
top: 50%
bottom: auto
&.arrow-right-top,
&.arrow-right-bottom
&:after
border-width: $border-width * 0.5
margin: 0
&.arrow-right-top
&:after
border-top-color: @background-color
top: 0
&.arrow-right-bottom
&:after
border-bottom-color: @background-color
top: auto
bottom: 0
// Border radius
&.arrow-bottom-left,
&.arrow-left-bottom
border-bottom-left-radius: 0
&.arrow-bottom-right,
&.arrow-right-bottom
border-bottom-right-radius: 0
&.arrow-top-left,
&.arrow-left-top
border-top-left-radius: 0
&.arrow-top-right,
&.arrow-right-top
border-top-right-radius: 0
////////////////////////////////////
// Styles only for this test page //
////////////////////////////////////
// Stylus function to create alternative colors
createOtherColors(class, color) {
&.{class} {
background-color: color
&.arrow-bottom-center,
&.arrow-bottom-left,
&.arrow-bottom-right {
&:after {
border-top-color: color
}
}
&.arrow-bottom-left {
&:after {
border-left-color: color
}
}
&.arrow-bottom-right {
&:after {
border-right-color: color
}
}
&.arrow-top-center,
&.arrow-top-left,
&.arrow-top-right {
&:after {
border-bottom-color: color
}
}
&.arrow-top-left {
&:after {
border-left-color: color
}
}
&.arrow-top-right {
&:after {
border-right-color: color
}
}
&.arrow-left-center,
&.arrow-left-top,
&.arrow-left-bottom {
&:after {
border-right-color: color
}
}
&.arrow-left-top {
&:after {
border-top-color: color
}
}
&.arrow-left-bottom {
&:after {
border-bottom-color: color
}
}
&.arrow-right-center,
&.arrow-right-top,
&.arrow-right-bottom {
&:after {
border-left-color: color
}
}
&.arrow-right-top {
&:after {
border-top-color: color
}
}
&.arrow-right-bottom {
&:after {
border-bottom-color: color
}
}
}
}
html, body
background: #f5f5f5
font-size: 100%
font-family: 'Open Sans', sans-serif
width: 100%
h3
position: relative
text-align: center
text-transform: uppercase
width: 240px
display: block
margin: 20px auto
h3:before, h3:after
content: ""
display: block
height: 1px
width: 50px
background-color: #ddd
position: absolute
top: 50%
left: -60px
h3:after
right: -60px
left: auto
.box
margin: 20px 10px
float: left
createOtherColors("blue", $blue)
createOtherColors("green", $green)
createOtherColors("orange", $orange)
createOtherColors("red", $red)
var CLASS_NAME_LOOKUP = {
"bottom center": "",
"bottom left": "arrow-bottom-left",
"bottom right": "arrow-bottom-right",
"top center": "arrow-top-center",
"top left": "arrow-top-left",
"top right": "arrow-top-right",
"left center": "arrow-left-center",
"left top": "arrow-left-top",
"left bottom": "arrow-left-bottom",
"right center": "arrow-right-center",
"right top": "arrow-right-top",
"right bottom": "arrow-right-bottom"
};
var BOX_BG_CLASS = ["blue", "green", "orange", "red"];
(function (){
var targetNode = document.getElementById("boxContainer");
var boxesHTML = "";
var classNames = "";
var i = 0;
for(var pos in CLASS_NAME_LOOKUP){
classNames = "box " + BOX_BG_CLASS[Math.floor(i / 3)];
classNames += " " + CLASS_NAME_LOOKUP[pos];
//var div = document.createElement("div");
var div = "<div class='" + classNames + "'></div>";
boxesHTML += div;
++i;
}
targetNode.innerHTML = boxesHTML;
})();
Also see: Tab Triggers