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.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Facebook Dimensions</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:500|Open+Sans:400,600" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<style>
body {font-family: 'Open Sans', 'Segoe UI'; padding-top: 75px;}
.navbar-brand,
h1, h2, h3, h4, h5, h6 {font-family: 'Montserrat'; font-weight: 500;}
.dim-form .panel-body input,
.dim-form .panel-body button {width: 50px; display: inline-block; vertical-align: middle;}
.dim-form .panel-body button {width: auto; line-height: 1.5; position: relative; top: 1px; margin-left: 20px;}
h2 {margin: 0 0 15px; font-size: 1.5em;}
</style>
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
$(function () {
// Hide the CSS hidden elements by JavaScript.
$(".hidden").hide().removeClass("hidden");
// Reset the layout to initial one.
var resetLayout = function () {
$(".dim-need, .dim-cons").fadeOut(function () {
$(".dim-need .list-group, .dim-cons .list-group").empty();
$(".dim-form").addClass("col-sm-offset-4");
});
};
// Display the error message and reset the layout if found an error.
var error = function (msg) {
if (msg.length !== 0) {
$(".alert-danger").text(msg).fadeIn();
resetLayout();
}
else
$(".alert-danger").fadeOut(function () {
$(this).text("");
});
}
// Calculate the proportions.
var prop = function (dim) {
if (!!dim.x) {
var y = 630 / 1200 * dim.x;
return (dim.x.toFixed(2) + " × " + y.toFixed(2));
}
if (!!dim.y) {
var x = 1200 / 630 * dim.y;
return (x.toFixed(2) + " × " + dim.y.toFixed(2));
}
}
// Display the list of proportional dimensions.
var display = function (x, y) {
var need = [];
var cons = [];
need.push(prop({x: x}));
need.push(prop({y: y}));
need = need.filter(function (value, index, self) {
return self.indexOf(value) === index;
}).filter(function (v) { return v !== undefined });
$(".dim-need .list-group, .dim-cons .list-group").empty();
need.forEach(function (v) {
$(".dim-need .list-group").append('<li class="list-group-item">' + v + "</li>");
});
cons.push(prop({x: getRound(x, 1)}));
cons.push(prop({y: getRound(y, 1)}));
cons.push(prop({x: getRound(x, 2)}));
cons.push(prop({y: getRound(y, 2)}));
cons = cons.filter(function (value, index, self) {
return self.indexOf(value) === index && need.indexOf(value) === -1;
}).filter(function (v) { return v !== undefined });
if (cons.length)
cons.forEach(function (v) {
$(".dim-cons .list-group").append('<li class="list-group-item">' + v + "</li>");
});
else
$(".dim-cons .list-group").append('<li class="list-group-item">Sorry, nothing here.</li>');
}
// Get the rounded value.
var getRound = function (n, p) {
if (!p)
p = 1;
var t = Math.pow(10, p);
if (n % t === 0)
return n;
else
return parseInt(n / t) * t;
}
// Calculate the proportion.
var calculate = function () {
var strX = $("#dim-x").val().trim();
var strY = $("#dim-y").val().trim();
var origX = parseInt(strX, 10);
var origY = parseInt(strY, 10);
if (strX === "" && strY === "") {
error("You need to provide at least one value!");
return false;
}
if ((strX !== "" && isNaN(origX)) || (strY !== "" && isNaN(origY))) {
error("Given values should be integers!");
return false;
}
var finX = isNaN(origX) ? null : origX;
var finY = isNaN(origY) ? null : origY;
error("");
$(".dim-form").removeClass("col-sm-offset-4");
display(finX, finY);
$(".dim-need, .dim-cons").fadeIn();
return false;
};
// Event listeners.
$("#dim-x, #dim-y").keyup(function (e) {
if (e.keyCode === 13)
calculate();
});
$("#btn-c").click(calculate);
});
</script>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Facebook Dimensions</a>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<h2>What is this tool about?</h2>
<p>This is a quick helper tool for getting the right dimensions for your post's image. Facebook requires the previews to be in proportion of 1200 × 630 for a full size share. This tool helps you to set one of the dimension with the other not modified with respect to your image.</p>
<div class="alert alert-danger text-center hidden"></div>
</div>
<div class="col-sm-4 dim-form col-sm-offset-4">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Original Image Dimensions</h3>
</div>
<div class="panel-body text-center">
<input type="text" class="form-control input-sm text-center" id="dim-x" placeholder="X" /> ×
<input type="text" class="form-control input-sm text-center" id="dim-y" placeholder="Y" />
<button type="button" class="btn btn-primary btn-sm" id="btn-c">Calculate</button>
</div>
</div>
</div>
<div class="col-sm-4 dim-need hidden">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Dimensions you Need</h3>
</div>
<ul class="list-group text-center"></ul>
</div>
</div>
<div class="col-sm-4 dim-cons hidden">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Considerable Dimensions</h3>
</div>
<ul class="list-group text-center"></ul>
</div>
</div>
</div>
</div>
</body>
</html>
Also see: Tab Triggers