Skip to content

Instantly share code, notes, and snippets.

@jhafner
jhafner / canvas-boilerplate.js
Created August 23, 2013 22:38
Canvas (2D) Boilerplate
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
function loop() {
clear();
update();
draw();
@jhafner
jhafner / mobile-form.html
Created August 19, 2013 15:47
Describes HTML5 Attributes for Forms on Mobile Devices
<form id="mobile-form">
<input type="tel" /> <!-- Displays number pad -->
<input type="text" pattern="\d*" novalidate /> <!-- Displays number pad on text fields -->
<input type="email" autocapitalize="off" /> <!-- Displays email input, disables auto-capitalization -->
<input type="text" autocorrect="off" /> <!-- Disables autocorrect -->
</form>
@jhafner
jhafner / absolute-centering.css
Created August 19, 2013 14:06
Absolute centering of elements with CSS. Advantages: Cross-browser (including IE8-10) No special markup, minimal styles Responsive with percentages and min-/max- Use one class to center any content Centered regardless of padding (without box-sizing!) Blocks can easily be resized Works great on images Caveats: Height must be declared Recommend se…
.Center-Container {
position: relative;
}
.Absolute-Center {
width: 50%;
height: 50%;
overflow: auto;
margin: auto;
position: absolute;
@jhafner
jhafner / prefetch.html
Created June 5, 2013 14:46
HTML5 DNS Prefetching and Link Prefetching/Prerendering. Source: http://daker.me/2013/05/5-html5-features-you-need-to-know.html
<!--
DNS hostname resolution is one of the issues that can make any website slow. Modern browsers start to be very smart when it comes to DNS resolution, they try to resolve domain names then cache them before the user tries to follow any link on the webpage.
With the dns-prefetch feature you are allowed to manually control this operation by telling the browser which domain names to resolve
-->
<link rel="dns-prefetch" href="//fonts.googleapis.com">
<link rel="dns-prefetch" href="//google-analytics.com">
<link rel="dns-prefetch" href="//www.google-analytics.com">
<link rel="dns-prefetch" href="//platform.twitter.com">
@jhafner
jhafner / no-ios-highlights.css
Created May 30, 2013 15:50
Disable Mobile Webkit Highlights
body {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@jhafner
jhafner / textcolumns.css
Created May 30, 2013 15:43
CSS Text Columns
#columns-3 {
text-align: justify;
-ms-column-count: 3;
-ms-column-gap: 12px;
-ms-column-rule: 1px solid #c4c8cc;
-moz-column-count: 3;
-moz-column-gap: 12px;
-moz-column-rule: 1px solid #c4c8cc;
-webkit-column-count: 3;
-webkit-column-gap: 12px;
@jhafner
jhafner / gradients.css
Created May 30, 2013 15:37
CSS3 Gradients Template.
#colorbox {
background: #629721;
background-image: -webkit-gradient(linear, left top, left bottom, from(#83b842), to(#629721));
background-image: -webkit-linear-gradient(top, #83b842, #629721);
background-image: -moz-linear-gradient(top, #83b842, #629721);
background-image: -ms-linear-gradient(top, #83b842, #629721);
background-image: -o-linear-gradient(top, #83b842, #629721);
background-image: linear-gradient(top, #83b842, #629721);
}
@jhafner
jhafner / vCenter.css
Created May 30, 2013 15:36
Vertically center inline content.
.container {
min-height: 6.5em;
display: table-cell;
vertical-align: middle;
}
@jhafner
jhafner / fontStacks.css
Created May 30, 2013 15:34
List of modern font stacks.
/* Times New Roman-based serif */
font-family: Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", serif;
/* A modern Georgia-based serif */
font-family: Constantia, "Lucida Bright", Lucidabright, "Lucida Serif", Lucida, "DejaVu Serif," "Bitstream Vera Serif", "Liberation Serif", Georgia, serif;
/*A more traditional Garamond-based serif */
font-family: "Palatino Linotype", Palatino, Palladio, "URW Palladio L", "Book Antiqua", Baskerville, "Bookman Old Style", "Bitstream Charter", "Nimbus Roman No9 L", Garamond, "Apple Garamond", "ITC Garamond Narrow", "New Century Schoolbook", "Century Schoolbook", "Century Schoolbook L", Georgia, serif;
/*The Helvetica/Arial-based sans serif */
@jhafner
jhafner / mediaQueries.css
Created May 30, 2013 15:33
General list of media queries.
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen and (min-width : 321px) {
/* Styles */
}