<?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>BlogmyQuery - BMQ &#187; CSS</title>
	<atom:link href="http://blogmyquery.com/index.php/category/design/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogmyquery.com</link>
	<description></description>
	<lastBuildDate>Fri, 03 Feb 2012 15:17:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using max-width on images can make them disappear in IE8</title>
		<link>http://blogmyquery.com/index.php/2012/02/using-max-width-on-images-can-make-them-disappear-in-ie8/</link>
		<comments>http://blogmyquery.com/index.php/2012/02/using-max-width-on-images-can-make-them-disappear-in-ie8/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 19:16:54 +0000</pubDate>
		<dc:creator>Roger Johansson</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://www.456bereastreet.com/archive/201202/using_max-width_on_images_can_make_them_disappear_in_ie8/</guid>
		<description><![CDATA[I recently ran into a problem that was really hard to figure out. I was working on a responsive design where I used img {max-width:100%;} to make sure that images would be downsized rather than overflow in narrower viewports.

It worked great everywher...]]></description>
			<content:encoded><![CDATA[<p class="preamble">I recently ran into a problem that was really hard to figure out. I was working on a responsive design where I used <code>img {max-width:100%;}</code> to make sure that images would be downsized rather than overflow in narrower viewports.</p>

<p>It worked great everywhereâ€¦ until I went to check in IE8. The siteâ€™s logo was gone! None of the usual IE bug fixes cured the problem, and it took me quite a while to realise that <code>max-width</code> was part of the problem.</p><p><a href="http://www.456bereastreet.com/archive/201202/using_max-width_on_images_can_make_them_disappear_in_ie8/">Read full post</a></p><p>Posted in <a href="http://www.456bereastreet.com/archive/categories/browsers/" rel="tag">Browsers</a>, <a href="http://www.456bereastreet.com/archive/categories/css/" rel="tag">CSS</a>.</p><p>Copyright Â© <a href="http://www.456bereastreet.com/">Roger Johansson</a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/asg0urLjdoS0RTfxGyMYPtxGsJ4/0/da"><img src="http://feedads.g.doubleclick.net/~a/asg0urLjdoS0RTfxGyMYPtxGsJ4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/asg0urLjdoS0RTfxGyMYPtxGsJ4/1/da"><img src="http://feedads.g.doubleclick.net/~a/asg0urLjdoS0RTfxGyMYPtxGsJ4/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/456bereastreet?a=PJ-73eQrVNc:8b_RwN5WA6g:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=PJ-73eQrVNc:8b_RwN5WA6g:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=bcOpcFrp8Mo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=PJ-73eQrVNc:8b_RwN5WA6g:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=PJ-73eQrVNc:8b_RwN5WA6g:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=PJ-73eQrVNc:8b_RwN5WA6g:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=PJ-73eQrVNc:8b_RwN5WA6g:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/456bereastreet/~4/PJ-73eQrVNc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2012/02/using-max-width-on-images-can-make-them-disappear-in-ie8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful CSS Snippets for Your Coding Arsenal</title>
		<link>http://blogmyquery.com/index.php/2012/01/useful-css-snippets-for-your-coding-arsenal/</link>
		<comments>http://blogmyquery.com/index.php/2012/01/useful-css-snippets-for-your-coding-arsenal/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 09:01:17 +0000</pubDate>
		<dc:creator>Kevin Muldoon</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://mgmt.noupe.com/?p=59822</guid>
		<description><![CDATA[<table width="650"><tr><td width="650"><div>
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=noupe-rss&#38;position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=noupe-rss&#38;position=1" border="0" alt="" /></a>&#160;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=noupe-rss&#38;position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=noupe-rss&#38;position=2" border="0" alt="" /></a>&#160;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=noupe-rss&#38;position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=noupe-rss&#38;position=3" border="0" alt="" /></a>
    </div></td></tr></table>
<a href="http://www.noupe.com/css/useful-css-snippets-for-your-coding-arsenal.html"><img src="http://media.noupe.com//uploads/2012/01/cssheader.jpg" width="550" /></a>

<strong>CSS</strong> is a beautiful language but it can also be frustrating at times. Certain CSS solutions don't work on certain browsers (cough Internet Explorer cough) and much of your time can be spent debugging code.]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=1" ><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=2" ><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=3" ><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=3" border="0" alt="" /></a>
    </div>
</td>
</tr>
</table>
<p><strong>CSS</strong> is a beautiful language but it can also be frustrating at times. Certain CSS solutions don&#8217;t work on certain browsers (cough Internet Explorer cough) and much of your time can be spent debugging code.</p>
<p>Thankfully there are lots of <strong>great CSS snippets available</strong> online that fix common problems and design issues. In this article we have listed 30 CSS snippets that we think you will find very useful.</p>
<h3>The Code</h3>
<p><strong>1. <a href="http://www.siolon.com/blog/browser-reset-css/" title="Chris Poteet CSS Browser Reset">Chris Poteet&#8217;s CSS Browser Reset</a> </strong></p>
<p><a href="http://sixrevisions.com/css/css-tips/css-tip-1-resetting-your-styles-with-css-reset/" title="Reset Your CSS Style">Resetting your CSS style</a> allows you to stop cross browser differences. Chris Proteet&#8217;s reset code doesn&#8217;t work in IE6 however this shouldn&#8217;t be a concern any more with use of the browser dropping below 1% in the USA.</p>
<pre name="code" class="css">
/*

Reset Default Browser Styles
- Place first in the listing of external style sheets for cascading.
- Be sure to explicitly set margin/padding styles.
- Styles are not reset that have to do with display (block, inline) are not reset.

By: Chris Poteet &#038; various influences

*/

* {
vertical-align: baseline;
font-family: inherit;
font-style: inherit;
font-size: 100%;
border: none;
padding: 0;
margin: 0;
}
body {
padding: 5px;
}
h1, h2, h3, h4, h5, h6, p, pre, blockquote, form, ul, ol, dl {
margin: 20px 0;
}
li, dd, blockquote {
margin-left: 40px;
}
dt {
font-weight: bold;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
</pre>
<p><strong>2. <a href="http://meyerweb.com/eric/tools/css/reset/" title="Eric Meyer CSS Reset">Eric Meyer&#8217;s CSS Reset</a> </strong></p>
<p>Eric Meyer&#8217;s CSS code resets is one of the most popular CSS snippets. It even found it&#8217;s way into the <a href="http://www.blueprintcss.org/" title="Blueprint CSS Framework">Blueprint CSS Framework</a>.</p>
<pre name="code" class="css">
/* http://meyerweb.com/eric/tools/css/reset/
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
	margin: 0;
	padding: 0;
	border: 0;
	font-size: 100%;
	font: inherit;
	vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
	display: block;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}
</pre>
<p><strong>3. <a href="http://www.sitepoint.com/css3-multiple-borders/" title="How to Create Multiple Borders in CSS3">How to Create Multiple Borders in CSS3</a> </strong></p>
<p>A cool technique using the box-shadow property that allows you to create multiple borders around an object. </p>
<pre name="code" class="css">
box-shadow:
    0 0 0 2px #000,
    0 0 0 3px #999,
    0 0 0 9px #fa0,
    0 0 0 10px #666,
    0 0 0 16px #fd0,
    0 0 0 18px #000;
</pre>
<p><strong>4. <a href="http://playground.genelocklin.com/tucked-corners/" title="Tucked Corners">Tucked Corners</a> </strong></p>
<p>This CSS code will give you the cool &#8216;tucked corners&#8217; effect that is used on the <a href="http://en.gravatar.com/" title="Gravatar">Gravatar home page</a>.</p>
<pre name="code" class="css">
div.tucked-corners {
	    background: #f6f6f6;
	    height: 380px;
	    margin: 50px auto;
	    padding: 10px;
	    position: relative;
	    width: 580px;
	    -webkit-box-shadow: 0 1px 7px hsla(0,0%,0%,.2);
	       -moz-box-shadow: 0 1px 7px hsla(0,0%,0%,.2);
	            box-shadow: 0 1px 7px hsla(0,0%,0%,.2);
	}
	span.tucked-corners {
	    background: #c4453c;
	    display: block;
	    height: 380px;
	    position: relative;
	    width: 580px;
	    -webkit-box-shadow: inset 0 0 10px hsla(0,0%,0%,.25);
	       -moz-box-shadow: inset 0 0 10px hsla(0,0%,0%,.25);
	            box-shadow: inset 0 0 10px hsla(0,0%,0%,.25);
	}

	/* Top Corner Effect */

	.top-corners:after,
	.top-corners:before {
	    background: #e6e6e6;
	    content: '';
	    height: 50px;
	    position: absolute;
	    top: -25px;
	    width: 100px;
	    z-index: 10;
	    -webkit-box-shadow: 0 6px 9px -8px hsla(0,0%,0%,.5);
	       -moz-box-shadow: 0 6px 9px -8px hsla(0,0%,0%,.5);
	            box-shadow: 0 6px 9px -8px hsla(0,0%,0%,.5);
	}
	.top-corners:after {
	    left: -50px;
	    -webkit-transform: rotate(-45deg);
	       -moz-transform: rotate(-45deg);
	        -ms-transform: rotate(-45deg);
	         -o-transform: rotate(-45deg);
	            transform: rotate(-45deg);
	}
	.top-corners:before {
	    right: -50px;
	    -webkit-transform: rotate(45deg);
	       -moz-transform: rotate(45deg);
	        -ms-transform: rotate(45deg);
	         -o-transform: rotate(45deg);
	            transform: rotate(45deg);
	}

	/* Bottom Corner Effect */

	.bottom-corners:after,
	.bottom-corners:before {
	    background: #e6e6e6;
	    content: '';
	    height: 50px;
	    position: absolute;
	    bottom: -25px;
	    width: 100px;
	    -webkit-box-shadow: 0 6px 9px -8px hsla(0,0%,0%,.5);
	       -moz-box-shadow: 0 6px 9px -8px hsla(0,0%,0%,.5);
	            box-shadow: 0 6px 9px -8px hsla(0,0%,0%,.5);
	}
	.bottom-corners:after {
	    left: -50px;
	    -webkit-transform: rotate(-135deg);
	       -moz-transform: rotate(-135deg);
	        -ms-transform: rotate(-135deg);
	         -o-transform: rotate(-135deg);
	            transform: rotate(-135deg);
	}
	.bottom-corners:before {
	    right: -50px;
	    -webkit-transform: rotate(135deg);
	       -moz-transform: rotate(135deg);
	        -ms-transform: rotate(135deg);
	         -o-transform: rotate(135deg);
	            transform: rotate(135deg);
	}
</pre>
<p><strong>5. <a href="http://css-tricks.com/snippets/css/ipad-specific-css/" title="iPad-Specific CSS">iPad-Specific CSS</a> </strong></p>
<p>Change the general layout of ipad screens and portrait and landscape modes. </p>
<pre name="code" class="css">
@media only screen and (device-width: 768px) {
  /* For general iPad layouts */
}

@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {
  /* For portrait layouts only */
}

@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) {
  /* For landscape layouts only */
}
</pre>
<p><strong>6. <a href="http://www.1stwebdesigner.com/design/useful-css-snippets/" title="Style links depending on file format">Style links depending on file format</a></strong></p>
<p>A short CSS snippet that changes the styling of external links, email links and links to pdf documents.</p>
<pre name="code" class="css">
	/* external links */
a[href^="http://"]{
    padding-right: 20px;
    background: url(external.gif) no-repeat center right;
}

/* emails */

a[href^="mailto:"]{
padding-right: 20px;

background: url(email.png) no-repeat center right;

}

/* pdfs */

a[href$=".pdf"]{
padding-right: 20px;
background: url(pdf.png) no-repeat center right;
</pre>
<p><strong>7. <a href="http://css-tricks.com/snippets/css/drop-caps/" title="Drop Caps">Drop Caps</a> </strong></p>
<p>A great cross-browser snippet that lets you make the first letter of a paragraph stand out.</p>
<pre name="code" class="css">
.firstcharacter { float: left; color: #903; font-size: 75px; line-height: 60px; padding-top: 4px; padding-right: 8px; padding-left: 3px; font-family: Georgia; }
</pre>
<p>This can also be achieved using CSS3 however it doesn&#8217;t work on IE9.</p>
<pre name="code" class="css">
p:first-child:first-letter { float: left; color: #903; font-size: 75px; line-height: 60px; padding-top: 4px; padding-right: 8px; padding-left: 3px; font-family: Georgia; }
</pre>
<p><strong>8. <a href="http://www.cssstickyfooter.com/" title="CSS Sticky Footer">CSS Sticky Footer</a> </strong></p>
<p>Create a sticky footer for your page. The solution works on <a href="http://www.cssstickyfooter.com/browser-list.html" title="Major Browsers">all major browsers</a> including Google Chrome and IE8.</p>
<p><em>CSS</em></p>
<pre name="code" class="css">
/*
Sticky Footer Solution
by Steve Hatcher 

http://stever.ca

http://www.cssstickyfooter.com

*/

* {margin:0;padding:0;} 

/* must declare 0 margins on everything, also for main layout components use padding, not
vertical margins (top and bottom) to add spacing, else those margins get added to total height
and your footer gets pushed down a bit more, creating vertical scroll bars in the browser */

html, body {height: 100%;}

#wrap {min-height: 100%;}

#main {overflow:auto;
	padding-bottom: 150px;}  /* must be same height as the footer */

#footer {position: relative;
	margin-top: -150px; /* negative value of footer height */
	height: 150px;
	clear:both;} 

/*Opera Fix*/
body:before {/* thanks to Maleika (Kohoutec)*/
content:"";
height:100%;
float:left;
width:0;
margin-top:-32767px;/* thank you Erik J - negate effect of float*/
}

/* IMPORTANT

You also need to include this conditional style in the <head> of your HTML file to feed this style to IE 6 and lower and 8 and higher.

<!--[if !IE 7]>
<style type="text/css">
		#wrap {display:table;height:100%}
	</style>

< ![endif]-->

*/
</head></pre>
<p><em>HTML</em></p>
<pre name="code" class="html">

&lt;div id="wrap"&gt;

	&lt;div id="main"&gt;

	&lt;/div&gt;

&lt;/div&gt;


&lt;div id="footer"&gt;

&lt;/div&gt;
</pre>
<p><strong>9. <a href="http://www.red-team-design.com/outline-dotted-border-and-image-replacement-technique" title="Image Replacement Technique">Image Replacement Technique</a> </strong></p>
<p>A handy way of replacing a text page element with an image. The snippet addresses a problem from another solution in which Firefox users noticed a dotted border that goes to the left of the screen.</p>
<pre name="code" class="css">
a.replacement
{
  background: url(dotted-border.png) no-repeat;
  height: 44px;
  width: 316px;
  display: block;
  text-indent: -9999px;
  overflow: hidden;  /*Add this line to the image replacement method*/
}
</pre>
<p><strong>10. <a href="http://sixrevisions.com/css/10-random-css-tricks-you-might-want-to-know-about/" title="Set body font-size to 62.5% for Easier em Conversion">Set body font-size to 62.5% for Easier em Conversion</a> </strong></p>
<p>If you want to have a more flexible layout, you should use em instead of pixels or points. By setting your font size at 62.5% you can easily set your font using em as the value will be a tenth of pixel value.</p>
<pre name="code" class="css">
body {
  font-size: 62.5%; /* font-size 1em = 10px */
}
p {
  font-size: 1.2em; /* 1.2em = 12px */
}
</pre>
<p><strong>11. <a href="http://sixrevisions.com/css/10-random-css-tricks-you-might-want-to-know-about/" title="Vertically Align Text">Vertically Align Text</a> </strong></p>
<p>If you set the line-height of your paragraph as the same size as it&#8217;s parent division you can easily center the text vertically.</p>
<pre name="code" class="css">
div { width:100px; height:100px; }
div p { line-height:100px; }
</pre>
<p><strong>12. <a href="http://www.sitepoint.com/css3-3d-text/" title="How to Create 3D Text With CSS3">How to Create 3D Text With CSS3</a> </strong></p>
<p>Using the text-shadow property, this snippet will help you create 3D text using CSS only.</p>
<pre name="code" class="css">
p.threeD
{
	text-shadow:
		-1px 1px 0 #ddd,
		-2px 2px 0 #c8c8c8,
		-3px 3px 0 #ccc,
		-4px 4px 0 #b8b8b8,
		-4px 4px 0 #bbb,
		0px 1px 1px rgba(0,0,0,.4),
		0px 2px 2px rgba(0,0,0,.3),
		-1px 3px 3px rgba(0,0,0,.2),
		-1px 5px 5px rgba(0,0,0,.1),
		-2px 8px 8px rgba(0,0,0,.1),
		-2px 13px 13px rgba(0,0,0,.1)
		;
}
</pre>
<p><strong>13. <a href="http://perishablepress.com/press/2010/06/01/wrapping-content/" title="Wrapping Long URLs and Text Content with CSS">Wrapping Long URLs and Text Content with CSS</a> </strong></p>
<p>This snippet will stop long lines of text extending over the content area by making sure the content wraps to fit the content width.</p>
<pre name="code" class="css">
pre {
	white-space: pre;           /* CSS 2.0 */
	white-space: pre-wrap;      /* CSS 2.1 */
	white-space: pre-line;      /* CSS 3.0 */
	white-space: -pre-wrap;     /* Opera 4-6 */
	white-space: -o-pre-wrap;   /* Opera 7 */
	white-space: -moz-pre-wrap; /* Mozilla */
	white-space: -hp-pre-wrap;  /* HP Printers */
	word-wrap: break-word;      /* IE 5+ */
	}
</pre>
<p><strong>14. <a href="http://css-tricks.com/snippets/css/fancy-ampersand/" title="Fancy Ampersand">Fancy Ampersand</a> </strong></p>
<p>Make your ampersands stand out using this short snippet. Simply change the font-family to suit your preference.</p>
<pre name="code" class="css">
.amp {
font-family: Baskerville, 'Goudy Old Style', Palatino, 'Book Antiqua', serif;
font-style: italic;
font-weight: normal;
}
</pre>
<p><strong>15. <a href="http://loneplacebo.com/css-snippets/" title="Pull Quotes for Improved Reading">Pull Quotes for Improved Reading</a> </strong></p>
<p>Make your quotes stand out more by floating them to the right or left hand side of your content and wrapping content around it.</p>
<pre name="code" class="css">
.pullquote {
width: 300px;
float: right;
margin: 5px;
font-family: Georgia, "Times New Roman", Times, serif;
font: italic bold #ff0000 ; }
</pre>
<p><strong>16. <a href="http://loneplacebo.com/css-snippets/" title="Rounded Borders Around Images">Rounded Borders Around Images</a> </strong></p>
<p>With CSS3 you can easily place rounded borders around your images using this snippet.</p>
<pre name="code" class="css">
img {
-webkit-border-radius: 25px;
-moz-border-radius: 25px;
border-radius: 25px;
}
</pre>
<p><strong>17. <a href="http://www.webdesigncreare.co.uk/blog/web-designers/useful-css-snippets.html" title="Image Preloader">Image Preloader</a> </strong></p>
<p>Load a small gif in the background of an image first so that it is showed before the main image loads.</p>
<pre name="code" class="css">
img
{
    background: url(img/preloader.gif) no-repeat 50% 50%;
}
</pre>
<p><strong>18. <a href="http://www.zenelements.com/blog/css3-opacity/" title="CSS3 Opacity">CSS3 Opacity</a> </strong></p>
<p>By using the opacity property, which lets you see through an element, you can create a layered textured background.</p>
<pre name="code" class="css">
div.L1 { background:#036; opacity:0.2; height:20px; }
div.L2 { background:#036; opacity:0.4; height:20px; }
div.L3 { background:#036; opacity:0.6; height:20px; }
div.L4 { background:#036; opacity:0.8; height:20px; }
div.L5 { background:#036; opacity:1.0; height:20px; }
</pre>
<p><strong>19. <a href="http://devsnippets.com/article/reviews/css-code-snippets-15-wicked-tricks.html" title="Highlight links that open in a new window">Highlight links that open in a new window</a> </strong></p>
<p>This snippet allows you to easily distinguish links that open in new browser/tab windows by styling them different from other links.</p>
<pre name="code" class="css">
a[target="_blank"]:before,
a[target="new"]:before {
margin:0 5px 0 0;
padding:1px;
outline:1px solid #333;
color:#333;
background:#ff9;
font:12px "Zapf Dingbats";
content: "\279C";
 }
</pre>
<p><strong>20. <a href="http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax" title="The New Bulletproof @Font-Face Syntax">The New Bulletproof @Font-Face Syntax</a> </strong></p>
<p>A cross-browser CSS snippet that lets you define your font faces.</p>
<pre name="code" class="css">
@font-face {
	font-family: 'MyFontFamily';
	src: url('myfont-webfont.eot?#iefix') format('embedded-opentype'),
	     url('myfont-webfont.woff') format('woff'),
	     url('myfont-webfont.ttf')  format('truetype'),
	     url('myfont-webfont.svg#svgFontName') format('svg');
	}
</pre>
<p><strong>21. <a href="http://css-tricks.com/snippets/css/flip-an-image/" title="Flip an Image">Flip an Image</a></strong></p>
<p>A CSS snippet that lets you flip an image. This is particularly useful if you want to flip icons such as arrows.</p>
<pre name="code" class="css">
img {
        -moz-transform: scaleX(-1);
        -o-transform: scaleX(-1);
        -webkit-transform: scaleX(-1);
        transform: scaleX(-1);
        filter: FlipH;
        -ms-filter: "FlipH";
}
</pre>
<p><strong>22. <a href="http://blog.leegustin.com/code-snippets/" title="Email Link With An Image">Email Link With An Image</a> </strong></p>
<p>A quick way of automatically adding a mail image to all of your email links.</p>
<pre name="code" class="css">
a[href^="mailto:"] {
     background: url(images/email.png) no-repeat right top;
     padding-right:10px;
}
</pre>
<p><strong>23. <a href="http://blog.leegustin.com/code-snippets/" title="Beautiful Blockquotes">Beautiful Blockquotes</a> </strong></p>
<p>A neat way of styling your blockquotes to add a bit more punch to them.</p>
<pre name="code" class="css">
blockquote {
     background:#f9f9f9;
     border-left:10px solid #ccc;
     margin:1.5em 10px;
     padding:.5em 10px;
     quotes:"\201C""\201D""\2018""\2019";
}
blockquote:before {
     color:#ccc;
     content:open-quote;
     font-size:4em;
     line-height:.1em;
     margin-right:.25em;
     vertical-align:-.4em;
}
blockquote p {
     display:inline;
}
</pre>
<p><strong>24. <a href="http://paulirish.com/2009/browser-specific-css-hacks/" title="Browser CSS hacks">Browser CSS hacks</a> </strong></p>
<p>A large list of browser hacks to make sure your website looks consistent across all browsers.</p>
<pre name="code" class="css">
/***** Selector Hacks ******/

/* IE6 and below */
* html #uno  { color: red }

/* IE7 */
*:first-child+html #dos { color: red } 

/* IE7, FF, Saf, Opera  */
html>body #tres { color: red }

/* IE8, FF, Saf, Opera (Everything but IE 6,7) */
html>/**/body #cuatro { color: red }

/* Opera 9.27 and below, safari 2 */
html:first-child #cinco { color: red }

/* Safari 2-3 */
html[xmlns*=""] body:last-child #seis { color: red }

/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:nth-of-type(1) #siete { color: red }

/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:first-of-type #ocho {  color: red }

/* saf3+, chrome1+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {
 #diez  { color: red  }
}

/* iPhone / mobile webkit */
@media screen and (max-device-width: 480px) {
 #veintiseis { color: red  }
}

/* Safari 2 - 3.1 */
html[xmlns*=""]:root #trece  { color: red  }

/* Safari 2 - 3.1, Opera 9.25 */
*|html[xmlns*=""] #catorce { color: red  }

/* Everything but IE6-8 */
:root *> #quince { color: red  }

/* IE7 */
*+html #dieciocho {  color: red }

/* Firefox only. 1+ */
#veinticuatro,  x:-moz-any-link  { color: red }

/* Firefox 3.0+ */
#veinticinco,  x:-moz-any-link, x:default  { color: red  }

/* FF 3.5+ */
body:not(:-moz-handler-blocked) #cuarenta { color: red; }

/***** Attribute Hacks ******/

/* IE6 */
#once { _color: blue }

/* IE6, IE7 */
#doce { *color: blue; /* or #color: blue */ }

/* Everything but IE6 */
#diecisiete { color/**/: blue }

/* IE6, IE7, IE8 */
#diecinueve { color: blue\9; }

/* IE7, IE8 */
#veinte { color/*\**/: blue\9; }

/* IE6, IE7 -- acts as an !important */
#veintesiete { color: blue !ie; } /* string after ! can be anything */

/* IE8, IE9 */
#anotherone  {color: blue\0/;} /* must go at the END of all rules */
</pre>
<p><strong>25. <a href="http://www.madtomatoe.com/css-change-default-text-selection-color/" title="How To Change The Default Text Selection Color on your Blog">How To Change The Default Text Selection Color on your Blog</a></strong></p>
<p>Change the color of highlighted text by adding this little CSS snippet to your stylesheet.</p>
<pre name="code" class="css">
::selection {
   background: #ffb7b7; /* Safari */
        color: #ffffff;
   }
::-moz-selection {
   background: #ffb7b7; /* Firefox */
        color: #ffffff;
   }
</pre>
<p><strong>26. <a href="http://www.1stwebdesigner.com/design/useful-css-snippets/" title="Clearfix">Clearfix</a> </strong></p>
<p>Clear floated elements easily by creating a CSS clear class.</p>
<pre name="code" class="css">
.clearfix:after {
	visibility: hidden;
	display: block;
	font-size: 0;
	content: " ";
	clear: both;
	height: 0;
}

.clearfix { display: inline-block; }

/* start commented backslash hack \*/
* html .clearfix { height: 1%; }
.clearfix { display: block; }
/* close commented backslash hack */
</pre>
<p><strong>27. <a href="http://www.codecollector.net/mafis/library/12857/Hide_text_with_text_indent" title="Hide Logo Text With Text Indent">Hide Logo Text With Text Indent</a> </strong></p>
<p>Make your logo is SEO friendly by using this snippet for your h1 tag. The snippet ensures that the logo text is not displayed on the page.</p>
<pre name="code" class="css">
h1 {
        text-indent:-9999px;
        margin:0 auto;
        width:400px;
        height:100px;
        background:transparent url("images/logo.jpg") no-repeat scroll;
}
</pre>
<p><strong>28. <a href="http://speckyboy.com/2011/04/15/25-css-snippets-for-some-of-the-most-common-and-frustrating-tasks/" title="Reset all Text Colors and Background Colors">Reset all Text Colors and Background Colors</a> </strong></p>
<p>Reset all text and background colours. The snippet sets everything back to black text on a white background though you can change these colours accordingly.</p>
<pre name="code" class="css">
* {
     color: black !important;
     background-color: white !important;
     background-image: none !important;
}
</pre>
<p><strong>29. <a href="http://www.djavupixel.com/development/css-development/master-css3-ultimate-css-code-snippets/" title="Multiple Background Images">Multiple Background Images</a> </strong></p>
<p>Use multiple background images with this useful CSS3 snippet. </p>
<pre name="code" class="css">
#multiple-images {
   background: url(image_1.png) top left no-repeat,
   url(image_2.png) bottom left no-repeat,
   url(image_3.png) bottom right no-repeat;
}
</pre>
<p><strong>30. <a href="http://www.djavupixel.com/development/css-development/master-css3-ultimate-css-code-snippets/" title="Linear Gradient">Linear Gradient</a> </strong></p>
<p>This CSS code will allow you to create a linear gradient in the background of an element. This works on all major browsers however some older browsers don&#8217;t display it properly (particularly older versions of IE).</p>
<pre name="code" class="css">
background-image: -webkit-linear-gradient(top, #F0ECE8 0%, #D8D3C8 100%);
background-image: -moz-linear-gradient( top, #F0ECE8 0%, #D8D3C8 100%);
background-image: -o-linear-gradient( top, #F0ECE8 0%, #D8D3C8 100%);
background-image: linear-gradient( top, #F0ECE8 0%, #D8D3C8 100%);
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #F0ECE8), color-stop(1, #D8D3C8) );
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=â€™#F0ECE8?, endColorstr=â€™#D8D3C8?,GradientType=0 );
</pre>
<p>We hope that you enjoyed the post and found it as useful as we&#8217;d hoped. If you know of any other useful CSS snippets that you keep handy that we neglected, please share them with us in the comment area.</p>
<p><em>(rb)</em></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Noupe?a=ThT6zPVmMn0:b3dX4xQeECg:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Noupe?i=ThT6zPVmMn0:b3dX4xQeECg:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Noupe?a=ThT6zPVmMn0:b3dX4xQeECg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Noupe?i=ThT6zPVmMn0:b3dX4xQeECg:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Noupe?a=ThT6zPVmMn0:b3dX4xQeECg:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Noupe?i=ThT6zPVmMn0:b3dX4xQeECg:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Noupe?a=ThT6zPVmMn0:b3dX4xQeECg:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Noupe?d=7Q72WNTAKBA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2012/01/useful-css-snippets-for-your-coding-arsenal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resolution Independence With SVG</title>
		<link>http://blogmyquery.com/index.php/2012/01/resolution-independence-with-svg/</link>
		<comments>http://blogmyquery.com/index.php/2012/01/resolution-independence-with-svg/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 13:35:00 +0000</pubDate>
		<dc:creator>David Bushell</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://mgmt.smashingmagazine.com/?p=122990</guid>
		<description><![CDATA[<table width="650"><tr><td width="650"><div>
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=1" border="0" alt="" /></a>&#160;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=2" border="0" alt="" /></a>&#160;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=3" border="0" alt="" /></a>
    </div></td></tr></table>
<p>In this article, weâ€™ll look at Scalable Vector Graphics (SVG), one of the most underused technologies in website development today. Before diving into an example, letâ€™s consider the state of the Web at present and where it is going.Â Website design has found new vigor in recent years, with the evolving technique of <strong>responsive design</strong>. </p>

<p><a href="http://coding.smashingmagazine.com/2012/01/16/resolution-independence-with-svg/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2012/01/resolution-independence.png" alt="Resolution Independence with SVG" width="500" height="250" /></a></p>

<p>And for good reason: essentially, responsive website design moves us away from the fixed-width pages weâ€™ve grown accustomed to, replacing them with shape-shifting layouts and intelligent reflowing of content. Add to that a thoughtful content strategy and mobile-first approach, and weâ€™re starting to offer an experience that adapts across devices and browsers to suit the userâ€™s context.</p>]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=1" ><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=2" ><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=3" ><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=3" border="0" alt="" /></a>
    </div>
</td>
</tr>
</table>
<p>In this article, weâ€™ll look at Scalable Vector Graphics (SVG), one of the most underused technologies in website development today.</p>
<p>Before diving into an example, letâ€™s consider the state of the Web at present and where it is going.Â Website design has found new vigor in recent years, with the evolving technique of <strong>responsive design</strong>. And for good reason: essentially, responsive website design moves us away from the fixed-width pages weâ€™ve grown accustomed to, replacing them with shape-shifting layouts and intelligent reflowing of content. Add to that a thoughtful content strategy and mobile-first approach, and weâ€™re starting to offer an experience that adapts across devices and browsers to suit the userâ€™s context.</p>
<p>When we look at the breadth of Web-enabled devices, responsive design is sure to provide a better user experience. Scrolling horizontally, panning and zooming the viewport have their place in user interface design, but forcing the user to do these things just to navigate a website quickly becomes tedious. Fitting the website to the viewportÂ is about more than just layout: itâ€™s also about <strong>resolution</strong>. In this article, Iâ€™ll demonstrate why SVG is a perfect addition to future-friendly Web development.</p>
<h4>Introducing SVG</h4>
<p>SVG offers a truly resolution-independent technique for presenting graphics on the Web. SVG is a vector graphics format that uses <strong>XML</strong> to define basic properties such as paths, shapes, fonts and colors, and more advanced features such as gradients, filters, scripting and animation.Â Create the file once and use it anywhere, at any scale and resolution.</p>
<p>Consider the use cases: <strong>UI and navigation icons, vector-style illustrations, patterns and repeating backgrounds</strong>. For all of these, a scalable graphic is the perfect solution from a visual standpoint, and yet fixed-resolution images are still the norm. In the example below, weâ€™ll show you how to expand on a common development technique to take advantage of SVG.</p>
<p><img class="alignnone size-full wp-image-119442" title="Resolution Independency with SVG" src="http://media.smashingmagazine.com/wp-content/uploads/2011/11/svg-header1.png" alt="Resolution independence with SVG" width="500" /></p>
<h3>A Case Study: CSS Sprites</h3>
<p>We all know about the CSS sprites technique. (If you donâ€™t, then have a quick read through <a title="CSS Sprites: Useful Technique, or Potential Nuisance?" href="http://coding.smashingmagazine.com/2009/04/27/the-mystery-of-css-sprites-techniques-tools-and-tutorials/">Sven Lennartzâ€™ article</a>. And Louis Lazaris points out its <a title="CSS Sprites: Useful Technique, or Potential Nuisance?" href="http://coding.smashingmagazine.com/2010/03/26/css-sprites-useful-technique-or-potential-nuisance/">pros and cons</a>.) In the example below, weâ€™ll show how seamlessly SVG replaces normal raster images. If this technique is not for you, you can certainly imagine a whole array of similar situations in which to use SVG.</p>
<p>Vector icons play a big role in user interface design. Pictures express concepts with vivid clarity, whereas their textual counterparts might carry ambiguity. In UI design, where space is scarce, a simple illustrated icon could be greatly welcome.</p>
<p>Iâ€™ve mocked up the following example:</p>
<p><img class="alignnone size-full wp-image-119392" title="An icon based UI menu" src="http://media.smashingmagazine.com/wp-content/uploads/2011/11/fig1-finalmenu.png" alt="An icon based UI menu" width="432" height="60" /></p>
<p>Iâ€™ll be first to admit that this row of icons wonâ€™t win any design awards, but it will suffice for the sake of this article! Letâ€™s look at the HTML:</p>
<pre class="brush: html">&#60;div class="actions"&#62;
   &#60;a class="a-share" href="#"&#62;Share&#60;/a&#62;
   &#60;a class="a-print" href="#"&#62;Print&#60;/a&#62;
   &#60;a class="a-tag" href="#"&#62;Tag&#60;/a&#62;
   &#60;a class="a-delete" href="#"&#62;Delete&#60;/a&#62;
&#60;/div&#62;</pre>
<p>Iâ€™ve kept the HTML to a minimum for clarity, but in practice youâ€™d probably want to mark it up with an unordered list. And youâ€™ll almost certainly want to replace those hashes with real URLs (even if JavaScript provides the functionality, having a fallback is nice). Letâ€™s look at the CSS:</p>
<pre class="brush: css">.actions {
   display: block;
   overflow: auto;
}

.actions a {
   background-image: url('sprite.png');
   background-repeat: no-repeat;
   background-color: #ccc;
   border-radius: 5px;
   display: block;
   float: left;
   color: #444;
   font-size: 16px;
   font-weight: bold;
   line-height: 20px;
   text-decoration: none;
   text-shadow: 0 -1px 2px #fff;
   padding: 10px 20px 10px 40px;
   margin-right: 5px;
}

.a-share  { background-position: 10px 0; }
.a-print  { background-position: 10px -40px; }
.a-tag    { background-position: 10px -80px; }
.a-delete { background-position: 10px -120px; }</pre>
<p>Note the fixed-pixel sizing and the PNG background, which we can see below framed in full Photoshop production glory:</p>
<p><img class="alignnone size-full wp-image-119394" title="A PNG sprite in Photoshop" src="http://media.smashingmagazine.com/wp-content/uploads/2011/11/fig2-pngsprite.png" alt="A PNG sprite in Photoshop" width="233" height="234" /></p>
<p>This implementation of a CSS sprite is basic, and at todayâ€™s standard, itâ€™s not good enough! How can we enhance this? First, letâ€™s consider the following issues:</p>
<ol>
<li>Weâ€™ve <strong>rasterized</strong> the image at a very early stage. Even at full size, icons in which points sit between pixels, such as the one for â€œPrint,â€� have blurred.</li>
<li>If we <strong>zoom in</strong>, the image will blur or pixellate even more; there is no additional data to re-render the image at larger sizes.</li>
<li>Everything has a <strong>fixed size</strong>, which is neither good for responsive design nor good for accessibility, because the browserâ€™s default font size is ignored.</li>
</ol>
<p>As youâ€™ve probably guessed by now, weâ€™ll show you how SVG solves these problems. But first, letâ€™s reiterate each point thoroughly to understand the issues at large.</p>
<h4>1. Rasterization</h4>
<p>Devices such as modern smartphones have a very high pixel density; some already surpass the 300 pixels-per-inch (PPI) mark that is assumed to be the limit of the human eyeâ€™s ability to distinguish fine details. A pixel has no real-world equivalent in size until it sits on a screen of fixed dimension (say, 3.5 inches diagonally) and fixed resolution (say, 640 Ã— 960 pixels). At this scale, text with a font size of 16 pixels would be incredibly small to the eye. For this reason, devices simply cannot translate 1 CSS pixel unit to 1 device pixel; instead, they double up. Thus, a 16-pixel font size actually takes over 32 pixels when rendered.</p>
<p>The same applies to images; but they are already rasterized, so doubling up the pixels has no benefit. In our example, each icon has been rasterized at around 25 Ã— 25 pixels (the whole sprite being 30 Ã— 160), so they cannot take advantage of the <strong>double pixel ratio</strong>. One solution is to use <strong>CSS media queries</strong> to detect the pixel ratio. This is already implemented in Webkit- and <a title="CSS media queries - device pixel ratio" href="https://developer.mozilla.org/en/CSS/Media_queries#-moz-device-pixel-ratio">Gecko</a>-based browsers.</p>
<p>To improve our example, we can add the following CSS declaration:</p>
<pre class="brush: css">@media only screen and (-webkit-min-device-pixel-ratio: 2)  {
   .actions a {
      background-image: url('sprite@2x.png');
      background-size: 30px 160px;
   }
}</pre>
<p>The alternate background image supplied in the code above has been saved at 60 Ã— 320 pixels (i.e. double the original dimensions). The <code>background-size</code> property tells CSS to treat it smaller. Significantly, now the device has the additional data to render a better image (if capable).</p>
<p>This solution isnâ€™t bad, but it doesnâ€™t solve the problems weâ€™ll run into in points 2 and 3 below. It also requires that we maintain multiple files of increasing size: a potential burden on bandwidth and a real hassle. For non-vector images, such as photography in JPG format, we canâ€™t do much more than that.</p>
<h4>2. Zooming</h4>
<p>At their default size, our rasterized icons look acceptable, at least on low-pixel-density screens. However, should the user zoom in on the Web page, these little UI delights will degrade very quickly.</p>
<p><img class="alignnone size-full wp-image-119397" title="A PNG sprite zoomed and blurred." src="http://media.smashingmagazine.com/wp-content/uploads/2011/11/fig3-zoom.png" alt="A PNG sprite zoomed in and blurred." width="453" height="104" /></p>
<p>Zooming is a common action when users find a website too small for comfortable viewing. Or, to put it another way, websites that are designed too small are very common. There is really no â€œperfectâ€� size, because almost everyone has at least some level of visual impairment, since our eyes inevitably deteriorate with age. Secondly, with the rapid increase in touchscreen devices, pinch-to-zoom has become the standard way to enlarge fixed-sized content designed for larger screens (i.e. much of the Web today).</p>
<p>We should develop websites in a way that minimizes the need for user input â€” thatâ€™s where responsive design comes in (see point 3 below) â€” but zooming is here to stay. Thereâ€™s simply no way to provide pre-rasterized images for every level of zoom (in theory, an infinite scale). Scalable graphics are the solution, and weâ€™ll show you how to enhance our example. But first, a related word on fixed sizing.</p>
<h4>3. Fixed Sizes</h4>
<p>Presenting page elements at fixed sizes forces many users to zoom, but it also disables a very useful browser feature. Users can set their preferred font size (the default in browsers is 16 pixels). By sizing everything in pixels, we override this preference. Sizing elements based on this default is much better, so that, if the text is bigger, everything adjusts to match. This essentially mimics the zooming effect but happens without the user having to manually do it on every visit. Ethan Marcotte has written a great article that <a title="Type study: Sizing the legible letter" href="http://blog.typekit.com/2011/11/09/type-study-sizing-the-legible-letter/">explains relative font sizes</a>.</p>
<p>Letâ€™s re-implement our sprite example with a solution to these three issues.</p>
<h4>A Scalable Implementation</h4>
<p>Here is the HTML again. We donâ€™t need to change anything here.</p>
<pre class="brush: html">&#60;div class="actions"&#62;
   &#60;a class="a-share" href="#"&#62;Share&#60;/a&#62;
   &#60;a class="a-print" href="#"&#62;Print&#60;/a&#62;
   &#60;a class="a-tag" href="#"&#62;Tag&#60;/a&#62;
   &#60;a class="a-delete" href="#"&#62;Delete&#60;/a&#62;
&#60;/div&#62;</pre>
<p>The updated CSS is where the magic happens:</p>
<pre class="brush: css">body { font-size: 100%; }

.actions {
   display: block;
   overflow: auto;
}

.actions a {
   font-size: 1em;
   line-height: 1.25em;
   padding: 0.625em 1.25em 0.625em 2.5em;
   margin-right: 0.3125em;
   border-radius: 0.3125em;
   background-image: url('sprite.svg');
   -webkit-background-size: 1.875em 10em;
   -o-background-size: 1.875em 10em;
   -moz-background-size: 1.875em 10em;
   background-size: 1.875em 10em;
   /* styles carried over from the original implementation */
   background-repeat: no-repeat;
   background-color: #ccc;
   color: #444;
   display: block;
   float: left;
   text-decoration: none;
   text-shadow: 0 -1px 2px #fff;
}

.actions-em .a-share { background-position: 0.625em 0; }
.actions-em .a-print { background-position: 0.625em -2.5em;  }
.actions-em .a-tag { background-position: 0.625em -5.0em;  }
.actions-em .a-delete { background-position: 0.625em -7.5em;  }</pre>
<p>In this version, weâ€™ve made the following changes:</p>
<ul>
<li>The <code>background-image</code> is now an SVG file.</li>
<li>All sizes are based on the default of 16 pixels, or 1 em. If the userâ€™s default is larger or smaller, then everything will scale relatively. (If you multiple each em size by 16, youâ€™ll get the number of pixels used in our initial fixed-size example.)</li>
<li>The <strong><code>background-size</code> is very important</strong>. By setting this in em units, weâ€™re telling the browser to scale the sprite relative to everything else. Youâ€™ll notice that 1.875 Ã— 10 em multiplied by 16 becomes 30 Ã— 160 â€” the base size at which we produced the sprite in pixels.</li>
<li>The <code>background-position</code> of each sprited icon is also based on relative units.</li>
</ul>
<p>Now that weâ€™re using SVG and relative sizes, we have solved the three big issues highlighted above. A scalable graphic can be rasterized on demand to perfectly suit any device resolution and any zoom level. By using relative sizes, we can continue implementing a responsive design, minimizing as much as possible the need for the user to zoom. Weâ€™re also respecting the browserâ€™s default font size, and enabling our design to adapt accordingly.</p>
<p>I actually produced the SVG sprite first and the PNG version from that. (I imported the SVG in Photoshop before exporting it as a PNG â€” Illustratorâ€™s PNG export had very poor rasterization.) Below is the header in my SVG file. Notice the same 30 Ã— 160 initial size.</p>
<pre class="brush: xml">&#60;svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
   width="30px" height="160px" viewBox="0 0 30 160" enable-background="new 0 0 30 160" xml:space="preserve"&#62;</pre>
<p>You can see that the attributes for width and height are set in pixels (<code>width="30px" height="160px"</code>) in the opening <code>svg</code> tag (as generated by Adobe Illustrator). This actually causes it to render early in Firefox, before the graphic has scaled to match theÂ em sizes in <code>background-size</code>. Webkit-based browsers seem to scale the SVG perfectly, regardless. Iâ€™ve found that editing the SVG file to use em units in these two attributes fixes any rendering issues in Firefox.</p>
<pre class="brush: xml">&#60;svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
   width="30em" height="160em" viewBox="0 0 30 160" enable-background="new 0 0 30 160" xml:space="preserve"&#62;</pre>
<p>I donâ€™t know which browser actually implements this scaling correctly, but let it be noted that extra care is needed to ensure cross-browser perfection. Mozilla MDN has an excellent in-depth article, â€œ<a title="Scaling of SVG backgrounds" href="https://developer.mozilla.org/en/CSS/Scaling_of_SVG_backgrounds">Scaling of SVG Backgrounds</a>,â€� which explores more practical examples. For more ideas, see Alex Walkerâ€™s articleÂ â€œ<a title="A Farewell to CSS3 Gradients" href="http://designfestival.com/a-farewell-to-css3-gradients/A%20Farewell%20to%20CSS3%20Gradients">A Farewell to CSS3 Gradients</a>.â€�</p>
<p>Hereâ€™s a super-close screenshot showing the SVG sprite:</p>
<p><img class="alignnone size-full wp-image-119399" title="A close-up of a SVG sprite." src="http://media.smashingmagazine.com/wp-content/uploads/2011/11/fig4-closeup.png" alt="A close-up of a SVG sprite." width="455" height="187" /></p>
<p>The sprite scales beautifully. (Sadly, the same canâ€™t be said for my tacky text-shadow effect.)</p>
<p>Itâ€™s best to experience the joys of scalable graphics and relative sizing firsthand. Iâ€™ve uploaded a <a title="Scalable Sprites in Action" href="http://dbushell.com/demos/css-sprites/">side-by-side live demo</a> demonstrating a combination of all the techniques mentioned above.</p>
<h3>Browser Support</h3>
<p>At the start of this article, I said that SVG was underused. I believe that has generally been the case due to poor browser support. But things are different now! Browser support for SVG has blossomed over the last year to the point where implementing it is a viable use of development time.</p>
<p>According to the website <a title="When can I use SVG?" href="http://caniuse.com/#search=SVG">When Can I Use?</a>, support for SVG across multiple implementations is as follows (Iâ€™ve combined support for both CSSâ€™Â <code>background-image</code> and HTMLâ€™sÂ <code>img</code> source â€” the most useful attributes):</p>
<ul>
<li>Internet Explorer 9+</li>
<li>Firefox 4+</li>
<li>Chrome 4+</li>
<li>Safari 4+</li>
<li>Opera 9.5+</li>
</ul>
<p><a title="Mobile HTML5" href="http://mobilehtml5.org/">Mobile browser support</a> is also pretty much across the board. If a workable fallback exists for older browsers, then SVG is aÂ very viable solution.</p>
<p>For some of the new additions to Web standards, we can implement them safe in the knowledge that old browsers will simply ignore them and that they arenâ€™t even required. We call thisÂ â€œprogressive enhancementâ€�: better browsers get a progressively better experience.Â SVG is slightly different, because for most practical purposes, it simply replaces other images in CSS backgrounds and HTML elements. The image format â€” be it SVG, PNG, JPG or GIF â€” is either supported or it isnâ€™t. We canâ€™t simply follow the practice of progressive enhancement here, because an image failing to render is not an acceptable experience.</p>
<h4>Browser Sniffing or Feature Detection?</h4>
<p>We could make an educated guess and say that we need to worry only about users of Internet Explorer 6 to 8. In this case, the <a title="HTML5 Boilerplate - IE html tag classes" href="http://html5boilerplate.com/docs/The-markup/#ie-html-tag-classes">conditional comments technique</a> for IE-only styles enable us to re-apply a second CSS <code>background-image</code> of a supported format such as PNG, instead of the default SVG background.</p>
<p>Browsing sniffing is always a dangerous game. While Internet Explorer tends to be the main offender, we can never assume it is the only one.</p>
<p>The safer and highly recommended option is to detect SVG support and use it only if itâ€™s found. I suggest using <a title="Modernizr" href="http://www.modernizr.com/">Modernizr</a> if you need to detect multiple features. Modernizr applies a class of <code>svg</code>Â to your root <code>html</code> element if detected (to which you can apply SVG as aÂ <code>background-image</code>).Â If youâ€™re using SVG as the source of an image element in HTML, then implementation is a little harder. Youâ€™ll have to write more JavaScript to find and replace all sources once support has been established.</p>
<p>The problem with these methods is that the browser will download the fallback image before SVG is detected â€” the only exception being the conditional comments technique for IE.Â Users will also likely see a flash of re-styled content when the source image changes.Â This shouldnâ€™t be the case for long; but at least for now, these problems may be enough to hold you off on SVG usage.</p>
<h4>File Size</h4>
<p>In our sprite example, the raw SVG file was 2445 bytes. The PNG version was only 1064 bytes, and the double-sized PNG for double-pixel ratio devices was 1932 bytes. On first appearance, the vector file loses on all accounts, but for larger images, the raster version more quickly escalates in size.</p>
<p>SVG files are also human-readable due to being in XML format. They generally comprise a very limited range of characters, which means they can be heavily Gzip-compressed when sent over HTTP. This means that the actual download size is many times smaller than the raw file â€” easily beyond 30%, probably a lot more. Raster image formats such as PNG and JPG are already compressed to their fullest extent.</p>
<h4>Performance</h4>
<p>Rendering performance is a concern with SVG, especially on mobile devices, whose hardware is limited. Raster images can be rendered pixel for pixel after decompression and de-encoding. Vector graphics need to be rasterized at a specific resolution every time theyâ€™re viewed.</p>
<p>SVG has <a title="Comparing hardware-accelerated SVG across browsers with Santaâ€™s Workshop" href="http://blogs.msdn.com/b/ie/archive/2011/03/08/comparing-hardware-accelerated-svg-across-browsers-with-santa-s-workshop.aspx">consistently</a> <a title="SVG vs Canvas performance" href="http://joeloughton.com/blog/web-applications/svg-vs-canvas-performance/">proved</a> <a title="Performance of Canvas versus SVG" href="http://smus.com/canvas-vs-svg-performance">slower</a>Â than Canvas as a platform for animating vector graphics; but our concern here is basic rendering, not manipulation a thousand times per second, and if <em>that</em> is possible, then simple rendering shouldnâ€™t be a concern.Â The more intensive SVG features are things like clipping masks and filter effects. These are unnecessary for many practical purposes (like our sprite example), but, if required, the best way to check performance is by <strong>testing</strong>. A lot of Web development is supported in theory, but in practice results are far from perfect.</p>
<h3>Alternative Methods</h3>
<p>Hopefully you agree that SVG is extremely useful but not always the ideal solution to resolution independence. Ultimately, the trick is to avoid raster images while maintaining the scalability of visual styles. Below are a few more ideas to think about.</p>
<h4>CSS3</h4>
<p>Youâ€™ve probably already started combining CSS3 properties such as <code>linear-gradient</code>, <code>text-shadow</code> and <code>box-shadow</code> to create more complex styles. Web developer Lea Verou curates aÂ <a title="Lea Verou â€” CSS Patterns" href="http://lea.verou.me/css3patterns/">CSS3 pattern gallery</a> that shows off the impressive potential of gradients alone.</p>
<p><a href="http://lea.verou.me/css3patterns/"><img title="CSS3 gradient patterns" src="http://media.smashingmagazine.com/wp-content/uploads/2011/12/css3patterns.png" alt="CSS3 gradient patterns" width="500" height="220" /></a></p>
<p>In his article â€œ<a title="Mobile Web in High Resolution" href="http://bradbirdsall.com/mobile-web-in-high-resolution">Mobile Web in High Resolution</a>,â€� Brad Birdsall introduces a technique to maintain pixel perfection for high-resolution displays using the pixel-ratio property.</p>
<p>Then there are pure CSS â€œicons,â€� whichÂ <a title="Pure CSS Icons: Make The Madness Stop" href="http://farukat.es/journal/2010/08/469-pure-css-icons-make-madness-stop">Faruk AteÅŸ</a> rightlyÂ points out as being absolute â€œmadnessâ€� â€” certainly so if youâ€™re using CSS to create a logo! But you could argue the benefits of a small handful of very specific techniques, such asÂ CSS triangles, as <a title="CSS Triangle | CSS Tricks" href="http://css-tricks.com/snippets/css/css-triangle/">demoed by Chris Coyier</a>.</p>
<h4>Web Fonts</h4>
<p><a title="Dingbat Web Fonts" href="http://filamentgroup.com/lab/dingbat_webfonts_accessibility_issues/">Dingbat Web fonts</a> andÂ look-a-like Unicode glyphsÂ are two interesting alternatives for vector icons, both with accessibility and semantic challenges.Â <a title="24 Ways: Displaying Icons with Fonts and Data- Attributes" href="http://24ways.org/2011/displaying-icons-with-fonts-and-data-attributes">Jon Hicks has a write-up</a> of perhaps the best practice for this. SVG seems a more appropriate technique for icons, but both have an immediate visual impact at high resolutions â€” and weâ€™ll be paying increasing attention to that in coming years.</p>
<h3>Looking Forward</h3>
<p>As you can see, SVG usage is very much a possibility, and browser support and performance will only improve in future. Whatâ€™s important to note from this article is that weÂ really should be building websites that are asÂ resolution-independent as possible.</p>
<p>Consider the â€œone Webâ€� philosophy and the vast range of devices we use to access it â€” there is no single user experience. The more we can do to stay device-agnostic, the better. Responsive website design addresses many of these needs and certainly provides many benefits. Using vector graphics may not be as apparent, but its little improvements really do make a difference.</p>
<p>With todayâ€™s level of support, many users can experience the beauty of crisp scalable graphicsâ€¦ or perhaps thatâ€™s the wrong way to think about it. Most users wonâ€™t say â€œWow! Kudos on the vectors.â€� To our dismay, they probably wouldnâ€™t even consider them (and certainly wouldnâ€™t recognize the effort required to craft them). And thatâ€™s a good thing; each time we improve the userâ€™s experience, we donâ€™t necessarily need to make a song and dance about it. Letting things continue to grind away under-appreciated is OK. Itâ€™s theÂ <em>lack</em> of such things that gets recognized and sniffed at. Raise the userâ€™s expectations in visual aesthetics, and theyâ€™ll start to notice the websites that do look shoddy. If you donâ€™t do it, others will.</p>
<p><em>(al)</em></p>
<hr />
<p><small>Â© dbushell for <a href="http://www.smashingmagazine.com">Smashing Magazine</a>, 2012.</small></p>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2012/01/resolution-independence-with-svg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Introduction To Object Oriented CSS (OOCSS)</title>
		<link>http://blogmyquery.com/index.php/2011/12/an-introduction-to-object-oriented-css-oocss/</link>
		<comments>http://blogmyquery.com/index.php/2011/12/an-introduction-to-object-oriented-css-oocss/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 15:11:46 +0000</pubDate>
		<dc:creator>Louis Lazaris</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://mgmt.smashingmagazine.com/?p=120512</guid>
		<description><![CDATA[<table width="650">
  <tr>
    <td width="650">
      <div>
        <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=1" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=1" border="0" alt="" />
        </a>
        &#160;
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=2" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=2" border="0" alt="" />
        </a>
        &#160;
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=3" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=3" border="0" alt="" />
        </a>
      </div>
    </td>
  </tr>
</table><p>Have you ever heard the phrase â€œ<strong>Content is King</strong>â€�? Being a Web developer, and therefore having a job thatâ€™s often linked to content creation, itâ€™s likely you have. Itâ€™s a fairly overused but true statement about what draws visitors to a site. From a Web developerâ€™s perspective, however, some may argue that <strong>speed is king</strong>. More and more, Iâ€™m starting to favour that stance. In recent years many experienced front-end engineers have offered their suggestions on how we can improve the user experience by means of some performance best practices.</p>

<p><a href="http://coding.smashingmagazine.com/2011/12/12/an-introduction-to-object-oriented-css-oocss/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/12/oocss-splash1.jpg" width="500" height="375" alt="An Introduction to Object Oriented CSS" /></a></p>

<p>Unfortunately, CSS seems to get somewhat overlooked in this area while many developers (for good reason) focus largely on JavaScript performance and other areas. In this post, Iâ€™ll deal with this often overlooked area by introducing you to the concept of object oriented CSS and how it can help improve both the performance and maintainability of your Web pages.</p>]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
        <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=1" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=1" border="0" alt="" /><br />
        </a><br />
        &nbsp;<br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=2" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=2" border="0" alt="" /><br />
        </a><br />
        &nbsp;<br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=3" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=3" border="0" alt="" /><br />
        </a>
      </div>
</td>
</tr>
</table>
<p>Have you ever heard the phrase &#8220;Content is King&#8221;? Being a Web developer, and therefore having a job that&#8217;s often linked to content creation, it&#8217;s likely you have. It&#8217;s a fairly overused but true statement about what draws visitors to a site.</p>
<p>From a Web developer&#8217;s perspective, however, some may argue that <a href="http://www.stevesouders.com/blog/2009/10/06/business-impact-of-high-performance/">speed is king</a>. More and more, I&#8217;m starting to favour that stance. In recent years many experienced front-end engineers have <a href="http://www.stevesouders.com/blog/">offered their suggestions</a> on how we can improve the user experience by means of some performance <a href="http://www.amazon.com/High-Performance-Web-Sites-Essential/dp/0596529309">best</a> <a href="http://www.amazon.com/Even-Faster-Web-Sites-Performance/dp/0596522304/">practices</a>.</p>
<p>Unfortunately, CSS seems to get somewhat overlooked in this area while many developers (for good reason) focus largely on JavaScript performance and <a href="http://developer.yahoo.com/performance/rules.html">other areas</a>.</p>
<p>In this post, I&#8217;ll deal with this often overlooked area by introducing you to the concept of <strong>object oriented CSS</strong> and how it can help improve both the performance and maintainability of your Web pages.</p>
<h3>The Principles Of OOCSS</h3>
<p>As with any object-based coding method, the purpose of OOCSS is to encourage code reuse and, ultimately, faster and more efficient stylesheets that are easier to add to and maintain.</p>
<p><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/12/oocss-splash1.jpg" alt="OOCSS" width="500" height="375" /></p>
<p>As described on the <a href="https://github.com/stubbornella/oocss/wiki">OOCSS GitHub repo&#8217;s Wiki page</a>, OOCSS is based on two main principles.</p>
<h4>Separation of Structure From Skin</h4>
<p>Almost every element on a styled Web page has different visual features (i.e. &#8220;skins&#8221;) that are repeated in different contexts. Think of a website&#8217;s branding &#8212; the colors, subtle uses of gradients, or visible borders. On the other hand, other generally invisible features (i.e. &#8220;structure&#8221;) are likewise repeated.</p>
<p>When these different features are abstracted into class-based modules, <strong>they become reusable</strong> and can be applied to any element and have the same basic result. Let&#8217;s compare some before and after code so you can see what I&#8217;m talking about.</p>
<p>Before applying OOCSS principles, you might have CSS that looks like this:</p>
<pre class="brush: css;">
#button {
	width: 200px;
	height: 50px;
	padding: 10px;
	border: solid 1px #ccc;
	background: linear-gradient(#ccc, #222);
	box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}

#box {
	width: 400px;
	overflow: hidden;
	border: solid 1px #ccc;
	background: linear-gradient(#ccc, #222);
	box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}

#widget {
	width: 500px;
	min-height: 200px;
	overflow: auto;
	border: solid 1px #ccc;
	background: linear-gradient(#ccc, #222);
	box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}
</pre>
<p>The three elements above have styles that are unique to each, and they&#8217;re applied with the non-reusable ID selector to define the styles. But they also have a number of styles in common. The common styles might exist for branding purposes or consistency of design.</p>
<p>With a little bit of planning and forethought, we can abstract the common styles so the CSS would end up instead like this:</p>
<pre class="brush: css;">
.button {
	width: 200px;
	height: 50px;
}

.box {
	width: 400px;
	overflow: hidden;
}

.widget {
	width: 500px;
	min-height: 200px;
	overflow: auto;
}

.skin {
	border: solid 1px #ccc;
	background: linear-gradient(#ccc, #222);
	box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}
</pre>
<p>Now all the elements are using classes, the common styles are combined into a reusable &#8220;skin&#8221; and nothing is unnecessarily repeated. We just need to apply the &#8220;skin&#8221; class to all the elements and the result will be the same as what the first example would produce, except with <strong>less code and a possiblity for further reuse</strong>.</p>
<h4>Separation of Containers and Content</h4>
<p>The second principle described on the OOCSS GitHub wiki page is the separation of containers from their content. To illustrate why this is important, take the following CSS:</p>
<pre class="brush: css;">
#sidebar h3 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: .8em;
	line-height: 1;
	color: #777;
	text-shadow: rgba(0, 0, 0, .3) 3px 3px 6px;
}
</pre>
<p>These styles will apply to any third-level headings that are children of the <code>#sidebar</code> element. But what if we want to apply the exact same styles to third-level headings that appear in the footer, with the exception of a different font size and a modified text shadow?</p>
<p>Then we would need to do something like this:</p>
<pre class="brush: css;">
#sidebar h3, #footer h3 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 2em;
	line-height: 1;
	color: #777;
	text-shadow: rgba(0, 0, 0, .3) 3px 3px 6px;
}

#footer h3 {
	font-size: 1.5em;
	text-shadow: rgba(0, 0, 0, .3) 2px 2px 4px;
}
</pre>
<p>Or we might end up with something worse:</p>
<pre class="brush: css;">
#sidebar h3 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 2em;
	line-height: 1;
	color: #777;
	text-shadow: rgba(0, 0, 0, .3) 3px 3px 6px;
}

/* other styles here.... */

#footer h3 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 1.5em;
	line-height: 1;
	color: #777;
	text-shadow: rgba(0, 0, 0, .3) 2px 2px 4px;
}
</pre>
<p>Now we&#8217;re <strong>unnecessarily duplicating styles</strong>, and might not realize it (or simply don&#8217;t care). With OOCSS, we&#8217;re encouraged to give more forethought to what is common among different elements, then separate those common features into modules, or objects, that can be reused anywhere.</p>
<p>The styles that are declared using the descendant selector in those above examples are <em>not reusable</em>, because they are dependent on a particular container (in this case either the sidebar or the footer).</p>
<p>When we use OOCSS&#8217;s class-based module building, we ensure that our styles are not dependent on any containing element. This means they can then be <strong>reused anywhere</strong> in the document, regardless of structural context.</p>
<h3>A Real-World Example</h3>
<p>To further illustrate how OOCSS can be used, I&#8217;ll use something similar to what I did on <a href="http://www.impressivewebs.com/rolled-new-design/">my site&#8217;s recent redesign</a>. After coding the inner header element on my site, I realized that the basic structural styles for the inside of the header could be reused on other elements on the page.</p>
<p>So here&#8217;s something along the lines of what I had when I started styling my header:</p>
<pre class="brush: css;">
.header-inside {
	width: 980px;
	height: 260px;
	padding: 20px;
	margin: 0 auto;
	position: relative;
	overflow: hidden;
}
</pre>
<p>A few of the styles listed here are unique to the <code>.header-inside</code> element. But the rest can form a module that I can reuse. So I can <strong>abstract the structural styles</strong> into their own reusable class. Here&#8217;s the result:</p>
<pre class="brush: css;">
.globalwidth {
	width: 980px;
	margin: 0 auto;
	position: relative;
	padding-left: 20px;
	padding-right: 20px;
	overflow: hidden;
}

.header-inside {
	padding-top: 20px;
	padding-bottom: 20px;
	height: 260px;
}
</pre>
<p>The styles belonging to the <code>.globalwidth</code> class cover the following:</p>
<ul>
<li>A fixed width</li>
<li>Centering using margin: auto</li>
<li>Relative positioning to create a positioning context for child elements</li>
<li>Left and right padding of 20px</li>
<li>Overflow set to &#8220;hidden&#8221; for clearfixing</li>
</ul>
<p>Now we&#8217;re free to use these styles on any elements that require these same characteristics by simply adding that class to the desired element &#8212; without writing a single extra line of CSS.</p>
<p>For my site, I reused these structural styles on the primary content element and the inner footer element. Depending on the design, these styles could also apply to a horizontal navigation element that might appear between the header and the content, or any other element that has a fixed-width and needs to be centered on the page.</p>
<p>After adding the &#8220;globalwidth&#8221; styles to these elements, the markup would look something like this:</p>
<pre class="brush: html;">
&#60;header&#62;
	&#60;div class="header-inside globalwidth"&#62;
	&#60;/div&#62;
&#60;/header&#62;

&#60;div class="main globalwidth"&#62;
&#60;/div&#62;

&#60;header&#62;
	&#60;div class="footer-inside globalwidth"&#62;
	&#60;/div&#62;
&#60;/footer&#62;
</pre>
<p>Some may feel that this type of styles abstraction clutters the HTML and goes against the principle of separating markup from presentation.</p>
<p>But putting aside any debates about how this might affect the markup, no one can question that this abstraction has now made it <strong>easier to track down and modify the common styles</strong> that are used to structure these three elements.</p>
<h3>The Media Object</h3>
<p>One of the pioneers of the OOCSS movement is <a href="http://www.stubbornella.org/">Nicole Sullivan</a>. She&#8217;s created a reusable module called the <a href="https://github.com/stubbornella/oocss/wiki/Content">media object</a> which, as she explains, can <a href="http://www.stubbornella.org/content/2010/06/25/the-media-object-saves-hundreds-of-lines-of-code/">save hundreds of lines of code</a>.</p>
<p><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/12/media-object.jpg" alt="OOCSS" width="500" height="375" /></p>
<p>The media object is a great example of the power of OOCSS because it can contain a media element of any size with content to its right. Although many of the styles that apply to the content inside of it &#8212; and even the size of the media element itself &#8212; could change, the media object itself has common base styles that help avoid needless repetition.</p>
<h3>The Benefits Of OOCSS</h3>
<p>I&#8217;ve already alluded to some of the benefits of OOCSS. Here I&#8217;ll expand on these.</p>
<h4>Faster Websites</h4>
<p>The performance benefits of OOCSS should be fairly clear. If you have fewer styles that are repeated in your CSS, then this will lead to <strong>smaller file sizes</strong> and thus faster downloading of those resources.</p>
<p>It&#8217;s true that markup will be more cluttered and thus create larger HTML files. But in many cases the amount of loss in markup performance will be greatly surpassed by the amount of gain in stylesheet performance.</p>
<p>Another concept to keep in mind is something that the OOCSS wiki refers to as <strong>performance freebies</strong>. This refers to the fact that every time you reuse something in your CSS, you&#8217;re essentially creating new styled elements with zero lines of CSS code. For large, high-traffic projects, these &#8220;freebies&#8221; could be <a href="http://www.svennerberg.com/2008/12/page-load-times-vs-conversion-rates/">a crucial performance gain</a>.</p>
<h4>Maintainable Stylesheets</h3>
<p>With OOCSS, instead of a constantly growing stylesheet full of specificity wars, you&#8217;ll have an <strong>easy to maintain set of modules</strong> where the natural cascade plays an important role.</p>
<p>When making additions to an existing site, you won&#8217;t be adding new styles to the bottom of your stylesheet without regard for what came before. Instead you&#8217;ll be reusing existing styles and extending your styles based on existing rule sets.</p>
<p>With this type of forethought, it&#8217;s possible to create entire pages while coding very little CSS. Any existing CSS modules can serve as a basis for all new pages, and any new CSS will be minimal. In some cases you might even be able to create a new fully-styled page without coding a single line of CSS.</p>
<p>These maintainability benefits also extend to the robustness of your stylesheets. Because the styles are modular, pages built on OOCSS will be less likely to break when a new developer starts to use the stylesheet.</p>
<h3>Points Worth Noting</h3>
<p>OOCSS has created a great deal of discussion in the community, raising some controversies. Here I&#8217;ll try to dispel a couple of common misconceptions.</p>
<h4>You Can Still Use IDs</h4>
<p>If you decide to work exclusively in an OOCSS manner, then your styles will be based largely on CSS classes, and you won&#8217;t be styling elements using the ID selector.</p>
<p>Because of this, many have falsely claimed that OOCSS encourages dropping the use of IDs completely. But this is not true.</p>
<p>The rule to avoid IDs is, more specifically, <em>don&#8217;t use IDs in selectors</em>. So it&#8217;s perfectly acceptable to use OOCSS principles (and thus avoid styling using the ID selector) while <strong>using IDs in your HTML for JavaScript hooks and fragment identifiers</strong>.</p>
<p>Of course, you may have a situation where you already have an ID applied to an element that you know is unique to the page. So, you can save a few bytes by avoiding adding a class to that element and instead style it using an ID selector. But even in this instance, it&#8217;s much safer to rely on a class to ensure you don&#8217;t run into specificity problems in the future.</p>
<h4>Dealing With Smaller Projects</h4>
<p>For smaller sites and apps, you could certainly make the case that OOCSS would be overkill. So don&#8217;t take this article as an advocacy for OOCSS in all circumstances &#8212; it will vary depending on the project.</p>
<p>Nonetheless, I think it&#8217;s a good idea, at the very least, to start thinking in terms of OOCSS in all your projects. Once you get the hang of it, I&#8217;m sure you&#8217;ll find it much easier to get it working on bigger projects where the benefits would be more noticeable and relevant.</p>
<h3>Some Guidelines For Implementation</h3>
<p>Getting started working with OOCSS could take time. I&#8217;m still working on it, so I don&#8217;t claim to have all the answers and experience in this area.</p>
<p>But here are some things you might want to start doing to help you get into an OOCSS mode of thinking:</p>
<ul>
<li>Avoid the descendent selector (i.e. don&#8217;t use <code>.sidebar h3</code>)</li>
<li>Avoid IDs as styling hooks</li>
<li>Avoid attaching classes to elements in your stylesheet (i.e. don&#8217;t do <code>div.header</code> or <code>h1.title</code>)</li>
<li>Except in some rare cases, avoid using <code>!important</code></li>
<li>Use <a href="http://csslint.net/">CSS Lint</a> to check your CSS (and know that it has options and <a href="https://github.com/stubbornella/csslint/wiki/Rules">method to its madness</a>)</li>
<li>Use <a href="http://www.stubbornella.org/content/2011/01/22/grids-improve-site-performance/">CSS grids</a></li>
</ul>
<p>There will obviously be times when some of these rules will be broken, but overall, these are good habits to develop and will lead to stylesheets that are smaller and easier to maintain.</p>
<h3>Follow Nicole Sullivan&#8217;s Work</h3>
<p>If you want to continue learning about OOCSS, the most important person in the industry to keep up with is <a href="http://www.stubbornella.org/">Nicole Sullivan</a>.</p>
<p>In addition to posting articles regularly on OOCSS on her blog, Nicole has done a number of presentations with accompanying slideshows. Below are some that you might want to check out:</p>
<ul>
<li><a href="http://www.slideshare.net/stubbornella/object-oriented-css">Object Oriented CSS</a> (Slideshow)</li>
<li><a href="http://developer.yahoo.com/blogs/ydn/posts/2009/03/website_and_webapp_performance/">High Performance Websites: Nicole Sullivan</a> (Video)</li>
<li><a href="http://www.slideshare.net/stubbornella/our-best-practices-are-killing-us">Our Best Practices Are Killing Us</a> (Slideshow)</li>
<li><a href="http://www.slideshare.net/stubbornella/css-bloat">CSS Bloat</a> (Slideshow)</li>
</ul>
<h3>Conclusion</h3>
<p>Many people fear the OOCSS ideology because it seems to go against many of the so-called &#8220;best practices&#8221; we&#8217;ve learned. But once the <strong>long-term benefits of using OOCSS</strong> are understood, I&#8217;m sure many developers will become converts.</p>
<p>Overall I think OOCSS has a bright future in CSS development, and it&#8217;s a concept that all developers should start incorporating into their projects &#8212; at least on some level &#8212; to help create Web pages that are faster, more efficient, and easier to maintain.</p>
<p><em>(il)</em></p>
<hr />
<p><small>Â© Louis Lazaris for <a href="http://www.smashingmagazine.com">Smashing Magazine</a>, 2011.</small></p>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/12/an-introduction-to-object-oriented-css-oocss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visited links can only be differentiated by colour</title>
		<link>http://blogmyquery.com/index.php/2011/12/visited-links-can-only-be-differentiated-by-colour/</link>
		<comments>http://blogmyquery.com/index.php/2011/12/visited-links-can-only-be-differentiated-by-colour/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 18:13:41 +0000</pubDate>
		<dc:creator>Roger Johansson</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://www.456bereastreet.com/archive/201112/visited_links_can_only_be_differentiated_by_colour/</guid>
		<description><![CDATA[Showing whether a link on a web page has been visited or not can be very useful. One example that many will be familiar with is how it helps you know which links you have already followed from a Google search results page â€“ links to pages you ha...]]></description>
			<content:encoded><![CDATA[<p class="preamble">Showing whether a link on a web page has been visited or not can be very useful. One example that many will be familiar with is how it helps you know which links you have already followed from a Google search results page â€“ links to pages you have already visited are a different colour than the other links.</p>

<p>Changing <em>only</em> the colour can be a bit subtle though, especially for people with <a href="http://en.wikipedia.org/wiki/Color_blindness">colour vision deficiency</a>. Depending on which colours are used to differentiate between visited and unvisited links it can be hard to tell them apart. To make the difference more obvious, there are a number of techniques involving background images, generated content (like the one I describe in <a href="http://www.456bereastreet.com/archive/200509/check_marking_visited_links/">Check marking visited links</a>), and other CSS properties. However, if youâ€™ve been using any similar tricks to style visited links, itâ€™s time to forget about those and start relying on colour alone.</p><p><a href="http://www.456bereastreet.com/archive/201112/visited_links_can_only_be_differentiated_by_colour/">Read full post</a></p><p>Posted in <a href="http://www.456bereastreet.com/archive/categories/browsers/" rel="tag">Browsers</a>, <a href="http://www.456bereastreet.com/archive/categories/css/" rel="tag">CSS</a>.</p><p>Copyright Â© <a href="http://www.456bereastreet.com/">Roger Johansson</a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/h7x6s-KFT3Zr1nvYwdh886sd2wY/0/da"><img src="http://feedads.g.doubleclick.net/~a/h7x6s-KFT3Zr1nvYwdh886sd2wY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/h7x6s-KFT3Zr1nvYwdh886sd2wY/1/da"><img src="http://feedads.g.doubleclick.net/~a/h7x6s-KFT3Zr1nvYwdh886sd2wY/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/456bereastreet?a=wU_clqiT2m8:DtTV_39zNmw:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=wU_clqiT2m8:DtTV_39zNmw:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=bcOpcFrp8Mo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=wU_clqiT2m8:DtTV_39zNmw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=wU_clqiT2m8:DtTV_39zNmw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=wU_clqiT2m8:DtTV_39zNmw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=wU_clqiT2m8:DtTV_39zNmw:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/456bereastreet/~4/wU_clqiT2m8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/12/visited-links-can-only-be-differentiated-by-colour/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The difference between width:auto and width:100%</title>
		<link>http://blogmyquery.com/index.php/2011/12/the-difference-between-widthauto-and-width100/</link>
		<comments>http://blogmyquery.com/index.php/2011/12/the-difference-between-widthauto-and-width100/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 08:05:44 +0000</pubDate>
		<dc:creator>Roger Johansson</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://www.456bereastreet.com/archive/201112/the_difference_between_widthauto_and_width100/</guid>
		<description><![CDATA[When adapting a layout for different viewport widths (a.k.a. responsive design) or media (like print), itâ€™s common to reset any float and width values on major layout blocks to linearise their display.

Unfloating a floated element is as simple ...]]></description>
			<content:encoded><![CDATA[<p class="preamble">When adapting a layout for different viewport widths (a.k.a. responsive design) or media (like print), itâ€™s common to reset any <code>float</code> and <code>width</code> values on major layout blocks to linearise their display.</p>

<p>Unfloating a floated element is as simple as specifying <code>float:none</code>. Width doesnâ€™t seem to be quite as straightforward â€“ lately Iâ€™ve come across several cases where people use <code>width:100%</code> to undo explicitly specified widths when they should be using <code>width:auto</code> instead. So hereâ€™s a brief explanation of the difference.</p><p><a href="http://www.456bereastreet.com/archive/201112/the_difference_between_widthauto_and_width100/">Read full post</a></p><p>Posted in <a href="http://www.456bereastreet.com/archive/categories/css/" rel="tag">CSS</a>, <a href="http://www.456bereastreet.com/archive/categories/quick_tips/" rel="tag">Quick Tips</a>.</p><p>Copyright Â© <a href="http://www.456bereastreet.com/">Roger Johansson</a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/WuPclAy84mgoMvWp-Mv05IkzFls/0/da"><img src="http://feedads.g.doubleclick.net/~a/WuPclAy84mgoMvWp-Mv05IkzFls/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/WuPclAy84mgoMvWp-Mv05IkzFls/1/da"><img src="http://feedads.g.doubleclick.net/~a/WuPclAy84mgoMvWp-Mv05IkzFls/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/456bereastreet?a=izAVhy0YmpY:4AUxfS0YLV8:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=izAVhy0YmpY:4AUxfS0YLV8:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=bcOpcFrp8Mo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=izAVhy0YmpY:4AUxfS0YLV8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=izAVhy0YmpY:4AUxfS0YLV8:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=izAVhy0YmpY:4AUxfS0YLV8:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=izAVhy0YmpY:4AUxfS0YLV8:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/456bereastreet/~4/izAVhy0YmpY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/12/the-difference-between-widthauto-and-width100/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Styling buttons in iOS WebKit and -webkit-appearance:none</title>
		<link>http://blogmyquery.com/index.php/2011/11/styling-buttons-in-ios-webkit-and-webkit-appearancenone/</link>
		<comments>http://blogmyquery.com/index.php/2011/11/styling-buttons-in-ios-webkit-and-webkit-appearancenone/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 19:12:33 +0000</pubDate>
		<dc:creator>Roger Johansson</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://www.456bereastreet.com/archive/201111/styling_buttons_in_ios_webkit_and_-webkit-appearancenone/</guid>
		<description><![CDATA[I just recently ran into an issue when styling buttons that had me pulling my hair for a while. I had my buttons looking the way they were supposed to look in desktop browsers, but when I went to have a look in Safari for iOS, much of my CSS wasnâ€]]></description>
			<content:encoded><![CDATA[<p class="preamble">I just recently ran into an issue when styling buttons that had me pulling my hair for a while. I had my buttons looking the way they were supposed to look in desktop browsers, but when I went to have a look in Safari for iOS, much of my CSS wasnâ€™t applied.</p>

<p>This was pretty puzzling as I couldnâ€™t remember having any problems with buttons in Safari for iOS before. After taking a closer look at the CSS I was using for these particular buttons and the CSS I had used previously, I managed to find out what made the difference.</p><p><a href="http://www.456bereastreet.com/archive/201111/styling_buttons_in_ios_webkit_and_-webkit-appearancenone/">Read full post</a></p><p>Posted in <a href="http://www.456bereastreet.com/archive/categories/css/" rel="tag">CSS</a>.</p><p>Copyright Â© <a href="http://www.456bereastreet.com/">Roger Johansson</a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/9lt9R3sBbRV1R8I5j0NGeFDK8bU/0/da"><img src="http://feedads.g.doubleclick.net/~a/9lt9R3sBbRV1R8I5j0NGeFDK8bU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/9lt9R3sBbRV1R8I5j0NGeFDK8bU/1/da"><img src="http://feedads.g.doubleclick.net/~a/9lt9R3sBbRV1R8I5j0NGeFDK8bU/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/456bereastreet?a=T6tXHaPHeRw:Mgr8VCkUIfE:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=T6tXHaPHeRw:Mgr8VCkUIfE:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=bcOpcFrp8Mo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=T6tXHaPHeRw:Mgr8VCkUIfE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=T6tXHaPHeRw:Mgr8VCkUIfE:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=T6tXHaPHeRw:Mgr8VCkUIfE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=T6tXHaPHeRw:Mgr8VCkUIfE:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/456bereastreet/~4/T6tXHaPHeRw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/11/styling-buttons-in-ios-webkit-and-webkit-appearancenone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Set Up A Print Style Sheet</title>
		<link>http://blogmyquery.com/index.php/2011/11/how-to-set-up-a-print-style-sheet/</link>
		<comments>http://blogmyquery.com/index.php/2011/11/how-to-set-up-a-print-style-sheet/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 15:11:41 +0000</pubDate>
		<dc:creator>Christian Krammer</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://mgmt.smashingmagazine.com/?p=119578</guid>
		<description><![CDATA[<table width="650">
  <tr>
    <td width="650">
      <div>
        <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=1" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=1" border="0" alt="" />
        </a>
        &#160;
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=2" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=2" border="0" alt="" />
        </a>
        &#160;
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=3" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=3" border="0" alt="" />
        </a>
      </div>
    </td>
  </tr>
</table><p>In a time when everyone seems to have a tablet, which makes it possible to consume everything digitally, and the only real paper we use is bathroom tissue, it might seem odd to write about the long-forgotten habit of printing a Web page. Nevertheless, as odd as it might seem to visionaries and tablet manufacturers, weâ€™re still far from the reality of a paperless world.</p>

<p><a href="http://coding.smashingmagazine.com/2011/11/24/how-to-set-up-a-print-style-sheet/"><img class="alignnone size-full wp-image-93212" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/11/print-screenshot-mainpage.png" alt="Infinitum" width="502" height="382" /></a></p>

<p>In fact, tons of paper float out of printers worldwide every day, because not everyone has a tablet yet and a computer isnâ€™t always in reach. Moreover, many of us feel that written text is just better consumed offline. Because I love to cook, sometimes I print recipes at home, or emails and screenshots at work, even though I do so as rarely as possible out of consideration for the environment.</p>]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
        <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=1" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=1" border="0" alt="" /><br />
        </a><br />
        &nbsp;<br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=2" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=2" border="0" alt="" /><br />
        </a><br />
        &nbsp;<br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=3" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=3" border="0" alt="" /><br />
        </a>
      </div>
</td>
</tr>
</table>
<p>In a time when everyone seems to have a tablet, which makes it possible to consume everything digitally, and the only real paper we use is bathroom tissue, it might seem odd to write about the long-forgotten habit of printing a Web page. Nevertheless, as odd as it might seem to visionaries and tablet manufacturers, weâ€™re still far from the reality of a paperless world.</p>
<p>In fact, tons of paper float out of printers worldwide every day, because not everyone has a tablet yet and a computer isnâ€™t always in reach. Moreover, many of us feel that written text is just better consumed offline. Because I love to cook, sometimes I print recipes at home, or emails and screenshots at work, even though I do so as rarely as possible out of consideration for the environment.</p>
<p>Print style sheets are useful and sometimes even necessary. Some readers might want to store your information locally as a well-formatted PDF to refer to the information later on, when they donâ€™t have an Internet connection. However, <a href="http://evolt.org/ResponsiveWebAndPrint">print styles are often forgotten</a> in the age of responsive Web design. The good news is that a print style sheet is actually very easy to craft: you can follow a couple of simple CSS techniques to create a good experience for readers and show them that youâ€™ve gone the extra mile to deliver just a slightly better user experience. So, how do we start?</p>
<h3>Getting Started</h3>
<p>Letâ€™s look at the process of setting up a print style sheet. The best method is to start from scratch and rely on the default style sheet of the browser, which takes care of the printed output pretty well by default. In this case, insert all declarations for printing at the end of your main style sheet, and enclose them with this distinct rule:</p>
<pre class="brush: css">
@media print {
   â€¦
}
</pre>
<p>For this to work, we have to prepare two things:</p>
<ol>
<li>Include all screen styles in the separate <code>@media screen {â€¦}</code> rule;</li>
<li>Omit the media type for the condensed style sheet: <code>&#60;link rel="stylesheet" href="css/style.css"/&#62;</code></li>
</ol>
<p>In rare cases, using screen styles for printing is the way to approach the design of the print style sheet. Although making the two outputs similar in appearance would be easier this way, the solution is not optimal because screen and print are different kettles of fish. Many elements will need to be reset or styled differently so that they look normal on a sheet of paper. But the biggest constraints are the limited page width and the need for an uncluttered, clear output. Building print styles separately from screen styles is better. This is what we will do throughout this article.</p>
<p>Of course, you could separate the declarations for screen and print into two CSS files. Just set the media type for the screen output to <code>media="screen"</code> and the media type for printing to <code>media="print"</code>, omitting it for the first one if you want to build on the screen style sheet.</p>
<p>To illustrate, I have set up a simpleÂ website of the fictional <a href="http://www.css3files.com/smashing-winery">Smashing Winery</a>.</p>
<p><a href="http://www.css3files.com/smashing-winery"><img title="The example site" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/1.jpg" alt="screenshot" width="500" /></a><br />
<em>Our example website.</em></p>
<p>Everything needed for a proper screen display is in place. But as soon as the environment changes from virtual pixels to real paper, the only thing that matters is the actual content.</p>
<p><img title="The two pages of the unaltered print preview" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/21.jpg" alt="screenshot" width="500" /><br />
<em>The two pages of the unaltered print preview. The header is not yet optimal, and both the main navigation and footer are superfluous.</em></p>
<p>Therefore, as a first task, we will hide all the clutter: namely, the main navigation and footer.</p>
<pre class="brush: css">
header nav, footer {
display: none;
}
</pre>
<p>Depending on the type of website, you could also consider hiding images by default. If the images are big, this would be wise, to save your users some printing costs. But if the images mainly support the content, and removing them would compromise the meaning, just leave them in. Whatever you decide, limit the images to a certain width, so that they donâ€™t bleed off the paper. Iâ€™ve found that 500 pixels is a good compromise.</p>
<pre class="brush: css">
img {
max-width: 500px;
}
</pre>
<p>Alternatively you could also rely on the tried and trusted <code>max-width: 100%</code>, which displays images at their maximum size but not bigger than the page width.</p>
<p>You might want to use a simple trick to get high-quality images when printing. Just provide a higher-resolution version of every image needed and resize it to the original size with CSS. Read more about this technique in the article â€œ<a href="http://www.alistapart.com/articles/hiresprinting/">High-Resolution Image Printing</a>â€� on A List Apart.</p>
<p>Of course, we should hide video and other interactive elements, because they are useless on paper. These include <code>&#60;video&#62;</code>, <code>&#60;audio&#62;</code>, <code>&#60;object&#62;</code> and <code>&#60;embed&#62;</code> elements. You might want to consider replacing each video element with an image in the print style sheet, too.</p>
<p><img title="The main navigation, the footer and images removed." src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/print_stylesheet_33.jpg" alt="screenshot" width="500" /><br />
<em>With the main navigation, footer and images gone, the actual text is getting ever closer to center stage. But work remains to be done, especially with the header.</em></p>
<h3>Adjusting To The Right Size</h3>
<p>To define page margins, you can use <code>@page</code> rule  to simply apply a margin all the way around the page. E.g.:</p>
<pre class="brush: css">
@page {
margin: 0.5cm;
}
</pre>
<p>will set the page margin on all sides to 0.5cm. You can also adjust the margins for every other page. The following code sets the left page (1, 3, 5, etc.) and right page (2, 4, 6, etc.) margins independently.</p>
<pre class="brush: css">
@page :left {
margin: 0.5cm;
}

@page :right {
margin: 0.8cm;
}
</pre>
<p>You can also use the <code>:first</code> page pseudo-class that describes the styling of the first page when printing a document:</p>
<pre class="brush: css">
@page :first {
  margin: 1cm 2cm;
}
</pre>
<p>Unfortunately, <code>@page</code> is not supported in Firefox, but supported in Chrome 2.0+, IE 8.0+, Opera 6.0+ and Safari 5.0+. <code>@page :first</code> is supported only in IE8+ and Opera 9.2+. (<em>thanks for the tip, <a href="http://designshack.net/articles/css/6-thinks-i-learned-about-print-stylesheets-from-html5-boilerplate/">Designshack</a></em>)</p>
<p>Now letâ€™s tweak some general settings for the fonts. Most browsers set the default to Times New Roman, because serif fonts are considered to be easier on the eyes when read on paper. We can use Georgia at 12-point font size and a slightly higher line height for better legibility.</p>
<pre class="brush: css">
body {
font: 12pt Georgia, "Times New Roman", Times, serif;
line-height: 1.3;
}
</pre>
<p>However, to retain some control, we should explicitly set the font sizes below. The <a href="http://reeddesign.co.uk/test/points-pixels.html">chart on ReedDesign</a> gives us a feel for this; but with all of the screen sizes and resolutions out there, these are only rough estimates.</p>
<pre class="brush: css">
h1 {
font-size: 24pt;
}

h2 {
font-size: 14pt;
margin-top: 25px;
}

aside h2 {
font-size: 18pt;
}
</pre>
<p>Apart from special cases (like the <code>&#60;h2&#62;</code> heading, which would otherwise be too close to the preceding paragraph), we donâ€™t need to touch the margins or appearance of any elements, because they are handled quite nicely by the default settings. If you donâ€™t like that certain elements are indented, such as <code>&#60;blockquote&#62;</code>, <code>&#60;ul&#62;</code> and <code>&#60;figure&#62;</code>, you could always reset their margins:</p>
<pre class="brush: css">
blockquote, ul {
margin: 0;
}
</pre>
<p>Or you could override the default bullet style in unordered listsâ€¦</p>
<pre class="brush: css">
ul {list-style: none}
</pre>
<p>â€¦and replace it with a custom one; for example, a double arrow (and a blank space to give it some room):</p>
<pre class="brush: css">
li {
content: "Â» ";
}
</pre>
<p>You could also make <code>&#60;blockquote&#62;</code> stand out a bit by enlarging it and italicizing the text.</p>
<h3>The Header</h3>
<p>Currently, the remaining things to be dealt with in the header are the <code>&#60;h1&#62;</code> title and the logo. The first is there just for <a href="http://www.456bereastreet.com/archive/201104/html5_document_outline_revisited/">accessibility</a> purposes and is hidden for screen display using CSS. While we could use it as a sort of header in the print-out to indicate the source of the content, letâ€™s try something more attractive. Wouldnâ€™t it be nice to display the actual logo, instead of the boring text?</p>
<p>Unfortunately, the â€œWineryâ€� part of the logo is white and therefore not ideal for printing on light-colored paper. Thatâ€™s why two versions of the logo are in the source code, one for screen display, one for printing. The latter image has no <code>alt</code> text, otherwise screen readers would repeat reading out â€œSmashing Winery.â€�</p>
<pre class="brush: xml">&#60;a href="/" title="Home" class="logo"&#62;
   &#60;img src="img/logo.png" alt="Smashing Winery" class="screen"/&#62;
   &#60;img src="img/logo_print.png" alt="" class="print"/&#62;
&#60;/a&#62;
</pre>
<p>First, we need to hide the screen logo and the <code>&#60;h1&#62;</code> heading. Depending on the relevance of the images, we might have already decided to hide them along with other unneeded elements:</p>
<pre class="brush: css">
header h1, header nav, footer, img {
display: none;
}
</pre>
<p>In this case, we have to bring back the print logo. Of course, you could use the adjacent sibling selector for the job (<code>header img + img</code>) to save the class name and live with it not working in Internet Explorer 6.</p>
<pre class="brush: css">
header .print {
display: block;
}
</pre>
<p>Otherwise, you could just use <code>header .screen</code> (or <code>header :first-child</code>) to hide the main logo. And then the second logo would remain. Keep in mind that in print layouts, only images embedded via the <code>&#60;img&#62;</code> tag are displayed. Background images are not.</p>
<p>VoilÃ ! Now we have a nice header for our print-out that clearly shows the source of everything. Alternatively, you could still remove the second logo from the source code and use the headerâ€™s <code>&#60;h1&#62;</code> heading that we switched off earlier (in other words, remove it from the <code>display: none</code> line). Perhaps youâ€™ll need to hide the remaining logo as we did before. Additionally, the font size could be enlarged so that it is clearly recognized as the title of the website.</p>
<pre class="brush: css">
header h1 {
font-size: 30pt;
}
</pre>
<p>As a little extra, the header in the print-out could show the URL of the website. This is done by applying the <code>:after</code> pseudo-element to the <code>&#60;header&#62;</code> tag, which unfortunately wonâ€™t work in IE prior to version 8; but because this is just a little bonus, we can live with IEâ€™s shortcoming.</p>
<pre class="brush: css">
header:after {
content: "www.smashing-winery.com";
}
</pre>
<p>To see what else these pseudo-elements can do, read the <a href="https://developer.mozilla.org/en/CSS/Pseudo-elements">description on the Mozilla Developer Network</a>, or consult Chris Coyerâ€™s <a href="http://css-tricks.com/9516-pseudo-element-roundup">excellent article on CSS-Tricks</a>.</p>
<p>Another thing about IE 6 to 8 is that HTML5 tags canâ€™t be printed. Because weâ€™re using these tags on the example website, weâ€™ll have to apply Remy Sharpâ€™s <a href="http://code.google.com/p/html5shiv/">HTML5shiv</a> in the header. The shiv allows you not only to style HTML5 tags but to print them as well. If youâ€™re already using <a href="http://modernizr.com">Modernizr</a>, thatâ€™s perfect, because the shiv is included in it.</p>
<pre class="brush: xml">
&#60;script src="js/html5.js"&#62;&#60;/script&#62;
</pre>
<p>Unfortunately, the behavior of the IEs is still a bit buggy even when this shiv is applied. HTML5 tags that were styled for the screen layout need to be reset, or else the styling will be adopted for the print-out.</p>
<p>Some developers add a short message as a supplement (or an alternative) to the displayed URL, reminding users where they were when they printed the page and to check back for fresh content. We can do this with the <code>:before</code> pseudo-element, so that it appears before the logo. Again, this wonâ€™t work in IE 6 or 7.</p>
<pre class="brush: css">
header:before {
display: block;
content: "Thank you for printing our content at www.smashing-winery.com. Please check back soon for new offers on delicious wine from our winery.";
margin-bottom: 10px;
border: 1px solid #bbb;
padding: 3px 5px;
font-style: italic;
}
</pre>
<p>To distinguish it from the actual content, weâ€™ve given it a gray border, a bit of padding and italics. Lastly, Iâ€™ve made it a block element, so that the border goes all around it, and given the logo a margin.</p>
<p>To make it more discreet, we could move this message to the bottom of the page and append it to main container of the page, which has the <code>.content</code> class. If so, we would use the <code>:after</code> element and a top margin to keep it distinct from the sidebarâ€™s content. As far as Iâ€™m concerned, the URL is indication enough, so I would rely on that and omit the message.</p>
<p>Finally, we need to remove the border of the logo to prevent it from showing in legacy browsers, and move the <code>&#60;header&#62;</code> away from the content:</p>
<pre class="brush: css">
img {
border: 0;
}

header {
margin-bottom: 40px;
}
</pre>
<p><img title="Print Output" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/print_stylesheet_52.jpg" alt="screenshot" width="500" /><br />
<em>The header shown two different ways, one with a logo and simple URL, and the other with a message and the title in plain text.</em></p>
<h3>The Missing Link</h3>
<p>Obviously, on paper, links arenâ€™t clickable and so are pretty useless. You could try to build a workaround, replacing links with QR codes on the fly, but the solution may not be feasible. To put the links to use, you could display the URL after each string of anchor text. But text littered with URLs can be distracting and can impair the reading experience; and sparing the reader excessive information where possible is advisable.</p>
<p>The best solution is the <code>:after</code> pseudo-element. It displays the URL after each anchor text, surrounded by brackets. And the font size is reduced to make it less intrusive.</p>
<pre class="brush: css">
p a:after {
content: " (" attr(href) ")";
font-size: 80%;
}
</pre>
<p>Weâ€™ve limited this technique to links within <code>&#60;p&#62;</code> elements as a precaution. To go a step further, we could choose to show only the URLs of external links. An <a href="https://developer.mozilla.org/en/CSS/Attribute_selectors">attribute selector</a> is perfect for this:</p>
<pre class="brush: css">
p a[href^="http://"]:after {
content: " (" attr(href) ")";
font-size: 90%;
}
</pre>
<p>The possibilities for links in printed documents seem to be almost endless, so letâ€™s try some more. To distinguish all internal links, letâ€™s precede them with the websiteâ€™s domain (omitting all the other properties, to keep things concise and clear):</p>
<pre class="brush: css">
p a:after {
content: " (http://www.smashing-winery.com/" attr(href) ")";
}
</pre>
<p>Then, we can hide internal links (<code>#</code>), because there is not much to display:</p>
<pre class="brush: css">
p a[href^="#"]:after {
display: none;
}
</pre>
<p>Also, external links will be appended as is, like above. Letâ€™s consider SSL-secured websites, too (i.e. ones that begin with <code>https://</code>):</p>
<pre class="brush: css">
p a[href^="http://"]:after, a[href^="https://"]:after {
content: " (" attr(href) ")";
}
</pre>
<p>But there is one thing to remember, especially with external links. Some are very long, such as the ones in the <a href="http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html#//apple_ref/doc/uid/TP30001266--webkit-border-radius">Safari Developer Library</a>. Such links can easily break a layout, like at the screen output. Luckily, a special property takes care of this:</p>
<pre class="brush: css">
p a {
word-wrap: break-word;
}
</pre>
<p>This breaks long URLs when they reach a certain limit or, as in our case, when they exceed the pageâ€™s width. Just add this property to the first of the above declarations. Although this property is basically supported in a wide range of browsers &#8212; even IE 6 &#8212; it works only in Chrome when printing. While Firefox automatically breaks long URLs, Internet Explorer has no capability for this.</p>
<p>Finally, we set the link color to black to improve the experience for readers.</p>
<pre class="brush: css">
a {
color: #000;
}
</pre>
<p><img title="Print Output" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/6.jpg" alt="screenshot" width="500" /><br />
<em>URLs, whether internal or external, now show up beside links with special treatment.</em></p>
<p>Aaron Gustafson went one step further and built the little script <a href="http://www.v2.easy-designs.net/code/footnoteLinks/index.php">Footnote Links</a>. According to the description:</p>
<blockquote>
<p>This script builds a list of URIs from any tags within a specified container and appends the list as footnotes to the document in a specified location. Any referenced elements are given a dynamically-assigned number which corresponds to the link in the footnote list.</p>
</blockquote>
<p>Aaronâ€™s article on A List Apart â€œ<a href="http://www.alistapart.com/articles/improvingprint/">Improving Link Display for Print</a>â€� gives more insight into the idea behind this script.</p>
<p>While weâ€™re at it, letting readers know where quotes come from, such as those wrapped in <code>&#60;blockquote&#62;</code> and <code>&#60;q&#62;</code> tags, would be thoughtful. Just append the <code>cite</code> attribute (which will be the URL) after quotation marks, like so:</p>
<pre class="brush: css">
q:after {
content: " (Source: " attr(cite) ")";
}
</pre>
<h3>Side By Side</h3>
<p>We havenâ€™t yet dealt with the sidebar content. Even though it appears after the main content by default, letâ€™s give it some special treatment. To keep it distinct, weâ€™ll give the sidebar a gray top border and a safe buffer of 30 pixels. The last property, <code>display: block</code>, ensures that the border shows up properly.</p>
<pre class="brush: css">
aside {
border-top: 1px solid #bbb;
margin-top: 30px;
display: block;
}
</pre>
<p>To separate it even more, we could set a special print property:</p>
<pre class="brush: css">
page-break-before: always;
</pre>
<p>This will move the contents of the sidebar to a new page when printed. If we do this, we can omit all of the other properties.</p>
<p><img title="The sidebar how it looks at the screen and the print out" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/7.jpg" alt="screenshot" width="500" /><br />
<em>The sidebar on screen (left) and printed out (right). Iâ€™ve grayed out everything else to make it more obvious here.</em></p>
<p>We could do the same for comments. Comments donâ€™t appear in the example, but theyâ€™re still worth touching on. Because they sometimes run long, omitting them in the print-out might be reasonable (just set <code>display: none</code> for the whole container). If you do want to show the comments, at least set <code>page-break-before</code>. You can also use <code>page-break-after: always</code> if there is content to print on a new page. The <code>page-break-before</code> and <code>page-break-after</code> properties are supported in all major browsers.</p>
<p>We can also use <code>widows</code> and <code>orphans</code> properties. The terms derive from traditional printing, and they take numbers as values. The <code>widows</code> property sets the minimum number of lines in a paragraph to leave at the top of a page before moving them entirely to a new page. The <code>orphans</code> property sets the number of lines for the bottom of the page. The <code>orphans</code> and <code>widows</code> properties are supported in IE 8+ and Opera 9.2+, but unfortunately not in Firefox, Safari or Chrome.</p>
<p>Now that we have taken care of the sidebar, the print style sheet is ready! You can <a href="http://www.css3files.com/smashing-winery/css/print.css">download it here</a>. The file is fully documented and so can serve as a helpful reference or starting point.</p>
<p><img class="alignnone size-full wp-image-106667" title="The finished print style sheet" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/8.jpg" alt="screenshot" width="550" height="380" /><br />
<em>The completed print style sheet.</em></p>
<h3>Just For Fun</h3>
<p>You might be asking, â€œWhy canâ€™t we just put the sidebar next to the main content, like on the website itself?â€� Well, the screen and print outputs are a bit different. Unlike the former, print-outs arenâ€™t very wide and thus donâ€™t have much space to fill. But depending on the font size, the line length could exceed the maximum of 75 characters and so be <a href="http://baymard.com/blog/line-length-readability">more difficult to read</a>.</p>
<p>In this case, we could, of course, limit the width of the main content (preferably not too much &#8212; we shouldnâ€™t set the line length to fall below about 55 characters) and then absolutely position the sidebar just below it, just like in the screen display. But describing this method falls beyond the scope of this article, so please consult the <a href="http://css3files.com/smashing-winery/css/style.css">screen style sheet</a> of the example website (line numbers 112 and 141 and down).</p>
<p>In my humble opinion, avoid such experiments. While in principle, print layouts have endless possibilities, focusing on the content and removing everything else is better. The better way to ensure an optimal line length is just to shrink the pageâ€™s width or enlarge the font size.</p>
<h4>Preview Made Easy</h4>
<p><a href="https://github.com/etimbo/jquery-print-preview-plugin">Print Preview</a> by Tim Connell is a handy little jQuery plugin that replicates the built-in print-preview function, but with one difference. Instead of opening a separate page, it shows a sleek overlay, with â€œCloseâ€� and â€œPrintâ€� buttons at the top. It also has the convenient â€œPâ€� shortcut. You might want to check out the <a href="http://etimbo.github.com/jquery-print-preview-plugin/example/index.html">demo page</a>, too.</p>
<h3>A Missed Opportunity</h3>
<p>Imagine that you were able to visit any page, hit â€œPrintâ€� and get an optimized version of the page to enjoy on paper. Unfortunately, we donâ€™t live in this perfect world. Some websites still rely on JavaScript to generate print versions, and many other designers simply donâ€™t care. But this is a missed opportunity. A carefully composed print style sheet could be used not only for printing but to optimize legibility for screen reading.</p>
<p>As the website owner, you can determine the images to display (if any), the optimal font and size, and the presentation of other elements. You could make the content more appealing than the versions produced by Instapaper and Readability by giving the print version the extra attention it deserves.</p>
<h4>The Future</h4>
<p>While using CSS3 for screen layouts is pretty common nowadays, it hasnâ€™t quite established itself in the print environment yet. The W3C has an extensive description of â€œ<a href="http://www.w3.org/TR/css3-page/">Paged Media</a>,â€� but unfortunately support is very limited at the moment, Opera and Chrome being the only browsers that enable a few of its related properties. With decent support, it would be possible to use the <code>@page</code> rule to set the dimensions of the page, switch to a landscape view, alter the margins, and do much more. Even <a href="http://www.w3.org/TR/css3-page/#page-size-media-query">media queries</a> are were conceived to respond to different page sizes.</p>
<h3>Websites Designed Well For Print</h3>
<p>Let&#8217;s take a look at some examples of websites optimized for print.</p>
<p><a href="http://alistapart.com/">A List Apart</a><br />
The slick multi-column design is simplified into a single column, full width, which intuitively mirrors the websiteâ€™s sensible hierarchy. Article titles and authors are no longer active links. And beautiful clean typography is kept intact, thanks to the compatible fonts and simple colors;Â no font change is necessary, although the font-size value increases slightly. Advertising and affiliate styles are hidden, and the result is a simple, clean printed page that easily conforms well to any printer or page set-up in the document. A List Apart is exemplary, save for one important point: the logo does not appear anywhere in the print-out.</p>
<p><a href="http://www.alistapart.com/articles/a-checklist-for-content-work/"><img class="alignnone size-full wp-image-93162" title="A List Apart" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/a-list-apart-screenshot.jpg" alt="A List Apart" width="500" height="282" /></a></p>
<p><a href="http://www.alistapart.com/articles/a-checklist-for-content-work/"><img class="alignnone size-full wp-image-93163" title="A List Apart" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/a-list-apart-printview.jpg" alt="A List Apart" width="500" height="278" /></a></p>
<p><a href="http://lostworldsfairs.com/">Lost Worldâ€™s Fairs</a><br />
The smooth printed page helps to carry the visuals of the website for Lost Worldâ€™s Fairs. The main title and its colorful background are swapped for a simplified version in the print-preview style. However, some images could be removed to save some expensive printer ink. (<em>Updated</em>).</p>
<p><a href="http://lostworldsfairs.com/"><img class="alignnone size-full wp-image-93208" title="Lost World's Fairs" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/lost-worlds-fairs.jpg" alt="Lost World's Fairs" width="500" height="350" /></a></p>
<p><a href="http://lostworldsfairs.com/"><img class="alignnone size-full wp-image-93209" title="Lost World's Fairs" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/lost-worlds-fairs-print.jpg" alt="Lost World's Fairs" width="500" height="381" /></a></p>
<p><a href="http://www.themorningnews.org/">The Morning News</a><br />
One would expect most news websites to employ the print-preview function, yet that isnâ€™t the case. The Morning News has prepared its content for print without much concern, happily excluding background images and color, while still getting its message across.</p>
<p><a href="http://www.themorningnews.org/"><img class="alignnone size-full wp-image-93210" title="The Morning News" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/the-morning-news.jpg" alt="The Morning News" width="500" height="313" /></a></p>
<p><a href="http://www.themorningnews.org/"><img class="alignnone size-full wp-image-93210" title="The Morning News" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/morning-news-print.jpg" alt="The Morning News" width="500" height="275" /></a></p>
<p><a href="http://www.jamesmli.net/">James Li</a><br />
James Li has designed his personal website exceptionally well for this purpose, carefully preserving all spacing and key elements. The logo is a part of the printed product, whereas the navigation links are not: very clever, because navigation has no value on a printed page unless it is informative in and of itself. Non-Web fonts are converted to simple printable ones (see â€œOther Stuffâ€¦â€�). Brilliantly executed for print.</p>
<p><a href="http://www.jamesmli.net/"><img class="alignnone size-full wp-image-93212" title="Infinitum" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/infinitum-screenshot.jpg" alt="Infinitum" width="500" height="384" /></a></p>
<p><a href="http://www.jamesmli.net/"><img class="alignnone size-full wp-image-93213" title="Infinitum" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/infinitum-print.jpg" alt="Infinitum" width="500" height="409" /></a></p>
<p><a href="http://www.techcrunch.com">TechCrunch</a><br />
TechCrunch&#8217;s recent redesign tweaked not only the visual design of the site, but also the small details that have to be considered when the site is viewed on mobile or printed out. The print layout is very clean and minimalistic, without unnecessary details, yet also without links to the actual page that was printed out. The TechCrunch logo is omitted as well.</p>
<p><a href="http://www.techcrunch.com/"><img class="alignnone size-full wp-image-93212" title="TechCrunch" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/t-crunch-main.jpg" alt="TechCrunch" width="500" height="278" /></a></p>
<p><a href="http://www.techcrunch.com/"><img class="alignnone size-full wp-image-93212" title="TechCrunch" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/t-crunch-print.jpg" alt="TechCrunch" width="500" height="349" /></a></p>
<p><a href="http://www.rga.com/">R/GA</a><br />
Although the logo isnâ€™t present in the printed version of this website, attention is paid to the spacing of the content within. While the Web version has simple lines and a clean space, the printed page tightens up elements in order to best use the space. A strong grid and effective typography add to the effect. In this example, some images could be removed as well.</p>
<p><a href="http://www.rga.com/"><img class="alignnone size-full wp-image-93214" title="r/ga" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/r-g-a-fwd-main.jpg" alt="r/ga" width="500" height="257" /></a></p>
<p><a href="http://www.rga.com/"><img class="alignnone size-full wp-image-93214" title="r/ga" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/r-g-a-fwd-print.jpg" alt="r/ga" width="500" height="464" /></a></p>
<p><a href="http://www.studiomister.com/index.php">Studio Mister</a><br />
An excellent job of the print-preview function. The page has been meticulously designed to a grid and requires little in order to prepare it for print;Â some attention to the background color of text and not much else. Unfortunately, though, the logo is a background image and thus excluded.</p>
<p><a href="http://www.studiomister.com/index.php"><img class="alignnone size-full wp-image-93216" title="Studio Mister" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/studio-mister-mainpage.jpg" alt="Studio Mister" width="500" height="292" /></a></p>
<p><a href="http://www.studiomister.com/index.php"><img class="alignnone size-full wp-image-93217" title="Studio Mister" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/studio-mister-print.jpg" alt="Studio Mister" width="500" height="343" /></a></p>
<p><a href="http://www.bottlerocketcreative.com/">Bottlerocket Creative</a><br />
Although this logo isnâ€™t represented in the print-out either, the folks at Bottlerocket Creative have done very well to adapt their typographic style for offline viewing. Assuming the design was created mainly with images would be easy, but meticulous attention to type is evident upon closer inspection.</p>
<p><a href="http://www.bottlerocketcreative.com/"><img class="alignnone size-full wp-image-93218" title="Bottle Rocket" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/bottlerocket-main.jpg" alt="Bottle Rocket" width="500" height="370" /></a></p>
<p><a href="http://www.bottlerocketcreative.com/"><img class="alignnone size-full wp-image-93219" title="Bottle Rocket" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/bottlerocket-printview.jpg" alt="Bottle Rocket" width="500" height="283" /></a></p>
<p><a href="http://omniti.com">OmniTI</a><br />
OmniTI has optimized its content for print not by shrinking the main column, but by increasing the size of the text and not crowding the images together. The playful look adheres to good spacing. The only drawback? Many of the line breaks have been eliminated, causing some words and sentences to run into each other.</p>
<p><a href="http://omniti.com/"><img class="alignnone size-full wp-image-93225" title="Omni TI" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/omniti-main.jpg" alt="Omni TI" width="500" height="300" /></a></p>
<p><a href="http://omniti.com/"><img class="alignnone size-full wp-image-93226" title="Omni TI" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/omniti-print.jpg" alt="Omni TI" width="500" height="414" /></a></p>
<h4>In Conclusion</h4>
<p>Thereâ€™s a lot to consider when preparing your website to be printed out by readers. The process forces you to scrutinize every element of your content like never before, all because someone will want a hard copy of your work. Yet most of all, itâ€™s important to recognize the difference between printing and actually reading. Perhaps these techniques hold merit in helping you visualize content for mobile devices. What better way to kill two birds with one stone than to work out your layout for the mobile while considering printing view at the same time to make sure that your content prints flawlessly for offline archival? The time you invest could double in value.</p>
<p>For more information on preparing content for print, including by modifying CSS, check out the following articles:</p>
<ul>
<li>â€œ<a href="http://www.webcredible.co.uk/user-friendly-resources/css/print-stylesheet.shtml">Print Style Sheet: The Definitive Guide</a>,â€� Trenton Moss, Webcredible</li>
<li><a href="http://designshack.net/articles/css/6-thinks-i-learned-about-print-stylesheets-from-html5-boilerplate/">&#8220;6 Things I Learned About Print Stylesheets From HTML5 Boilerplate</a>,&#8221; Joshua Johnson, DesignShack</li>
<li>â€œ<a href="http://www.alistapart.com/articles/goingtoprint/">CSS Design: Going to Print</a>,â€� Eric Meyer, A List Apart</li>
<li>â€œ<a href="http://css-tricks.com/css-tricks-finally-gets-a-print-stylesheet/">CSS-Tricks Finally Gets a Print Style Sheet</a>,â€� Chris Coyier, CSS-Tricks</li>
<li>â€œ<a href="http://www.w3.org/TR/css-print/">CSS Print Profile</a>,â€� W3C</li>
<li>â€œ<a href="http://www.w3.org/TR/css3-mediaqueries/">Media Queries</a>,â€� W3C</li>
</ul>
<p><em>(al) (vf) (il)</em></p>
<hr />
<p><small>Â© Christian Krammer for <a href="http://www.smashingmagazine.com">Smashing Magazine</a>, 2011.</small></p>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/11/how-to-set-up-a-print-style-sheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Screen readers and CSS</title>
		<link>http://blogmyquery.com/index.php/2011/11/screen-readers-and-css/</link>
		<comments>http://blogmyquery.com/index.php/2011/11/screen-readers-and-css/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 19:03:10 +0000</pubDate>
		<dc:creator>Roger Johansson</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://www.456bereastreet.com/archive/201111/screen_readers_and_css/</guid>
		<description><![CDATA[As I have noted in a couple of blog posts recently, there are some cases when CSS has quite unexpected results in screen readers (or the way web browsers create the accessibility information they hand over to screen readers). If you havenâ€™t read...]]></description>
			<content:encoded><![CDATA[<p class="preamble">As I have noted in a couple of blog posts recently, there are some cases when CSS has quite unexpected results in screen readers (or the way web browsers create the accessibility information they hand over to screen readers). If you havenâ€™t read them, the posts are <a href="http://www.456bereastreet.com/archive/201109/screen_readers_list_items_and_list-stylenone/">Screen readers, list items and list-style:none</a> and <a href="http://www.456bereastreet.com/archive/201110/using_displaytable_has_semantic_effects_in_some_screen_readers/">Using display:table has semantic effects in some screen readers</a>.</p>

<p>Here are a few examples:</p>

<ul>
	<li>Using <code>display:table</code> on non-table elements to get the visual layout characteristics of an HTML table without actually using one may cause screen readers to act as if there was a real table</li>
	<li>Using <code>display:block</code> or float on table-related elements may cause screen readers to treat the table as a layout table and ignore its semantics or report an incorrect data structure</li>
	<li>Using <code>list-style:none</code> to visually remove bullets or numbers from list items may cause screen readers to ignore them too, basically treating list items as paragraphs of text</li>
</ul><p><a href="http://www.456bereastreet.com/archive/201111/screen_readers_and_css/">Read full post</a></p><p>Posted in <a href="http://www.456bereastreet.com/archive/categories/accessibility/" rel="tag">Accessibility</a>, <a href="http://www.456bereastreet.com/archive/categories/css/" rel="tag">CSS</a>.</p><p>Copyright Â© <a href="http://www.456bereastreet.com/">Roger Johansson</a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/5Dl111r42wJ6X9oxDp0ogavUl4U/0/da"><img src="http://feedads.g.doubleclick.net/~a/5Dl111r42wJ6X9oxDp0ogavUl4U/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/5Dl111r42wJ6X9oxDp0ogavUl4U/1/da"><img src="http://feedads.g.doubleclick.net/~a/5Dl111r42wJ6X9oxDp0ogavUl4U/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/456bereastreet?a=5_yWBRvL5HY:rReC76oBm3s:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=5_yWBRvL5HY:rReC76oBm3s:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=bcOpcFrp8Mo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=5_yWBRvL5HY:rReC76oBm3s:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=5_yWBRvL5HY:rReC76oBm3s:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=5_yWBRvL5HY:rReC76oBm3s:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=5_yWBRvL5HY:rReC76oBm3s:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/456bereastreet/~4/5_yWBRvL5HY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/11/screen-readers-and-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An accessible, keyboard friendly custom select menu</title>
		<link>http://blogmyquery.com/index.php/2011/11/an-accessible-keyboard-friendly-custom-select-menu/</link>
		<comments>http://blogmyquery.com/index.php/2011/11/an-accessible-keyboard-friendly-custom-select-menu/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 19:04:17 +0000</pubDate>
		<dc:creator>Roger Johansson</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://www.456bereastreet.com/archive/201111/an_accessible_keyboard_friendly_custom_select_menu/</guid>
		<description><![CDATA[Iâ€™ve always been wary of styling form elements too much. Possible usability and accessibility issues, browser quirks, and the fact that the CSS specification does not define form control styling are the main reasons.

With that said, sometimes y...]]></description>
			<content:encoded><![CDATA[<p class="preamble">Iâ€™ve always been wary of styling form elements too much. Possible usability and accessibility issues, browser quirks, and the fact that <a href="http://www.w3.org/TR/CSS21/conform.html#conformance">the CSS specification does not define form control styling</a> are the main reasons.</p>

<p>With that said, sometimes you have to do things you donâ€™t really want to. Like styling <code>select</code> elements, which Iâ€™ve recently had to find a way to do. There are quite a few workarounds for doing this out there. However, most of the ones I looked at replace the <code>select</code> element with a bunch of links which changes semantics and behaviour a bit too much for my tastes. I couldnâ€™t find any implementation that I was completely happy with, so I took the best one I could find and tweaked it.</p><p><a href="http://www.456bereastreet.com/archive/201111/an_accessible_keyboard_friendly_custom_select_menu/">Read full post</a></p><p>Posted in <a href="http://www.456bereastreet.com/archive/categories/accessibility/" rel="tag">Accessibility</a>, <a href="http://www.456bereastreet.com/archive/categories/css/" rel="tag">CSS</a>, <a href="http://www.456bereastreet.com/archive/categories/javascript/" rel="tag">JavaScript</a>.</p><p>Copyright Â© <a href="http://www.456bereastreet.com/">Roger Johansson</a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/c741rU3z65u_Snswk2AN66XhOWE/0/da"><img src="http://feedads.g.doubleclick.net/~a/c741rU3z65u_Snswk2AN66XhOWE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/c741rU3z65u_Snswk2AN66XhOWE/1/da"><img src="http://feedads.g.doubleclick.net/~a/c741rU3z65u_Snswk2AN66XhOWE/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/456bereastreet?a=CxJ24wNeuqQ:9dxLbAJowZw:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=CxJ24wNeuqQ:9dxLbAJowZw:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=bcOpcFrp8Mo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=CxJ24wNeuqQ:9dxLbAJowZw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=CxJ24wNeuqQ:9dxLbAJowZw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=CxJ24wNeuqQ:9dxLbAJowZw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=CxJ24wNeuqQ:9dxLbAJowZw:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/456bereastreet/~4/CxJ24wNeuqQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/11/an-accessible-keyboard-friendly-custom-select-menu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

