<?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>Frederik Vig - ASP.NET developer &#187; CSS</title>
	<atom:link href="http://www.frederikvig.com/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.frederikvig.com</link>
	<description></description>
	<lastBuildDate>Wed, 28 Jul 2010 14:08:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>CSS and JavaScript compression and bundling</title>
		<link>http://www.frederikvig.com/2010/06/css-and-javascript-compression-and-bundling/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=css-and-javascript-compression-and-bundling</link>
		<comments>http://www.frederikvig.com/2010/06/css-and-javascript-compression-and-bundling/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 22:26:50 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1298</guid>
		<description><![CDATA[In the last post in Create an EPiServer site from scratch I go through some optimization tips and tricks from YSlow. One of these are CSS and JavaScript compression and bundling of files to create fewer HTTP requests and to send the least amount of data back to the client as possible, removing whitespaces, comments [...]]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://www.frederikvig.com/2009/12/part-8-preparing-for-launch-create-an-episerver-site-from-scratch/">last post</a> in <a href="http://www.frederikvig.com/2009/12/introduction-create-an-episerver-site-from-scratch/">Create an EPiServer site from scratch</a> I go through some optimization tips and tricks from <a href="http://developer.yahoo.com/yslow/">YSlow</a>. One of these are CSS and JavaScript compression and bundling of files to create fewer HTTP requests and to send the least amount of data back to the client as possible, removing whitespaces, comments etc, that we don&#8217;t need to run our code. </p>
<p>In the past I&#8217;ve done this as part of my deployment process, but recently I&#8217;ve come across a tool called <a href="http://www.codethinked.com/post/2010/05/26/SquishIt-The-Friendly-ASPNET-JavaScript-and-CSS-Squisher.aspx">SquishIt</a>. Which basically is a wrapper for <a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a> (you can easily replace it with your compressor of choice). It is dead simple to use, you simply add a reference to SquishIt.Framework.dll in your project, and replace your old CSS and JavaScript links and script tags with code like this.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%=</span> Bundle.<span style="color: #0000FF;">Css</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
          .<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;~/Styles/screen.css&quot;</span><span style="color: #000000;">&#41;</span>
          .<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;~/Styles/print.css&quot;</span><span style="color: #000000;">&#41;</span>
          .<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;~/Styles/mobile.css&quot;</span><span style="color: #000000;">&#41;</span>
          .<span style="color: #0000FF;">Render</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;~/Styles/combined-#.css&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">%&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;%=</span> Bundle.<span style="color: #0000FF;">JavaScript</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
          .<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;~/Scripts/belatedPNG-0.0.8a-min.js&quot;</span><span style="color: #000000;">&#41;</span>
          .<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;~/Scripts/ie6.js&quot;</span><span style="color: #000000;">&#41;</span>
          .<span style="color: #0000FF;">Render</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;~/Scripts/ie6combined-#.js&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;</span></pre></div></div>

<p>Using a fluent interface makes it easy to add more file references, ending with the Render method that takes a parameter for where to store the combined and minimized file. </p>
<p>It is very easy to toggle SquishIt on and off. Simply set debug=&#8221;true&#8221; in your web.config file to turn it off and render CSS and JavaScript files as normal, great for when you need to debug your code. Set debug=&#8221;false&#8221; to enable compression and bundling again.</p>
<p>Best part is that it only took me 2 minutes to setup and add to my current project! Works like a charm so far <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .<strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/08/adding-css-and-javascript-files-dynamically-to-your-asp-net-page/" rel="bookmark" title="August 15, 2009">Adding CSS and JavaScript files dynamically to your ASP.NET page</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-8-preparing-for-launch-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 24, 2009">Part 8: Preparing for launch – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-newslist/" rel="bookmark" title="July 25, 2009">EPiServer web controls: NewsList</a></li>
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-pagelist/" rel="bookmark" title="July 20, 2009">EPiServer web controls: PageList</a></li>
<li><a href="http://www.frederikvig.com/2010/01/episerver-code-walkthrough-1-404-handler/" rel="bookmark" title="January 29, 2010">EPiServer code walkthrough #1 &#8211; 404 handler</a></li>
</ul>
<p><!-- Similar Posts took 11.886 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2010/06/css-and-javascript-compression-and-bundling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Guide to font sizing with CSS</title>
		<link>http://www.frederikvig.com/2010/02/guide-to-font-sizing-with-css/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=guide-to-font-sizing-with-css</link>
		<comments>http://www.frederikvig.com/2010/02/guide-to-font-sizing-with-css/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 09:23:55 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Web design]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1057</guid>
		<description><![CDATA[Font sizing with CSS and browser support as always been a mystery to me. We used to use pixels, than we switched to ems and percent, then we switched back to pixels again?!.. In this post I&#8217;ve tried shedding some light on the matter and explaining the reason for this, and the different ways of [...]]]></description>
			<content:encoded><![CDATA[<p>Font sizing with CSS and browser support as always been a mystery to me. We used to use pixels, than we switched to ems and percent, then we switched back to pixels again?!.. In this post I&#8217;ve tried shedding some light on the matter and explaining the reason for this, and the different ways of doing font sizing on the web. </p>
<p>You have quite a few different measuring units to use in CSS for use with the font-size property (em, ex, px, in, cm, mm, pt, pc, %). We can group these lengths into two groups.</p>
<h3>Relative lenghts</h3>
<ul>
<li>em: the &#8216;font-size&#8217; of the relevant font</li>
<li>ex: the &#8216;x-height&#8217; of the relevant font</li>
<li>px: pixels, relative to the viewing device (resolution and pixel density)</li>
</ul>
<h3>Absolute lengths</h3>
<ul>
<li>in: inches — 1 inch is equal to 2.54 centimeters.</li>
<li>cm: centimeters</li>
<li>mm: millimeters</li>
<li>pt: points — the points used by CSS 2.1 are equal to 1/72nd of an inch.</li>
<li>pc: picas — 1 pica is equal to 12 points.</li>
</ul>
<p>Percentage values are always relative to a length or other value.</p>
<p>To be honest I only use four of these units. I use points (pt) in my print stylesheet, and px, em and % for my screen stylesheet. </p>
<h3>Pixels</h3>
<p>When using pixels for your font size you don&#8217;t have much to think about, 12px is 12px in every browser. What can be a problem, and what is the main reason that organizations like the <a href="http://www.w3.org">W3C</a> advice against using pixels for font size measurement, is the lack of support in browsers like Internet Explorer 6 when changing the browser&#8217;s default font size. The reason for this is that most browsers used to use text scaling for this, only enlarging the text on the page. However the newest versions of all the major browsers now use page zooming instead. What this does is increase (or decrease) all the elements on the page, not just the text, by zooming. </p>
<p>Lack of support for page zooming in Internet Explorer 6 can be a problem. If it is you should consider using ems and percent, which all browsers support. You can use ems/percent either for all browsers or by using a conditional comment stylesheet for Internet Explorer 6 and using pixels for the rest. I personally have started using pixels again, simple because it saves me a ton of work, and is much more reliable for measurement than using % and ems.</p>
<h3>Ems and percent</h3>
<p>If your audience still consists of a lot of Internet Explorer 6 users, you might want to stick with using ems or % for measurement. The rule to follow here is <strong>target &divide; context = result</strong>.</p>
<h4>Example</h4>
<p>If we give body a font size of 100% (roughly around 16px in most browsers), we can use that as the context. So if we want 12px in font size for normal text, and 20px for headings, this then becomes the target.</p>
<ul>
<li>12 &divide; 16 = 0,75</li>
<li>20 &divide; 16 = 1,25</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
p <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">.75em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
h1 <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.25em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>If we&#8217;d used pixels we would have something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">p <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
h1 <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Okay, say we have some text inside our paragraphs that we want to be 13px. The target becomes 13px, but the context changes, instead of using the body as the context, the paragraph becomes the context. So we get 13 &divide; 12 = 1,0833.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">p strong <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.0833em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>By using the <strong>target &divide; context = result</strong> rule, everything comes down to maths <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>Here is the live example with <a href="http://www.frederikvig.com/wp-content/uploads/font-sizing/font-sizing.html">ems and percent</a> and here with <a href="http://www.frederikvig.com/wp-content/uploads/font-sizing/font-sizing-px.html">pixels</a>.</p>
<p>So, what are you using?<strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/10/font-resizing-and-printing-with-jquery/" rel="bookmark" title="October 27, 2009">Font resizing and printing with jQuery</a></li>
<li><a href="http://www.frederikvig.com/2009/05/css-tricks-part-1/" rel="bookmark" title="May 31, 2009">CSS tricks &#8211; part 1</a></li>
<li><a href="http://www.frederikvig.com/2010/04/episerver-file-manager-and-file-summary/" rel="bookmark" title="April 2, 2010">EPiServer File Manager and File Summary</a></li>
<li><a href="http://www.frederikvig.com/2009/05/transparent-pngs/" rel="bookmark" title="May 5, 2009">Transparent PNGs</a></li>
<li><a href="http://www.frederikvig.com/2009/08/adding-css-and-javascript-files-dynamically-to-your-asp-net-page/" rel="bookmark" title="August 15, 2009">Adding CSS and JavaScript files dynamically to your ASP.NET page</a></li>
</ul>
<p><!-- Similar Posts took 10.190 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2010/02/guide-to-font-sizing-with-css/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating a mobile version of a web site</title>
		<link>http://www.frederikvig.com/2009/10/creating-a-mobile-version-of-a-web-site/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=creating-a-mobile-version-of-a-web-site</link>
		<comments>http://www.frederikvig.com/2009/10/creating-a-mobile-version-of-a-web-site/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 17:51:31 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[Web design]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=244</guid>
		<description><![CDATA[When building web sites we has developers or designers have to take into consideration all the different types of devices that can be used to access the web sites we create. Not just PC or Mac with Internet Explorer, Firefox, Safari, Opera, Jaws, or any other browser. But also mobile devices, like iPhones, iTouch, Nintendo [...]]]></description>
			<content:encoded><![CDATA[<p>When building web sites we has developers or designers have to take into consideration all the different types of devices that can be used to access the web sites we create. Not just PC or Mac with Internet Explorer, Firefox, Safari, Opera, Jaws, or any other browser. But also mobile devices, like iPhones, iTouch, Nintendo Wii. </p>
<p>Especially in recent years, after the launch of the iPhone, accessing online information through a mobile device has become more common. This is something that is going to increase even more in the next few years.</p>
<p>Below I&#8217;ve listed some resources for creating a mobile version of a web site that I hope you&#8217;ll find useful.</p>
<h3>Mobify</h3>
<p><a href="http://mobify.me/">Mobify</a> is a free online service that lets you convert an existing web site into a mobile version. This is done by selecting the content you wish to display for mobile users, customizing it by changing the display order and tweaking the CSS. The last step is to publish it by creating an url and adding a little JavaScript to your page. </p>
<p>Check out <a href="http://woork.blogspot.com/2009/08/how-to-implement-mobile-version-of-your.html">How to implement a mobile version of your blog in three simple steps</a> for a quick introduction.</p>
<p>Mobify is quick and easy way to great a mobile version, but you cannot change the HTML code and you&#8217;re stuck with the options the service offers. It can sometimes be better to create a mobile version from scratch.</p>
<h4>Update 05.10.2009</h4>
<p>Igor Faletski, founder of <a href="http://www.mobify.me">Mobify</a>, was kind enough to send me an email explaining the use of HTML blocks to add more static content. While this is a great feature I still miss the ability to update my existing markup and easily see what classes and ids that the mobile version uses. Now I have to test and tweak a little before I get the right id or class when changing my CSS.</p>
<h3>Creating a mobile version with ASP.NET</h3>
<p>Although services like Mobify are great, sometimes you need full control. On <a href="http://www.mobify.me/">mobify.me</a> it says that Mobify supports over 4500+ different mobile devices. This is a lot of different devices to support! Fortunately there is an open source project on CodePlex that has done most of the work for us. It is called <a href="http://mdbf.codeplex.com/">Mobile Device Browser File</a> and consists of a browser file with information about what the different mobile devices support (Java, JavaScript, Images, Flash etc). This project is pretty active with new devices added all the time. </p>
<p>You simply download the browser file and add it to your projects App_Browser folder. After you&#8217;ve done that you&#8217;ll be able to use Request.Browser["IsMobileDevice"] to detect if the device accessing your page is actually a mobile device. There are also <a href="http://mdbf.codeplex.com/Wiki/View.aspx?title=Capabilities&#038;referringTitle=Home">64 other capabilities</a> that offers a lot of different detection functionality. You can for instance check if the device supports Flash, JavaScript, Color, CSS background images etc.</p>
<p>If you&#8217;re using ASP.NET MVC check out <a href="http://www.hanselman.com/blog/MixMobileWebSitesWithASPNETMVCAndTheMobileBrowserDefinitionFile.aspx">Scott Hanselman&#8217;s post about how he implemented this with Nerd Dinner</a>. </p>
<p>If you&#8217;re using ASP.NET web forms there are a couple of approaches you could take. You could use a different master page for the mobile version by adding some detection code to your base page and <a href="http://odetocode.com/Articles/450.aspx">switching the master pages in the Init method</a>. Or you could register a <a href="http://msdn.microsoft.com/en-us/library/ms227673.aspx">custom HttpModule</a> that redirects the user to a different page if it is a mobile device.</p>
<p>Recently I stumbled over another library to detect the mobile device, it is called <a href="http://www.51degrees.mobi/Products/NETMobileAPI">51Degrees.mobi</a>. <a href="http://dotnetslackers.com/articles/aspnet/Mobile-Device-Detection-and-Redirection-Using-ASP-NET.aspx">Here is the article</a> that describes how to use it.</p>
<h3>iPhone</h3>
<p>Apple iPhone uses the Safari browser as its default browser. The great thing about that is that CSS3 stuff like <a href="http://www.css3.info/preview/rounded-border.html">border-radius</a>, multiple background images, <a href="http://furbo.org/2007/07/11/quartz-and-JavaScript-sitting-in-a-tree/">canvas</a> and more are supported. </p>
<p>If you like to simply target iPhone users you can do so by simply adding a custom stylesheet with this code.</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;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;only screen and (max-device-width: 480px)&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;iPhone.css&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/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>For more information I recommend reading <a href="http://www.alistapart.com/articles/putyourcontentinmypocket/">A List Aparts Put Your Content in My Pocket</a> and checking out the <a href="http://developer.apple.com/iphone/">iPhone Dev Center</a>.</p>
<h3>WordPress</h3>
<p>For WordPress you have a nice plugin called <a href="http://www.bravenewcode.com/wptouch/">WPtouch</a>, that will help you easily add a mobile view for iPhone, iPod, Android, Storm and Pre. You just need to install and activate the plugin, and you&#8217;re ready! You can easily customize it to your needs as well. </p>
<h3>Other resources</h3>
<p>More and more resources are being added each day. Below are some I&#8217;ve bookmarked and that have helped me in the past.</p>
<ul>
<li><a href="http://quirksmode.org/m/">Quirksmode great set of mobile tests</li>
<li><a href="http://mobify.me/">Mobify easily turn an existing site into a mobile view</a></li>
<li><a href="http://mobilewebbook.com/">Cameron Molls book about mobile web design</a></li>
<li><a href="http://mdbf.codeplex.com/">Mobile Device Browser File</a></li>
<li><a href="http://www.w3.org/Mobile/">W3C Mobile Web Initiative</a></li>
<li><a href="http://www.w3.org/TR/mwabp/">W3C Mobile Web Application Best Practices</a></li>
<li><a href="http://ready.mobi/launch.jsp?locale=en_EN">Test your website for mobile compatibility</a></li>
</ul>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/07/asp-net-web-forms-and-jquery-thickbox-plugin/" rel="bookmark" title="July 13, 2009">ASP.NET web forms and jQuery Thickbox plugin</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-1-setting-up-the-development-environment-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 4, 2009">Part 1: Setting up the development environment &#8211; Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-8-preparing-for-launch-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 24, 2009">Part 8: Preparing for launch – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2009/12/introduction-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 1, 2009">Introduction &#8211; Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2010/04/creating-a-simple-image-gallery-with-episerver/" rel="bookmark" title="April 3, 2010">Creating a simple image gallery with EPiServer</a></li>
</ul>
<p><!-- Similar Posts took 12.130 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/10/creating-a-mobile-version-of-a-web-site/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>CSS tricks &#8211; part 1</title>
		<link>http://www.frederikvig.com/2009/05/css-tricks-part-1/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=css-tricks-part-1</link>
		<comments>http://www.frederikvig.com/2009/05/css-tricks-part-1/#comments</comments>
		<pubDate>Sun, 31 May 2009 14:52:55 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[Web design]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=49</guid>
		<description><![CDATA[Here are a few CSS tricks I&#8217;ve picked up along the way. Always visible vertical scrollbar When you have a fixed width centered web site open you&#8217;ve probably noticed that the page sometimes jumps a little. This is because the vertical scrollbar only is visible if the content is longer than the viewport, if no [...]]]></description>
			<content:encoded><![CDATA[<p>Here are a few CSS tricks I&#8217;ve picked up along the way.</p>
<h3>Always visible vertical scrollbar</h3>
<p>When you have a fixed width centered web site open you&#8217;ve probably noticed that the page sometimes jumps a little. This is because the vertical scrollbar only is visible if the content is longer than the viewport, if no vertical scrollbar is visible in the browser. To always have the vertical scrollbar visible you can use the CSS hack below.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">html <span style="color: #00AA00;">&#123;</span>
    overflow-y<span style="color: #00AA00;">:</span> <span style="color: #993333;">scroll</span><span style="color: #00AA00;">;</span>	
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h3>CSS reset styles</h3>
<p>To make our lives as web developers easier we have a few css reset style rules which will help make things more consistent across browsers. It started out with simply setting the padding and margin of all elements to 0 with this CSS code.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Though this caused a few problems with form elements. After a few years of using the technique above I started using a CSS reset stylesheet.</p>
<ul>
<li><a href="http://meyerweb.com/eric/tools/css/reset/">Eric Meyer&#8217;s CSS Reset</a></li>
<li><a href="http://developer.yahoo.com/yui/reset/">YUI Reset CSS</a></li>
</ul>
<h3>100% min-height</h3>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#wrapper</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">600px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">*</span> html <span style="color: #cc00cc;">#wrapper</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">600px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Internet Explorer 6 has problems understanding the min-height property. Therefor I use the star selector hack to target IE6 and set the height property (IE6 uses the height property the same way as min-height, so if the content is bigger the page will still grow, like with min-height).</p>
<p><a href="http://reference.sitepoint.com/css/min-height">More information about the min-height property</a></p>
<h3>Star selector hack</h3>
<p>Applying * html {selector here} will only target Internet Explorer 5.5 and 6. Which makes this a nice way to still use valid CSS and only target those two browsers. Like in the min-height example above.</p>
<p>More information: <a href="http://reference.sitepoint.com/css/workaroundsfilters">Workarounds and Filters</a></p>
<h3>Internet Explorer 6 double margin bug</h3>
<p>When setting the float property to either left or right and having a margin set in the same direction as the float (either margin-left or margin-right) will give IE6 users twice the margin.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#sidebar</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This will give IE6 users a left margin of 20px. Fortunately it is easy to fix. Simply add the display property and set it to inline.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#sidebar</span> <span style="color: #00AA00;">&#123;</span>  
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This has no negative effect on other browsers. Also, when floating inline elements (a, span, em, etc), the element automatically becomes the same as when using display:block.</p>
<h4>More on floats</h4>
<ul>
<li><a href="http://css.maxdesign.com.au/floatutorial/">Step by Step CSS float tutorial</a></li>
<li><a href="http://reference.sitepoint.com/css/floatclear">Floating and clearing</a></li>
</ul>
<h3>hasLayout in Internet Explorer</h3>
<blockquote><p>“Layout” is an IE/Win proprietary concept that determines how elements draw and bound their content, interact with and relate to other elements, and react on and transmit application/user events.</p>
<p>This quality can be irreversibly triggered by some CSS properties. Some HTML elements have “layout” by default.</p>
<p>Microsoft developers decided that elements should be able to acquire a “property” (in an object-oriented programming sense) they referred to as hasLayout, which is set to true when this rendering concept takes effect.</p>
</blockquote>
<p>Source: <a href="http://www.satzansatz.de/cssd/onhavinglayout.html">satzansatz.de</a></p>
<p>I mostly come across this when I have no width or height applied. Like in the code below.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#wrapper</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#sidebar</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#content</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">600px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Overflow: hidden will clear the floats in all browsers except for in IE6. I could fix this by giving #wrapper a width or by floating it. But that is not always possible. Instead I can use the star selector and give IE6 a height of 1% to just trigger hasLayout.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#wrapper</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">*</span> html <span style="color: #cc00cc;">#wrapper</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">1</span>%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#sidebar</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#content</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">600px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h4>More information on hasLayout<br />
<h4>
<ul>
<li><a href="http://www.satzansatz.de/cssd/onhavinglayout.html">satzansatz.de</a></li>
<li><a href="http://reference.sitepoint.com/css/haslayout">The Internet Explorer hasLayout Property</a></li>
</ul>
<h3>Displaying a pointer cursor for button, label and select elements</h3>
<p>I always add this code when I start a new project.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>submit<span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">,</span> button<span style="color: #00AA00;">,</span> label<span style="color: #00AA00;">,</span> select <span style="color: #00AA00;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span> 
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Just to make it easier for users to see where they can click.</p>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2010/02/guide-to-font-sizing-with-css/" rel="bookmark" title="February 6, 2010">Guide to font sizing with CSS</a></li>
<li><a href="http://www.frederikvig.com/2009/11/flash-and-flash-video-episerver-dynamic-content/" rel="bookmark" title="November 17, 2009">Flash and Flash Video EPiServer Dynamic Content</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-5-creating-the-search-page-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 16, 2009">Part 5: Creating the search page – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-4-creating-the-standard-page-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 13, 2009">Part 4: Creating the standard page – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2009/11/better-breadcrumb-trail/" rel="bookmark" title="November 14, 2009">Better breadcrumb trail</a></li>
</ul>
<p><!-- Similar Posts took 14.180 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/05/css-tricks-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->