<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SoftLayer Blog &#187; style</title>
	<atom:link href="http://blog.softlayer.com/tag/style/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.softlayer.com</link>
	<description>A Behind the Scenes Look at the Best Hosting Provider in the World</description>
	<lastBuildDate>Tue, 04 Jun 2013 20:27:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>Tips and Tricks &#8211; jQuery Select2 Plugin</title>
		<link>http://blog.softlayer.com/2012/tips-and-tricks-jquery-select2-plugin/</link>
		<comments>http://blog.softlayer.com/2012/tips-and-tricks-jquery-select2-plugin/#comments</comments>
		<pubDate>Wed, 17 Oct 2012 19:50:27 +0000</pubDate>
		<dc:creator>Cassandra Wolff</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[developers]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[Select2]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[tips and tricks]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=9467</guid>
		<description><![CDATA[Web developers have the unique challenge of marrying coding logic and visual presentation to create an amazing user experience. Trying to find a balance between those two is pretty difficult, and it&#8217;s easy to follow one or the other down the rabbit hole. What&#8217;s a web developer to do? I&#8217;ve always tried to go the [...]]]></description>
			<content:encoded><![CDATA[<p>Web developers have the unique challenge of marrying coding logic and visual presentation to create an amazing user experience. Trying to find a balance between those two is pretty difficult, and it&#8217;s easy to follow one or the other down the rabbit hole. What&#8217;s a web developer to do?</p>
<p>I&#8217;ve always tried to go the &#8220;work smarter, not harder&#8221; route, and when it comes to balancing functionality and aesthetics, that usually means that I look around for plugins and open source projects that meet my needs. In the process of sprucing up an form, I came across <a href="http://ivaynberg.github.com/select2/">jQuery Select2</a>, and it quickly became one of my favorite plugins for form formatting. With minimal scripting and little modification, you get some pretty phenomenal results. </p>
<p>We&#8217;ve all encountered drop-down selection menus on web forms, and they usually look like this:</p>
<p><img class="centered" src="http://cdn.softlayer.com/innerlayer/select.jpg" alt="Option Select"/></p>
<p>Those basic drop-downs meet a developer&#8217;s need for functionality, but they aren&#8217;t winning any beauty pageants. Beyond the pure aesthetic concerns, when a menu contains dozens (or hundreds) of selectable options, it becomes a little unwieldy. That&#8217;s why I was so excited to find Select2.</p>
<p>With Select2, you can turn the old, plain, boring-looking select boxes into beautiful, graceful and more-than-functional select widgets:</p>
<p><img class="centered" src="http://cdn.softlayer.com/innerlayer/selectpretty.jpg" alt="Pretty Option Select"/></p>
<p>Not only is the overall presentation of the data improved, Select2 also includes an auto-complete box. A user can narrow down the results quickly ad easily, and if you&#8217;ve got some of those endlessly scrolling select boxes of country names or currencies, your users will absolutely notice the change (and love you for it).</p>
<p>What&#8217;s even sexier than the form facelift is that you can add the plugin to your form in a matter of minutes.</p>
<p>After we <a href="https://github.com/ivaynberg/select2/tags">download Select2</a> and upload it to our box, we add our the jQuery library and scripts to the <code>&lt;head&gt;</code> of our document:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;jquery.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span> 
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;select2.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>For the gorgeous styling, we&#8217;ll also add Select2&#8242;s included style sheet:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;select2.css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span><span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>Before we close our <code>&lt;head&gt;</code> tag, we invoke the Select2 function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
	$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#selectPretty&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">select2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>At this point, Select2 is locked and load, and we just have to add the <code>#selectPretty</code> ID to the <code>select</code> element we want to improve:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>select id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;selectPretty&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Option1&quot;</span><span style="color: #339933;">&gt;</span>Option <span style="color: #CC0000;">1</span><span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Option2&quot;</span><span style="color: #339933;">&gt;</span>Option <span style="color: #CC0000;">2</span><span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Option3&quot;</span><span style="color: #339933;">&gt;</span>Option <span style="color: #CC0000;">3</span><span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Option4&quot;</span><span style="color: #339933;">&gt;</span>Option <span style="color: #CC0000;">4</span><span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>select<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Notice: the <code>selectPretty</code> ID is what we defined when we invoked the Select2 function in our <code>&lt;head&gt;</code> tag.</p>
<p>With miniscule coding effort, we&#8217;ve made huge improvements to the presentation of our usually-boring select menu. It&#8217;s so easy to implement that even the most black-and-white coding-minded web developers can add some pizzazz to their next form without having to get wrapped up in styling!</p>
<p>-Cassandra</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/tips-and-tricks-jquery-select2-plugin/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Web Development &#8211; JavaScript &#8211; Creating a Sticky Menu</title>
		<link>http://blog.softlayer.com/2012/web-development-javascript-creating-a-sticky-menu/</link>
		<comments>http://blog.softlayer.com/2012/web-development-javascript-creating-a-sticky-menu/#comments</comments>
		<pubDate>Wed, 23 May 2012 15:50:10 +0000</pubDate>
		<dc:creator>Philip Thompson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[display]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[sticky menu]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=8193</guid>
		<description><![CDATA[When designing websites, I like to focus on ease of use and accessibility for the end user. While creating your site to be friendly to screen readers and text-based browsers is a must, the accessibility I&#8217;m referring to is making it easy for your audience to navigate your site and perform certain common actions. By [...]]]></description>
			<content:encoded><![CDATA[<p>When designing websites, I like to focus on ease of use and accessibility for the end user. While creating your site to be friendly to screen readers and text-based browsers is a must, the accessibility I&#8217;m referring to is making it easy for your audience to navigate your site and perform certain common actions. By providing an easy interface for your users, you are immediately increasing your chances that they&#8217;ll return for more of your site&#8217;s goodness.</p>
<p>Thus far in our &#8220;Web Development&#8221; blog series, we&#8217;ve looked at <a href="http://blog.softlayer.com/2011/html5-javascript-web-development-part-i/">JavaScript Optimization</a>, <a href="http://blog.softlayer.com/2012/web-development-html5-custom-data-attributes/">HTML5 Custom Data Attributes</a>, <a href="http://blog.softlayer.com/2012/web-development-html5-web-fonts/">HTML5 Web Fonts</a> and using CSS to style the <a href="http://blog.softlayer.com/2012/web-development-css-highlight-selection/">Highlight Selection</a>. In this post, we&#8217;re going to create a &#8220;sticky&#8221; menu at the top of a page. As a user scrolls down, the menu will &#8220;stick&#8221; to the top and always be visible (think of Facebook&#8217;s Timeline view), allowing the user quicker access to clicking common links. With some simple HTML, CSS and JavaScript, you can have a sticky menu in no time.</p>
<style type="text/css">
code{color:blue;}
</style>
<p>Let&#8217;s start with our HTML. We&#8217;re going to have a simple header, menu and content section that we&#8217;ll throw in our <code>&lt;body&gt;</code> tag.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>header<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;</span>My Header<span style="color: #339933;">&lt;/</span>h1<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>header<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>nav id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;menu&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>ul id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;menu-list&quot;</span><span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Items<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>nav<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;content&quot;</span><span style="color: #339933;">&gt;</span>
    Some content
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></div></div>

<p>For brevity, I&#8217;ve shortened the content I show here, but the working example will have all the information. Now we can throw in some CSS to style our elements. The important part here is how the <code>&lt;nav&gt;</code> is styled.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">nav<span style="color: #666666; font-style: italic;">#menu {
</span>    background<span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">#FFF;
</span>    clear<span style="color: #339933;">:</span> both<span style="color: #339933;">;</span>
    margin<span style="color: #339933;">:</span> 40px <span style="color: #cc66cc;">0</span> 80px <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    width<span style="color: #339933;">:</span> <span style="color:#800080;">99.8</span><span style="color: #339933;">%;</span>
    z<span style="color: #339933;">-</span>index<span style="color: #339933;">:</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
ul<span style="color: #666666; font-style: italic;">#menu-list li {
</span>    border<span style="color: #339933;">:</span> solid 1px blue<span style="color: #339933;">;</span>
    list<span style="color: #339933;">-</span>style<span style="color: #339933;">-</span>type<span style="color: #339933;">:</span> none<span style="color: #339933;">;</span>
    display<span style="color: #339933;">:</span> inline<span style="color: #339933;">-</span>block<span style="color: #339933;">;</span>
    margin<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">-</span>3px<span style="color: #339933;">;</span>
    padding<span style="color: #339933;">:</span> 4px 10px<span style="color: #339933;">;</span>
    width<span style="color: #339933;">:</span> auto<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>We have set the menu&#8217;s <code>background</code> to white (<code>#FFF</code>) and given it a <code>z-index</code> of <code>2</code> so that when the user scrolls, the menu will stay on top and not be see-through. We&#8217;ve also set the list items to be styled <code>inline-block</code>, but you can style your items however you desire.</p>
<p>Now we get to the fun part – the JavaScript. I&#8217;ve created a class using <a href="http://mootools.net/">Mootools</a>, but similar functionality could be achieved using your favorite JavaScript framework. Let&#8217;s examine our <code>initialize</code> method (our constructor) in our <code>Stickit</code> class.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Stickit <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Stickit</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    initialize<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// 'item' is our nav#menu in this case</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066; font-weight: bold;">item</span> <span style="color: #339933;">=</span> document.<span style="color: #660066;">id</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// The element we're scrolling will be the window</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">scrollTarget</span> <span style="color: #339933;">=</span> document.<span style="color: #660066;">id</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">scrollTarget</span> <span style="color: #339933;">||</span> document.<span style="color: #660066;">window</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// The 'anchor' is an empty element that will always keep the same location</span>
        <span style="color: #006600; font-style: italic;">// when the user scrolls. This is needed because this.item will change and</span>
        <span style="color: #006600; font-style: italic;">// we cannot rely on it for accurate calculations.</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">anchor</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Element<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">inject</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'top'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// The 'filler' is an empty element that we'll use as a space filler for when</span>
        <span style="color: #006600; font-style: italic;">// the 'item' is being manipulated - this will prevent the content below from</span>
        <span style="color: #006600; font-style: italic;">// jumping around when we scroll.</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">filler</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Element<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">inject</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'after'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// Set the styles of our 'filler' to match the styles of the 'item'</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setFillerStyles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// Initialize our scroll events – see the next code section for details</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">initEvents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>What we&#8217;re doing here is grabbing our element to stick to the top – in this case, <code>nav#menu</code> – and initializing our other important elements. I&#8217;ll review these in the next code section.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Stickit <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Stickit</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    ...
    <span style="color: #660066;">initEvents</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> that <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span>
            <span style="color: #006600; font-style: italic;">// Grab the position of the anchor to be used for comparison during vertical scroll</span>
            anchorOffsetY <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">anchor</span>.<span style="color: #660066;">getPosition</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">y</span><span style="color: #339933;">,</span>
            <span style="color: #006600; font-style: italic;">// Grab our original styles of our 'item' so that we can reset them later</span>
            originalStyles <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">getStyles</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'margin-top'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'position'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'top'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// This is the function we'll provide as our scroll event handler</span>
        <span style="color: #003366; font-weight: bold;">var</span> stickit <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// Determine if we have scrolled beyond our threshold - in this case, our</span>
            <span style="color: #006600; font-style: italic;">// anchor which is located as the first element of our 'item'</span>
            <span style="color: #003366; font-weight: bold;">var</span> targetScrollY <span style="color: #339933;">=</span> that.<span style="color: #660066;">scrollTarget</span>.<span style="color: #660066;">getScroll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">y</span><span style="color: #339933;">,</span>
                fixit <span style="color: #339933;">=</span> targetScrollY <span style="color: #339933;">&gt;</span> anchorOffsetY<span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fixit <span style="color: #339933;">&amp;&amp;</span> that.<span style="color: #660066;">cache</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'fixed'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #006600; font-style: italic;">// If we have scrolled beyond the threshold, fix the 'item' to the top</span>
                <span style="color: #006600; font-style: italic;">// of the window with the following styles: margin-top, position and top</span>
                that.<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">setStyles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #3366CC;">'margin-top'</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
                    position<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fixed'</span><span style="color: #339933;">,</span>
                    top<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #006600; font-style: italic;">// Show our (empty) filler so that the content below the 'item' does not</span>
                <span style="color: #006600; font-style: italic;">// jump - this would otherwise be distracting to the user</span>
                that.<span style="color: #660066;">filler</span>.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'block'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #006600; font-style: italic;">// Cache our value so that we only set the styles when we need to</span>
                that.<span style="color: #660066;">cache</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'fixed'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>fixit <span style="color: #339933;">&amp;&amp;</span> that.<span style="color: #660066;">cache</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'default'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #006600; font-style: italic;">// We have not scrolled beyond the threshold.</span>
                <span style="color: #006600; font-style: italic;">// Hide our filler</span>
                that.<span style="color: #660066;">filler</span>.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'none'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #006600; font-style: italic;">// Reset the styles to our 'item'</span>
                that.<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">setStyles</span><span style="color: #009900;">&#40;</span>originalStyles<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #006600; font-style: italic;">// Cache our values so we don't keep resetting the styles</span>
                that.<span style="color: #660066;">cache</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'default'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// Add our scroll event to the target - the 'window' in this case</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">scrollTarget</span>.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'scroll'</span><span style="color: #339933;">,</span> stickit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">// Fire our scroll event so that all the elements and styles are initialized</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">scrollTarget</span>.<span style="color: #660066;">fireEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'scroll'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This method contains the meat of our functionality. The logic includes that we test how far the user has scrolled down on the page. If s/he scrolls past the threshold – in this case, the anchor which is located at the very top of the &#8220;stuck&#8221; item – then we set the menu to be fixed to the top of the page by setting the CSS values for <code>margin-top</code>, <code>position</code> and <code>top</code>. We also display a filler so that the content below the menu doesn&#8217;t jump when we set the menu&#8217;s <code>position</code> to <code>fixed</code>. When the user scrolls back to the top, the styles are reset to their original values and the filler is hidden. </p>
<p>To see a full working example, check out this <a href="http://jsfiddle.net/MrA85/4/">fiddle</a>. The <code>Stickit</code> class I created is flexible enough so that you can &#8220;stick&#8221; any element to the top of the page, and you can specify a different <code>scrollTarget</code>, which will allow you to scroll another element (besides the <code>window</code>) and allow the item to stick to the top of that element instead of the <code>window</code>. If you want to give that a try, you can specify different options in <code>Stickit</code> and modify your CSS as needed to get it working as you&#8217;d like.</p>
<p>Happy coding,</p>
<p>-Philip</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/web-development-javascript-creating-a-sticky-menu/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Web Development &#8211; CSS &#8211; Highlight Selection</title>
		<link>http://blog.softlayer.com/2012/web-development-css-highlight-selection/</link>
		<comments>http://blog.softlayer.com/2012/web-development-css-highlight-selection/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 21:07:08 +0000</pubDate>
		<dc:creator>Philip Thompson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[display]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[highlight]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[selector]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=7431</guid>
		<description><![CDATA[I immediately fell in love with CSS when we were introduced in late 2000. The ability to style a whole site outside the HTML was a fantastic concept and probably my first true introduction to separation of style and content. Put your words over here, and put how you display those words over there. So [...]]]></description>
			<content:encoded><![CDATA[<p>I immediately fell in love with CSS when we were introduced in late 2000. The ability to style a whole site outside the HTML was a fantastic concept and probably my first true introduction to separation of style and content. Put your words over here, and put how you display those words over there. So simple! Since then I have always been an advocate of cascading style sheets. Today&#8217;s tip will involve an effortless addition that will have your readers say, &#8220;Ooooh. That&#8217;s a clever little change.&#8221;</p>
<p>I find that when I read articles and blogs online, I not only read with my eyes, I scan the page with my mouse. Especially if it&#8217;s a wordy article or not styled in smaller columns, I highlight the text by clicking and dragging to help me maintain my focus. Up until recently, whenever you selected text that way in your browser, your operating system would choose the color of the background highlight. For Windows, this is generally blue. For OS X, this is whatever you&#8217;ve set your preferences to (which is light blue by default).</p>
<p>For those of you that use a newer version of Webkit (Chrome or Safari) or Gecko (Firefox), the site designer can determine what color to highlight your selection of text, and CSS has made it easy.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* Webkit */</span>
<span style="color: #339933;">::</span><span style="color: #004000;">selection</span> <span style="color: #009900;">&#123;</span>
    background<span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">#972F2C;
</span>    color<span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">#FFF;
</span><span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">/* Gecko/Mozilla */</span>
<span style="color: #339933;">::-</span>moz<span style="color: #339933;">-</span>selection <span style="color: #009900;">&#123;</span>
    background<span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">#972F2C;
</span>    color<span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">#FFF;
</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>As of today, Webkit browsers are the only ones that support <code>::selection</code> without browser prefixing. Firefox requires the <code>-moz-</code> prefix. Here we have set the highlight background color to &#8220;SoftLayer Red&#8221; (<code>#972F2C</code>) and made the text color white (<code>#FFF</code>). It should be noted that earlier versions of Webkit and Gecko did not support anything but the <code>background</code> property. There is still limited support for which CSS properties are allowed during selection. You are unable to change <code>font-style</code>, <code>font-size</code>, <code>text-decoration</code> and many other properties, but we can hope support for most of the properties will be available in the future.</p>
<p>This is pretty cool so far, but we can take it one small step further. Just like other selectors, we can apply the <code>::selection</code> selector to other elements and style each one differently.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">h2<span style="color: #339933;">::</span><span style="color: #004000;">selection</span> <span style="color: #009900;">&#123;</span>
    background<span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">#B72E33;
</span>    color<span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">#FFF;
</span><span style="color: #009900;">&#125;</span>
p<span style="color: #339933;">::</span><span style="color: #004000;">selection</span> <span style="color: #009900;">&#123;</span>
    background<span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">#ACEFB2;
</span><span style="color: #009900;">&#125;</span>
div<span style="color: #339933;">::</span><span style="color: #004000;">selection</span> <span style="color: #009900;">&#123;</span>
    background<span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">#E4DB80;
</span><span style="color: #009900;">&#125;</span>
span<span style="color: #339933;">::</span><span style="color: #004000;">selection</span> <span style="color: #009900;">&#123;</span>
    background<span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">#C780E4;
</span>    color<span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">#FFF;
</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>This produces the following:</p>
<p><img class="centered" src="http://cdn.softlayer.com/innerlayer/csshighlightingexample.png" alt="Highlighting Example"/></p>
<p>Surprise your readers and give them some highlight goodness.</p>
<p>Happy coding!</p>
<p>-Philip</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/web-development-css-highlight-selection/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Web Development &#8211; HTML5 &#8211; Web Fonts</title>
		<link>http://blog.softlayer.com/2012/web-development-html5-web-fonts/</link>
		<comments>http://blog.softlayer.com/2012/web-development-html5-web-fonts/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 17:25:30 +0000</pubDate>
		<dc:creator>Philip Thompson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[fonts]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[typography]]></category>
		<category><![CDATA[web fonts]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=6961</guid>
		<description><![CDATA[All but gone are the days of plain, static webpages flowered with horrible repeating neon backgrounds and covered with nauseating animated GIFs created by amateur designers that would make your mother cry and induce seizures in your grandpa. Needless to say, we have come a long way since Al Gore first &#8220;created the intarwebs&#8221; in [...]]]></description>
			<content:encoded><![CDATA[<p>All but gone are the days of plain, static webpages flowered with horrible repeating neon backgrounds and covered with nauseating animated GIFs created by amateur designers that would make your mother cry and induce seizures in your grandpa. Needless to say, we have come a long way since <a href="http://image.wetpaint.com/image/1/2SabbhSYx07KUalUhXo0MQ37019/GW404H304">Al Gore</a> first &#8220;created the intarwebs&#8221; in the early &#8217;90&#8242;s. For those of you born in this century, that&#8217;s the 1990&#8242;s &#8230; Yes, the World Wide Web is still very new. Luckily for the seven billion people on this lovely planet, many advancements have been introduced into our web browsers that make our lives as designers and developers just a little bit more tolerable.</p>
<p>Welcome to the third installment in Web Development series. If you&#8217;re just joining us, the first posts in the series covered <a href="http://blog.softlayer.com/2011/html5-javascript-web-development-part-i/">JavaScript Optimization</a> and <a href="http://blog.softlayer.com/2012/web-development-html5-custom-data-attributes/">HTML5 Custom Data Attributes</a> &#8230; If you haven&#8217;t read those yet, take a few minutes to catch up and head back to this blog where we&#8217;ll be looking at how custom web fonts can add a little spice to your already-fantastic website.</p>
<p>If you&#8217;re like me, you&#8217;ve probably used the same three or four fonts on most sites you&#8217;ve designed in the past: Arial, Courier New, Trebuchet MS and Verdana. You know that pretty much all browsers will have support for these &#8220;core&#8221; fonts, so you never ventured beyond them because you wanted the experience to remain the same for everyone, no matter what browser a user was using to surf. If you were adventurous and wanted to throw in a little typographical deviation, you might have created a custom image of the text in whatever font Photoshop would allow, but those days are in the past (or at least they should be).</p>
<p>Why is using an image instead of plain text unfriendly?</p>
<ol>
<li><strong>Lack of Flexibility</strong> &#8211; Creating an image is time-consuming. Even if you have really fast fingers and know your way around Photoshop, it will never be as fast as simply typing that text into your favorite editor. Also, you can&#8217;t change the styles (font-size, color, text-decoration, etc.) of an image using CSS like you can with text.</li>
<li><strong>Lack of Accessibility</strong> – Not everyone is alike. Some of your readers or clients may have impairments that require screen readers or a really large font. Using an image – especially one that doesn&#8217;t contain a good <a href="http://lmgtfy.com/?q=html+image+long+description">long description</a> – prevents those users from getting the full experience. Also, some people use text-only browsers that don&#8217;t display any images. Think about your whole audience!</li>
<li><strong>More to Download</strong> – Plain text doesn&#8217;t require the same number of bytes as an image of that same text. By not having another image, you are saving on the amount of time it takes to load your page.</li>
</ol>
<p>Now that we&#8217;re on the same page about the downsides of the &#8220;old way&#8221; of doing things, let&#8217;s look at some cool HTML5-powered methods for displaying custom fonts. Before we get started, we need to have some custom fonts to use. Google has a nice interface for downloading custom fonts (<a href="http://www.google.com/webfonts">http://www.google.com/webfonts</a>), and there are plenty of other sites that provide free and non-free fonts that can suit your taste/needs. You can pick and choose which ones you&#8217;d like to use (remembering to always follow copyright guidelines), and once you&#8217;ve created and downloaded your collection of fonts, you&#8217;ll need to setup your CSS to read them.</p>
<p>For simplicity, my file structure will be setup with the HTML and CSS files in the same root directory. I will have a <em>fonts</em> directory where I will keep all my custom fonts.</p>
<style type="text/css">
code{color:blue;}
</style>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">/</span>fonts<span style="color: #339933;">.</span>html
<span style="color: #339933;">/</span>fonts<span style="color: #339933;">.</span>css
<span style="color: #339933;">/</span>styles<span style="color: #339933;">.</span>css
<span style="color: #339933;">/</span>fonts<span style="color: #339933;">/</span>MyCustomFont<span style="color: #339933;">/</span>MyCustomFont<span style="color: #339933;">-</span>Regular<span style="color: #339933;">.</span>ttf
<span style="color: #339933;">/</span>fonts<span style="color: #339933;">/</span>MyCustomFont<span style="color: #339933;">/</span>MyCustomFont<span style="color: #339933;">-</span>Bold<span style="color: #339933;">.</span>ttf
<span style="color: #339933;">/</span>fonts<span style="color: #339933;">/...</span></pre></div></div>

<p>My <em>fonts.html</em> file will include the two CSS files in the head section. The order in which you include the CSS files does not matter.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;fonts.css&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;styles.css&quot;</span> <span style="color: #339933;">/&gt;</span></pre></div></div>

<p>The <em>fonts.css</em> file will include the definitions for all of our custom fonts. The <em>styles.css</em> file will be our main CSS file for our website. Defining our custom fonts (in <em>fonts.css</em>) is really simple:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">@</span>font<span style="color: #339933;">-</span>face <span style="color: #009900;">&#123;</span>
    font<span style="color: #339933;">-</span>family<span style="color: #339933;">:</span> <span style="color: #0000ff;">'MyCustomFont'</span><span style="color: #339933;">;</span>
    src<span style="color: #339933;">:</span> url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fonts/MyCustomFont/MyCustomFont-Regular.ttf'</span><span style="color: #009900;">&#41;</span> format<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'truetype'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It&#8217;s almost too easy thanks to HTML5! </p>
<p>Let&#8217;s break this down into its components to better understand what&#8217;s going on here. The <code>@font-face</code> declaration will be ignored by older browsers that don&#8217;t understand it, so this standards-compliant definition degrades nicely. The <code>font-family</code> descriptor is the name that you&#8217;ll use to reference this font family in your other CSS file(s). The <code>src</code> descriptor contains the location of where your font is stored and the format of the font.</p>
<p>There are several things to note here. The quotes around <code>MyCustomFont</code> in the <code>font-family</code> descriptor are optional. If it were <code>My Custom Font</code> instead (in <em>fonts.css</em> and <em>styles.css</em>), it would still be successfully read. The quotes around the <code>url</code> portion are also optional. However, the quotes around the <code>format</code> portion are not optional. To keep things consistent, I have a habit of adding quotes around all of these items.</p>
<p>An alternative way to define the same font would be to leave off the <code>format</code> portion of the <code>src</code> descriptor. Browsers don&#8217;t need the <code>format</code> portion if it&#8217;s a standard font format (described below).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">@</span>font<span style="color: #339933;">-</span>face <span style="color: #009900;">&#123;</span>
    font<span style="color: #339933;">-</span>family<span style="color: #339933;">:</span> <span style="color: #0000ff;">'MyCustomFont'</span><span style="color: #339933;">;</span>
    src<span style="color: #339933;">:</span> url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fonts/MyCustomFont/MyCustomFont-Regular.ttf'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Like standard <code>url</code> inclusions in other CSS definitions, the URL item is relative to the location of the definition file (<em>fonts.css</em>). The URL may also be an absolute location or point to a different website altogether. If using the Google web fonts site mentioned earlier (or similar site), you may simply point the URL to the location suggested instead of downloading the actual font.</p>
<p>If you&#8217;ve dealt with web fonts before, you may already be familiar with the multiple formats: WOFF (Web Open Font Format, .woff), TrueType (.ttf), OpenType (.ttf, .otf), Embedded Open Type (.eot) and SVG Font (.svg, .svgz). I won&#8217;t go into great detail here about these, but if you&#8217;re interested in learning more, Google and <a href="http://www.w3.org/TR/css3-fonts/#font-face-rule">W3C</a> are great resources.</p>
<p>It should be noted that all browsers are not alike (no shock there) and some may not render some font formats correctly or at all. You can get around this by including multiple <code>src</code> descriptors in your <code>@font-face</code> declaration to try and support all the browsers.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">@</span>font<span style="color: #339933;">-</span>face <span style="color: #009900;">&#123;</span>
    font<span style="color: #339933;">-</span>family<span style="color: #339933;">:</span> <span style="color: #0000ff;">'MyCustomFont'</span><span style="color: #339933;">;</span>
    src<span style="color: #339933;">:</span> url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fonts/MyCustomFont/MyCustomFont-Regular.eot'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* Old IE */</span>
    src<span style="color: #339933;">:</span> url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fonts/MyCustomFont/MyCustomFont-Regular.ttf'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* Cool browsers */</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now that we have our font definition setup, we have to include our new custom font in our <em>styles.css</em>. You&#8217;ve done this plenty of times:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">h1<span style="color: #339933;">,</span> p <span style="color: #009900;">&#123;</span>
    font<span style="color: #339933;">-</span>family<span style="color: #339933;">:</span> MyCustomFont<span style="color: #339933;">,</span> Arial<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>There you go! For some reason if <code>MyCustomFont</code> is not understood, the browser will default to Arial. This degrades gracefully and is really simple to use. One thing to note is that even though your <em>fonts.css</em> file may define twenty custom fonts, only the fonts that are included and used in your <em>styles.css</em> file will be downloaded. This is very smart of the browser &ndash; it only downloads what it&#8217;s going to use.</p>
<p>So now you have one more tool to add to your development box. As more users adopt newer, standards-compliant browsers, it&#8217;s easier to give your site some spice without the headaches of creating unnecessary images. Go forth and impress your friends with your new web font knowledge!</p>
<style type="text/css">
@font-face {
    font-family: 'Monofett';
    src: url('http://themes.googleusercontent.com/static/fonts/monofett/v3/94n9d8-lEEaOz-Sn4plHGPesZW2xOQ-xsNqO47m55DA.woff') format('woff');
}
#fontfaceexample{font-family: 'Monofett', Arial; font-size:28px;}
</style>
<p id="fontfaceexample">Happy Coding!</p>
<p>-Philip</p>
<p>P.S. As a bonus, you can check out the in-line style declaration in the source of this post to see how &#8220;Happy Coding!&#8221; is coded to use the Monofett font family.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/web-development-html5-web-fonts/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
