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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<body ng-app="app" ng-controller="main">
<header>
<h1>Objects <span>( {{ items.length }} )</span></h1>
</header>
<main>
<div class="ctrls">
<div class="filter">
<span class="m m-search"></span>
<input type="text" ng-model="searchies" ng-change="onQueryChange(searchies)" class="form-control" placeholder="Filter">
</div>
<div class="grid-toggle">
<a ng-click="gridToggle = !gridToggle" ng-class="{ 'active' : gridToggle }">
<span class="m m-squares"></span>
<span class="m m-form"></span>
</a>
</div>
</div>
<div class="container">
<ul class="grid" ng-class="{ 'grid-list' : gridToggle, 'grid-thumb' : !gridToggle }">
<li class="grid-head">
<ul>
<li style="width:40%"><a ng-click="sort_by('name')">Name</a></li>
<li style="width:30%"><a ng-click="sort_by('user.name')">User</a></li>
<li style="width:15%"><a ng-click="sort_by('date')">Date</a></li>
<li style="width:15%"></li>
</ul>
</li>
<li class="grid-body animate-repeat" ng-repeat="item in pagedItems[currentPage - 1] | orderBy:sortingOrder:reverse" ng-class="{'last':$last}">
<ul>
<li>
<span class="grid-icon m" ng-class="item.icon"></span>
<span class="grid-title"><a href="#">{{ item.name }}</a></span>
</li>
<li>
<span class="grid-user">
<span class="grid-usericon" ng-style="{ 'background' : item.user.color }">{{ item.user.name }}</span>
<span class="grid-username">Updated by {{ item.user.name }}</span>
</span>
</li>
<li>
<span class="grid-date">{{ item.date }}</span>
</li>
<li>
<span class="grid-options"><a href="#"><span class="m m-ellipsis"></span></a></span>
</li>
</ul>
</li>
<li class="clear-fix"></li>
<li class="pagination">
<pager total-items="totalItems" items-per-page="itemsPerPage" ng-model="currentPage" max-size="maxSize" ng-change="pageChanged()"></pager>
<p ng-if="itemsPerPage * currentPage < totalItems">
Showing {{ itemsPerPage * currentPage - itemsPerPage + 1 }} - {{ itemsPerPage * currentPage }} of {{ totalItems }} total items
</p>
<p ng-if="itemsPerPage * currentPage >= totalItems">
Showing {{ itemsPerPage * currentPage - itemsPerPage + 1 }} - {{ totalItems }} of {{ totalItems }} total items
</p>
</li>
</ul>
</div>
</main>
<footer>
<p>Me playing with a mockup for a searchable collection of objects using angularjs.</p>
</footer>
</body>
@import "compass/css3";
@import url(https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,600,700);
$body: #38405e;
$bg: #f9fcfe;
$gray: #5d7592;
$shadow: #dde8f0;
$gray2: #476283;
$primary: #1bbbef;
.no-select {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
::-webkit-input-placeholder { color: $gray; }
:-moz-placeholder { color: $gray; }
::-moz-placeholder { color: $gray; }
:-ms-input-placeholder { color: $gray; }
.m {
font-size: 28px;
}
body {
text-align: center;
background: $bg;
color: $body;
font-size: 16px;
font-family: 'Open Sans', sans-serif;
font-weight: 400;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
}
header {
width: 100%;
background: $body;
padding: 3em 0;
color: white;
h1 {
font-weight: 300;
font-size: 36px;
margin: 0.75em 0;
span {
font-size: 90%;
color: $primary;
}
}
}
main {
padding: 1.5em 0 0;
}
footer, main {
max-width: 960px;
margin: 0 auto;
&:after {
content: '';
display: block;
clear: both;
}
}
footer {
padding: 2em 0;
p {
color: $gray;
font-size: 14px;
}
}
.ctrls {
margin-bottom: 1em;
&:after {
content: '';
clear: both;
display: block;
}
}
.filter {
float: left;
width: 75%;
padding-left: 2.5em;
.m {
color: $gray;
position: absolute;
margin-left: -1.25em;
}
input {
width: 100%;
vertical-align: top;
height: 2em;
border: none;
background: $bg;
font-size: 16px;
font-weight: 300;
color: $gray;
outline: none;
padding: 0 0.5em;
}
}
.grid-toggle {
cursor: pointer;
@extend .no-select;
float: right;
a {
span { color: $gray; }
span:first-child { color: $body; margin-right: 12px; }
&.active {
span:first-child { color: $gray; }
span:last-child { color: $body; }
}
}
}
.btn {
text-decoration: none;
text-transform: uppercase;
font-weight: 600;
color: $gray;
}
.container {
}
ul.grid {
.grid-body ul {
li {
span {
display: inline-block;
line-height: normal;
vertical-align: middle;
&.grid-icon {
color: $gray2;
}
&.grid-title a {
font-size: 16px;
font-weight: 500;
color: $body;
text-decoration: none;
&:hover { text-decoration: underline; }
}
&.grid-usericon {
&:first-letter {
color: white;
font-size: 16px;
}
margin-right: 12px;
font-size: 0;
width: 36px;
height: 36px;
line-height: 36px;
text-align: center;
background: $primary;
@include border-radius(100px);
}
&.grid-date, &.grid-user {
color: $gray;
font-size: 14px;
}
a .m {
color: $gray;
}
}
}
}
}
ul.grid.grid-thumb {
&:after {
content:'';
display: block;
clear: both;
}
.grid-head { display: none; }
.grid-body {
width: 50%;
float: left;
@include box-sizing(border-box);
margin-bottom: 2em;
&:nth-child(even) { padding-right: 1em; }
&:nth-child(odd) { padding-left: 1em; }
ul {
@include box-sizing(border-box);
background: white;
border: 1px solid $shadow;
padding: 1em 1.5em .75em;
@include border-radius(5px);
float: left;
width: 100%;
&:after {
content:'';
display: block;
clear: both;
}
li {
position: relative;
span {
&.grid-icon {
display: block;
font-size: 56px;
margin: 0 0 12px;
}
&.grid-title {
display: block;
margin-bottom: 1em;
}
&.grid-user {
.grid-usericon {
position: absolute;
left: 0;
bottom: -37px;
}
margin-bottom: 2px;
}
&.grid-date {
display: block;
}
&.grid-options {
float: right;
}
}
}
}
}
}
ul.grid.grid-list {
background: white;
border: 1px solid $shadow;
padding: 0 2em;
@include border-radius(5px);
li.grid-body {
border-bottom: 1px solid $shadow;
&:last-child, &.last { border-bottom: none; }
}
.grid-head ul {
&:after {
content:'';
display: block;
clear: both;
}
li {
@extend .no-select;
font-size: 16px;
border: none;
text-align: left;
padding: 2em 0 1em;
float: left;
a {
cursor: pointer;
color: $primary;
font-weight: 600;
&:hover {
text-decoration: underline;
}
}
}
}
.grid-body ul {
&:after {
content:'';
display: block;
clear: both;
}
li {
border: none;
text-align: left;
height: 5em;
line-height: 5em;
padding: 0;
float: left;
&:first-child { text-align: left; width: 40%; }
&:nth-child(2) { width: 30%; }
&:nth-child(3) { width: 15%; }
&:last-child { text-align: right; width: 15%; }
span {
&.grid-icon {
margin-right: 0.5em;
}
&.grid-username {
width: 100px;
}
}
}
}
}
li.clear-fix {
display: block;
clear: both;
}
li.pagination {
padding: 1em 0 2em;
p {
font-size: 14px;
}
ul.pager {
margin: 2em 0;
li {
display: inline;
&:first-child { margin-right: 1em; }
a {
color: $primary;
text-decoration: none;
padding: 0.5em 1.5em;
border: 1px solid $primary;
@include border-radius(100px);
}
}
}
}
// Animations
.animate-repeat {
list-style:none;
box-sizing:border-box;
overflow: hidden;
}
.animate-repeat.ng-move,
.animate-repeat.ng-enter,
.animate-repeat.ng-leave {
-webkit-transition:all ease-in-out 0.4s;
transition:all ease-in-out 0.4s;
}
.animate-repeat.ng-leave.ng-leave-active,
.animate-repeat.ng-move,
.animate-repeat.ng-enter {
opacity:0;
}
.animate-repeat.ng-leave,
.animate-repeat.ng-move.ng-move-active,
.animate-repeat.ng-enter.ng-enter-active {
opacity:1;
}
.grid-thumb {
.animate-repeat.ng-move,
.animate-repeat.ng-enter,
.animate-repeat.ng-leave {
-webkit-transition:none;
transition:none;
}
}
.grid-list {
.animate-repeat {
line-height:5em;
}
.animate-repeat.ng-leave.ng-leave-active,
.animate-repeat.ng-move,
.animate-repeat.ng-enter {
height:0;
}
.animate-repeat.ng-leave,
.animate-repeat.ng-move.ng-move-active,
.animate-repeat.ng-enter.ng-enter-active {
height:5em;
}
}
angular.module('app', ['ui.bootstrap', 'ngAnimate'])
.factory('sortable', ['$filter', '$rootScope', function($filter, $rootScope){
return function (scope, data, itemsPerPage, initSortingOrder) {
scope.sortingOrder = initSortingOrder;
scope.reverse = false;
scope.filteredItems = [];
scope.groupedItems = [];
scope.itemsPerPage = itemsPerPage;
scope.pagedItems = [];
scope.currentPage = 1;
scope.items = data;
scope.maxSize = 5;
var searchMatch = function (haystack, needle) {
if (!needle) {
return true;
}
return haystack.toLowerCase().indexOf(needle.toLowerCase()) !== -1;
};
// init the filtered items
scope.search = function () {
scope.filteredItems = $filter('filter')(scope.items, $rootScope.query);
// take care of the sorting order
if (scope.sortingOrder !== '') {
scope.filteredItems = $filter('orderBy')(scope.filteredItems, scope.sortingOrder, scope.reverse);
}
scope.currentPage = 1;
// now group by pages
scope.groupToPages();
// reset the total items for the pagination buttons
scope.totalItems = scope.filteredItems.length;
};
// calculate page in place
scope.groupToPages = function () {
scope.pagedItems = [];
for (var i = 0; i < scope.filteredItems.length; i++) {
if (i % scope.itemsPerPage === 0) {
scope.pagedItems[Math.floor(i / scope.itemsPerPage)] = [ scope.filteredItems[i] ];
} else {
scope.pagedItems[Math.floor(i / scope.itemsPerPage)].push(scope.filteredItems[i]);
}
}
};
scope.range = function (start, end) {
var ret = [];
if (!end) {
end = start;
start = 0;
}
for (var i = start; i < end; i++) {
ret.push(i);
}
return ret;
};
// functions have been described process the data for display
scope.search();
// change sorting order
scope.sort_by = function(newSortingOrder) {
if (scope.sortingOrder == newSortingOrder)
scope.reverse = !scope.reverse;
scope.sortingOrder = newSortingOrder;
// call search again to make sort affect whole query
scope.search();
};
scope.sort_by(initSortingOrder);
scope.totalItems = scope.filteredItems.length;
}
}])
.controller('main', [ '$scope', '$rootScope', 'sortable', function($scope, $rootScope, sortable) {
$rootScope.query = '';
$scope.gridToggle = true;
$scope.onQueryChange = function(val){
$rootScope.query = val;
$scope.search();
};
var items = [
{ 'icon' : 'm-munkey', 'name' : 'A Munkey Page', 'date' : 'Yesterday at Noon', 'user' : { 'name' : 'Munkey', 'color' : '#07D5E5'} },
{ 'icon' : 'm-bug', 'name' : 'Mobile Splash Page', 'date' : 'Yesterday at 4:30pm', 'user' : { 'name' : 'Munkey', 'color' : '#07D5E5'} },
{ 'icon' : 'm-photo', 'name' : 'Some Other Site', 'date' : 'Today at 3:35am', 'user' : { 'name' : 'Someone', 'color' : '#456183'} },
{ 'icon' : 'm-desktop', 'name' : 'Jerry\'s Blog', 'date' : 'Thursday at 7:15pm', 'user' : { 'name' : 'Jerry', 'color' : '#4677A7'} },
{ 'icon' : 'm-form', 'name' : 'Ape\'s Capture Form', 'date' : 'Today at Noon', 'user' : { 'name' : 'Ape', 'color' : '#09ABC5'} },
{ 'icon' : 'm-phone', 'name' : 'Some Mobile Site', 'date' : 'Thursday at 1:27pm', 'user' : { 'name' : 'Someone', 'color' : '#456183'} },
{ 'icon' : 'm-bell', 'name' : 'Fish\'s Wordpress Site', 'date' : 'Yesterday at Noon', 'user' : { 'name' : 'Fish', 'color' : '#1CB7BB'} },
{ 'icon' : 'm-group', 'name' : 'Kitty Kat Kapture Form', 'date' : 'Wednesday at 7:15pm', 'user' : { 'name' : 'Kitty', 'color' : '#1D9D9D'} }
];
sortable($scope, items, 6, 'updated_at');
}]);
Also see: Tab Triggers