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.
%header
.wrapper
%div.logo
%h1
Gross Domestic
%strong Product
%nav
%ul
%li
%a.active{:href => '#timeline'}
Chart
%li
%a{:href => '#about'}
About GDP
.wrapper
%aside.feature#chartfeature
%h4#timeline
%h3#charttitle
.table-responsive
.chart
%main
.wrapper
%section#about
%h2 About the GDP
%p.lead Gross domestic product (GDP) is a monetary measure of the market value of all final goods and services produced in a period (quarterly or yearly) of time. Nominal GDP estimates are commonly used to determine the economic performance of a whole country or region, and to make international comparisons. Nominal GDP per capita does not, however, reflect differences in the cost of living and the inflation rates of the countries; therefore using a basis of GDP per capita at purchasing power parity (PPP) is arguably more useful when comparing differences in living standards between different nations.
<small>—Wikipedia</small>
%footer
%p
Made with ♥ by
%a{:href => 'https://satinflame.com', :target=> '_blank'}
satinflame design
* {
box-sizing: border-box;
}
body,
html {
padding: 0;
margin: 0;
}
$base-font-size: 18px;
$heading-scale: 8;
$color-primary: #009688;
$color-primary-light: #52c7b8;
$color-primary-dark: #00675b;
$color-secondary: #8e24aa;
$color-secondary-light: #c158dc;
$color-secondary-dark: #5c007a;
* {
font-family: "Open Sans", sans-serif;
}
@for $i from 1 through 6 {
h#{$i} {
font-size: $base-font-size + $heading-scale * (4 - $i);
font-family: "Oswald", sans-serif;
color: $color-primary;
font-weight: 400;
}
}
h1 {
border: 1px solid $color-primary-dark;
display: inline-block;
padding-left: 0.5rem;
margin: 0;
font-size: 2rem;
background: #fff;
strong {
font-family: inherit;
margin-left: 10px;
background: $color-primary;
color: #fff;
padding-left: 0.5rem;
padding-right: 0.5rem;
float: right;
}
}
header {
background: #f6f6f6;
padding: 8px;
.wrapper {
display: flex;
}
div.logo,
nav {
flex: 1;
}
}
.wrapper {
max-width: 900px;
margin: 0 auto;
}
div.logo {
padding: 15px;
}
nav {
margin: 0;
padding-right: 15px;
ul {
float: right;
padding: 0;
}
ul,
li {
display: inline;
}
a {
color: $color-secondary;
cursor: pointer;
padding: 8px;
display: inline-block;
text-decoration: none;
&:hover {
background: $color-secondary-dark;
color: #fff;
}
}
a.active {
border-bottom: 3px solid $color-secondary-light;
}
}
@media (max-width: 767px) {
header .wrapper {
flex-direction: column;
text-align: center;
padding: 8px 15px;
}
nav {
padding-top: 15px;
}
nav ul {
float: none;
}
}
main {
h2 {
display: inline-block;
&:after {
border-bottom: solid 0.1em $color-secondary-light;
display: block;
margin-left: 1rem;
margin-right: -1rem;
content: "";
}
}
}
main {
.wrapper {
display: flex;
flex-direction: row;
section,
aside {
flex: 1;
padding: 1rem;
}
}
}
.chart {
border: 1px solid $color-primary;
padding: 5px 5px 0;
margin: 0;
}
.chart div {
background-color: $color-secondary-light;
padding: 0.5px;
cursor: pointer;
display: inline-block; // magic for vert chart
&:hover {
background-color: $color-secondary;
}
}
.tag { display:none; position: absolute; font-size: .8rem; padding: 3px 8px; background:rgba(98, 23, 117, 0.8); }
.tag strong { font-size: .9rem;}
.tag strong:after { content: ""; display:block; clear:both;}
.chart div:hover .tag { display:block;}
aside.feature {
margin-top: 1rem;
background: $color-primary-dark;
color: #fff;
padding: 1rem;
h2,
h3 {
margin: 0;
color: #fff;
}
h4 {
text-align: right;
margin: 0;
color: $color-primary-light;
}
small {
font-size: 0.9rem;
line-height: 1.3;
display: block;
padding: 3px 0 8px 0;
}
}
footer {
text-align: center;
padding: 10px 20px;
margin-top: 1rem;
background: $color-secondary-dark;
color: #fff;
font-size: 0.8rem;
a {
color: lighten($color-secondary-light, 20);
}
}
// Thanks to https://codepen.io/jasonadelia/pen/DnrAe
.chart {
background-image: linear-gradient(0deg, transparent 24%, rgba(255, 255, 255, .05) 25%, rgba(255, 255, 255, .05) 26%, transparent 27%, transparent 74%, rgba(255, 255, 255, .05) 75%, rgba(255, 255, 255, .05) 76%, transparent 77%, transparent), linear-gradient(90deg, transparent 24%, rgba(255, 255, 255, .05) 25%, rgba(255, 255, 255, .05) 26%, transparent 27%, transparent 74%, rgba(255, 255, 255, .05) 75%, rgba(255, 255, 255, .05) 76%, transparent 77%, transparent);
height:100%;
background-size:50px 50px;
}
let model = {
i: 0,
chartMax: 0
};
let controller = {
init: function() {
let d = {};
this.getData();
},
getData: function() {
var myD;
var XHR = new XMLHttpRequest();
XHR.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myData = JSON.parse(this.responseText);
controller.loadChart(myData);
}
};
XHR.open(
"GET",
"https://raw.githubusercontent.com/FreeCodeCamp/ProjectReferenceData/master/GDP-data.json"
);
XHR.send();
},
loadChart: function(obj) {
let i = model.i;
this.setMax(this.findMax(obj.data));
let chartScale = d3
.scaleLinear()
.domain([0, model.chartMax])
.range([0, 300]); // second # controls height
document.getElementById("charttitle").innerHTML = `${obj.name} <small>${
obj.description
}</small>`;
document.getElementById("timeline").innerHTML = `${showMonth(
obj.from_date
)} - ${showMonth(obj.to_date)}`;
let barH = 100 / obj.data.length;
d3
.select(".chart")
.selectAll("div")
.data(obj.data)
.enter()
.append("div")
.style("height", d => chartScale(Math.floor(d[1])) + "px")
.style("width", barH + "%")
// .attr("title", function(d) {
// return `${showMonth(d[0])} (${d[1]})`;
// })
.html(function(d) {
return `<span class="tag"><strong>${getAmount(d[1])}</strong> ${showMonth(d[0])}</span>`
})
;
// this.incrementChart(); // for multi charts
},
findMax: function(arr) {
let max = model.chartMax;
let m = arr.forEach(e => {
if (e[1] > max) {
max = e[1];
}
});
return max;
},
setMax: function(num) {
model.chartMax = num;
},
incrementChart: function() {
model.i++;
}
};
controller.init();
function showMonth(timestamp) {
let time = new Date(timestamp);
return getMonthLabel(time.getUTCMonth()) + " " + time.getUTCFullYear();
}
function getMonthLabel(num) {
var month = new Array();
month[0] = "Jan";
month[1] = "Feb";
month[2] = "Mar";
month[3] = "Apr";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "Aug";
month[8] = "Sept";
month[9] = "Oct";
month[10] = "Nov";
month[11] = "Dec";
return month[num];
}
function getAmount(val) {
return "$"+val.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,') + " billion";
}
Also see: Tab Triggers