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.
<link href="https://fonts.googleapis.com/css?family=Fredoka+One" rel="stylesheet">
<div id="table" class="container"></div>
/*change in JS also*/
$tdHeight: 50px
@media(max-width: 520px)
td
font-size: 16px !important
th
font-size: 12px !important
#userName
width: 130px !important
#title
font-size: 18px !important
tr
height: $tdHeight
.rank
width: 60px !important
.table
background-color: lightgrey
max-width: 500px
font-family: 'Fredoka One', cursive
th
font-size: 14px
table
margin: 0px auto !important
td
color: black
position: relative
font-size: 22px
min-width: 2em !important
td a /*exclude the header bar*/
color: black
text-shadow: 2px 2px 1px white
position: relative
line-height: $tdHeight
padding-left: 5px
min-width: 6em !important
.data
margin-left: 5px
line-height: 40px
overflow: hidden
height: 100%
top: 0
bottom: 0
left: 0
right: 0
#userName
width: 250px !important
caption
text-align: center
font-size: 18px
.tdOverlay
position: absolute
background: rgba(211, 211, 211, 0.5)
height: 100%
width: 100%
libe-height: 20px
top: 0
bottom: 0
left: 0
right: 0
.panel
border: none
.panel:hover
background: Transparent
.panel:hover a
color: orange !important
text-shadow: 3px 3px 3px green
#title
background-color: lightgrey
font-size: 28px
body
background: linear-gradient(270deg, #018e06, #014f8e)
background-size: 400% 400%
animation: AnimationName 20s ease infinite
@keyframes AnimationName
0%
background-position: 0% 50%
50%
background-position: 100% 50%
100%
background-position: 0% 50%
//The two API calls store the data in these variables.
//This is so it doesn't have to do a new call each time
//the list is sorted.
var last30days = {};
var top100 = {};
var tdHeight = '50px'; //change in CSS also - image & tr height
//make a tag for each user with slots for the
//info from the stored objects
var User = React.createClass({
render: function() {
console.log(tdHeight);
return (
<tr>
<td className="rank"><div className="data">{this.props.rank}</div></td>
<td id="userName" style={
{backgroundImage: 'url(' + this.props.image + ')',
backgroundSize: tdHeight,
backgroundRepeat: 'no-repeat'}
}>
<div className="tdOverlay panel panel-default">
<a href={"https://freecodecamp.com/" + this.props.name} target="_blank">
{this.props.name}
</a>
</div>
</td>
<td><div className="data">{this.props.last30}</div></td>
<td><div className="data">{this.props.alltime}</div></td>
</tr>
);
}
});
//Loop through and add an entry for each user.
//This will be the main readerboard.
//The byTop30 state toggles which set of data
//to display.
var List = React.createClass({
getInitialState: function() {
return {byTop100: false};
},
sortByLast30: function() {
this.setState({byTop100: false});
},
sortByAllTime: function() {
this.setState({byTop100: true});
},
//Only build table after data is received
componentWillMount: function() {
//load data and build an array for each
$.ajax({ //get the best from the last 30 days
type: "GET",
url: "https://fcctop100.herokuapp.com/api/fccusers/top/recent",
contentType: "application/json; charset=utf-8",
async: false,
dataType: "json",
success: function(data) {
last30days = $.extend(true, [], data); //deep copy received data from {} to []
},
error: function() {
console.log("couldn't get data");
}
});
$.ajax({ //get the all-time top 100
type: "GET",
url: "https://fcctop100.herokuapp.com/api/fccusers/top/alltime",
contentType: "application/json; charset=utf-8",
async: false,
dataType: "json",
success: function(data) {
top100 = $.extend(true, [], data); //deep copy received data from {} to []
},
error: function() {
console.log("couldn't get data");
}
});
},
render: function() {
//sortBy is a reference to either top100 or last30days arrays
//theList is the user list
var theList = [], sortBy = [];
if(this.state.byTop100 === true) sortBy = top100;
else sortBy = last30days;
//add entry for each user
for(var i = 0, len = sortBy.length; i < len; ++i) {
theList.push(<User rank={i+1}
image={sortBy[i]["img"]}
name={sortBy[i]["username"]}
last30={sortBy[i]["recent"]}
alltime={sortBy[i]["alltime"]} />
);
}
//Couldn't find a simpler way to do this. Open & close JSX tags have to go together.
return (<div>
<table className="table table-hover table-condensed">
<caption id="title">FCCers by brownie points</caption>
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th><a href='#' onClick={this.sortByLast30}>Last 30 Days</a></th>
<th><a href='#' onClick={this.sortByAllTime}>All-time</a></th>
</tr>
</thead>
<tbody>
{theList}
</tbody>
</table>
</div>
);
}
});
ReactDOM.render(<List />, document.getElementById("table"));
Also see: Tab Triggers