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.
<!-- Simple template for the ListView instantiation -->
<div class="smallListIconTextTemplate"
data-win-control="WinJS.Binding.Template"
style="display: none">
<div class="smallListIconTextItem">
<span class="date-picker">
<img src="#"
class="smallListIconTextItem-Image date-picker"
data-win-bind="src: picture"
onerror="this.style.display='none'"/>
</span>
<div class="smallListIconTextItem-Detail">
<h4 class="win-h4" data-win-bind="textContent: title"></h4>
<h6 class="win-h6" data-win-bind="textContent: text"></h6>
<h6 class="win-h6 counter" data-win-bind="innerText: counter"></h6>
</div>
</div>
</div>
<div class="listLayoutTopHeaderTemplate" data-win-control="WinJS.Binding.Template">
<div class="listLayoutTopHeaderTemplateRoot">
<div data-win-bind="innerHTML: title"></div>
</div>
</div>
<!-- Elements used for header and footer elements for ListView -->
<div class="headerFooterPlaceholder">
<div class="header">
<span style="display: inline-block;">
<h2 class="win-h2">Ordered ListView with Editing Items</h2>
<p>
<span>Total Items: </span>
<span data-win-bind="textContent: data.length"></span>
</p>
</span>
<span style="display: inline-block; float: right;">
<button class="win-button" data-win-bind="onclick: eh.toggleStripes">
Toggle Odd/Even
</button>
<button id="removeSelected" class="win-button" data-win-bind="onclick: eh.removeSelected">
Remove
</button>
</span>
</div>
<div class="footer">
<div>
<button class="win-button"
data-win-bind="onclick: eh.backToTop">
Back to Top
</button>
</div>
<div class="status">
<div>Loading more items </div>
<progress class="win-progress-bar progress hide"></progress>
</div>
</div>
</div>
<div id="listView"
class="listView stripes win-selectionstylefilled "
data-win-control="WinJS.UI.ListView"
data-win-options="{
itemDataSource: Sample.ListView.data.dataSource,
itemTemplate: select('.smallListIconTextTemplate'),
header: select('.header'),
footer: select('.footer'),
onheadervisibilitychanged: Sample.ListView.eh.headerVisibility,
onfootervisibilitychanged: Sample.ListView.eh.footerVisibility,
layout: { type: WinJS.UI.ListLayout, groupHeaderPosition: 'top'},
groupDataSource: Sample.ListView.data.groups.dataSource,
groupHeaderTemplate: select('.listLayoutTopHeaderTemplate'),
selectionMode: 'multi',
tapBehavior: WinJS.UI.TapBehavior.toggleSelect
}">
</div>
/* Template for the items in the ListViews in this sample */
.smallListIconTextItem
{
width: 100%;
height: 70px;
padding: 5px;
overflow: hidden;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.smallListIconTextItem img.smallListIconTextItem-Image
{
width: 64px;
height: 64px;
margin: 5px;
margin-right:20px;
}
.smallListIconTextItem .smallListIconTextItem-Detail
{
margin: 5px;
}
.listLayoutTopHeaderTemplateRoot, .gridLayoutLeftHeaderTemplateRoot {
font-size: larger;
margin-left: 16px;
}
/* CSS applied to the ListViews in this sample */
#listView
{
height: 100%;
}
.headerFooterPlaceholder {
display: none;
}
.listView .header,
.listView .footer {
height: 80px;
padding: 10px;
background-color: #333;
}
.listView .footer .progress.hide {
display: none;
}
img.date-picker {
display: none;
}
span.date-picker:after {
font-family: FontAwesome;
content: "\f03e";
color: grey;
font-size: 64px;
display: inline-block;
margin-top: 0em;
margin-bottom: 0em;
margin-right: 5px;
}
/* Override the background color for even/odd win-containers */
.listView.stripes .win-container.win-container-odd {
background-color: #212;
}
.listView.stripes .win-container.win-container-even {
background-color: #424;
}
.counter {
font-size: 8pt;
position: absolute;
top: 0px;
right: 5px;
width: 20px;
height: 20px;
text-align: left;
}
var itemArray = [
{ title: "Banana Blast", text: "Low-fat frozen yogurt", picture: "/images/fruits/60Banana.png" }
];
// For Example of loading
var itemArray2 = [
{ title: "Banana Blast Two", text: "Low-fat frozen yogurt", picture: "/images/fruits/60Banana.png" },
{ title: "Marvelous Mint", text: "Gelato", picture: "/images/fruits/60Mint.png" },
{ title: "Succulent Strawberry", text: "Sorbet", picture: "/images/fruits/60Strawberry.png" },
{ title: "Lavish Lemon Ice", text: "Sorbet", picture: "/images/fruits/60Lemon.png" },
{ title: "Creamy Orange", text: "Sorbet", picture: "/images/fruits/60Orange.png" },
{ title: "Very Vanilla", text: "Ice Cream", picture: "/images/fruits/60Vanilla.png" },
{ title: "Lavish Lemon Ice Two", text: "Sorbet", picture: "/images/fruits/60Lemon.png" }
];
function generateItems() {
var tIndex = 0;
itemArray.forEach(function(item){
item.counter = tIndex++;
});
return itemArray;
};
var items = generateItems();
var data = new WinJS.Binding.List(items);
var groupedData = data.createGrouped(function (item) {
return item.title.toUpperCase().charAt(0);
}, function (item) {
return {
title: item.title.toUpperCase().charAt(0)
};
}, function (left, right) {
return left.charCodeAt(0) - right.charCodeAt(0);
});
WinJS.Namespace.define("Sample.ListView", {
generate: generateItems,
data: groupedData,
eh: {
footerVisibility: WinJS.UI.eventHandler(function (ev) {
var visible = ev.detail.visible;
if (visible) {
WinJS.Utilities.removeClass(Sample.ListView.progress, "hide");
WinJS.UI.Animation.fadeIn(Sample.ListView.status);
// Simulate XHR by just setting a timeout and updating the observable binding list
WinJS.Promise.timeout(100).then(function () {
var items = itemArray2;
items.forEach(function (item) {
Sample.ListView.data.push(item);
});
});
} else {
WinJS.Utilities.addClass(Sample.ListView.progress, "hide");
}
}),
toggleStripes: WinJS.UI.eventHandler(function (ev) {
WinJS.Utilities.toggleClass(Sample.ListView.listView, "stripes");
}),
backToTop: WinJS.UI.eventHandler(function (ev) {
Sample.ListView.listView.winControl.scrollPosition = 0;
}),
removeSelected: WinJS.UI.eventHandler(function (ev) {
//Sample.ListView.listView.winControl.scrollPosition = 0;
removeSelected();
})
}
});
// Remove the selected tile
function removeSelected() {
// Get the control
//var list2 = document.getElementById("listView").winControl;
var list2 = Sample.ListView.listView.winControl;
if (list2.selection.count() > 0) {
list2.selection.getItems().done(function (items) {
//Sort the selection to ensure its in index order
items.sort(function CompareForSort(item1, item2) {
var first = item1.index, second = item2.index;
if (first === second) {
return 0;
} else if (first < second) {
return -1;
}
else {
return 1;
}
});
//Work backwards as the removal will affect the indices of subsequent items
for (var j = items.length - 1; j >= 0; j--) {
// To remove the items, call splice on the list, passing in a count and no replacements
data.splice(items[j].index, 1);
}
});
}
}
// Cache ListView and Header elements
Sample.ListView.listView = document.querySelector(".listView");
Sample.ListView.header = document.querySelector(".header");
Sample.ListView.progress = document.querySelector(".footer .progress");
Sample.ListView.status = document.querySelector(".footer .status");
// Data bind header element and split pane element
WinJS.Binding.processAll(Sample.ListView.header, Sample.ListView).then(function () {
return WinJS.Binding.processAll(Sample.ListView.splitPane, Sample.ListView);
}).then(function () {
// Process UI to initialize WinJS controls
return WinJS.UI.processAll();
});
var msToTime = function(duration) {
var milliseconds = parseInt((duration % 1000)/100);
var seconds = parseInt((duration / 1000) % 60);
var minutes = parseInt((duration / (1000*60)) % 60);
var hours = parseInt((duration / (1000*60*60)) % 24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
};
Also see: Tab Triggers