<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>CSSnewbie</title>
	
	<link>http://www.cssnewbie.com</link>
	<description>CSS Tutorials, Tips &amp; Techniques for the uninitiated.</description>
	<pubDate>Mon, 01 Dec 2008 15:57:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/cssnewbie" type="application/rss+xml" /><feedburner:emailServiceId>1376060</feedburner:emailServiceId><feedburner:feedburnerHostname>http://www.feedburner.com</feedburner:feedburnerHostname><item>
		<title>CSS Newbie Gets a Facelift</title>
		<link>http://feeds.feedburner.com/~r/cssnewbie/~3/471418165/</link>
		<comments>http://www.cssnewbie.com/css-newbie-gets-a-facelift/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 15:48:42 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Site News]]></category>

		<category><![CDATA[cssnewbie]]></category>

		<category><![CDATA[design]]></category>

		<category><![CDATA[facelift]]></category>

		<category><![CDATA[redesign]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=268</guid>
		<description><![CDATA[Welcome to the new and improved CSS Newbie! This new version of the site has been a long time in the making, so I’m very excited to finally have it ready for its grand unveiling. There are a few changes to the site that I’d like to point out.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.cssnewbie.com/wp-content/uploads/2008/11/cssnewbie-facelift.jpg" alt="" title="CSS Newbie Facelift" width="579" height="200" class="alignnone size-full wp-image-269" /></p>
<p>Welcome to the new and improved CSS Newbie! This new version of the site has been a long time in the making, so I’m very excited to finally have it ready for its grand unveiling. And to make things extra auspicious, today is also the eight month anniversary of <a href="http://www.cssnewbie.com/book-style-chapter-intros/">the site&#8217;s official launch on February 1, 2008.</a></p>
<p>Before I go any further, I’d like to thank <a href="http://www.crawlspacemedia.com/">Jeremy Harrington of crawlspace|media</a> for designing the page you see before you (or, if you’re reading this in your RSS feed, you should really <a href="http://www.cssnewbie.com/">click through to the site proper</a>). Jeremy was extremely patient with my incessant tweaking, and I think the result is a very beautiful and functional site.</p>
<p>Now, the main focus of CSS Newbie hasn’t changed. I’m still going to strive to produce quality articles on all matter of web development, with a focus on CSS in particular, but also including XHTML, JavaScript, and related frameworks, templates, and technologies. After all, CSS by itself isn’t much use without those other disciplines. </p>
<p>That having been said, there are a few changes to the site that I’d like to take some time to point out. Hopefully, you’ll find them all beneficial (or at least not overly annoying).<br />
<span id="more-268"></span></p>
<h3>A Home Worth Coming Home To</h3>
<p>The homepage of the new and improved CSS Newbie has a lot more information than it did previously. Before now, the homepage has always just featured the most recent article in its entirety. However, that sort of a layout assumes you either visit the site often enough to catch every single article I publish, or have some sort of a burning desire to go digging through the archives to see if you’ve missed anything recently.</p>
<p>No more!</p>
<p>The new homepage features a total of five recent articles instead of just one. However, to keep the page compact, I’ve shortened the amount of each article shown. The most recent article will generally get several paragraphs on the front page, with easy access to the rest of the article either by clicking on the title or the “read more” link below the content. The other four articles will feature descriptive excerpts, helping you decide which articles are most worth your time.</p>
<h3>Find What You’re Looking For</h3>
<p>Of course, there’s always the possibility that you really are one of those people that enjoys digging through website archives to see what you can find. To that end, I’ve built a CSS Newbie <a href="http://www.cssnewbie.com/toc/">Table of Contents.</a> Every article I’ve ever written is available, organized by category. If the article is listed under more than one category, it’ll be listed more than once for increased findability. So go ahead – see what CSS Newbie has to offer!</p>
<p>I’ve also added a search bar to the site’s sidebar – a search bar was a major oversight of mine in the last design. So if you have an idea of what sort of information you’re looking for, but can’t find it by article title in the table of contents, give the search bar a whirl – you might get lucky.</p>
<h3>Enhancing the Conversation</h3>
<p>I’ve always enjoyed getting comments on the articles I’ve written – the feedback is almost always beneficial in some way. And comments are still around, with the added benefit of <a href="http://en.gravatar.com/">gravatars</a> (Globally Recognized Avatars). If you have a gravatar associated with your email address, your photo will now appear next to your comment, making the whole process a lot more personable.</p>
<p>I’ve also added mini-surveys (i.e., polls) to the website. Every once in a while, I’ll post a new survey to the site. It’s a chance for you to offer feedback on a wide variety of questions. The most recent survey will always be featured in the footer of the website, and I’ll try to remember to announce when I’ve released a new survey. Right now, you can offer feedback on what you think of the new design. Be sure to check it out and let me know!</p>
<p>And if I’ve written an article that you’ve really found helpful, please consider submitting it to the social media site of your choice. To make that easier, I’ve added a ShareThis toolbar to the top of every article in the site. Save your favorite articles to Delicious, Ma.gnolia, or dozens of other social networks with the click of a single button.</p>
<p>And speaking of social networks, if you’d like to take the conversation off CSS Newbie entirely, be sure to <a href="http://www.twitter.com/robbyg/">follow me on twitter.</a> I’ll warn you – I talk about things other than web development. But twitter is a great way to get to better know the person on the other side of the screen. I’d really like to get to know you-all better, so if you feel the same, <a href="http://www.twitter.com/robbyg/">send a follow my way.</a></p>
<h3>Community News</h3>
<p>Many sites these days have a community news section – a portion of the website set aside to allow the users to circulate new and interesting articles within the community. The new CSS Newbie is no different, but our community news section has a twist. I’m conducting what I’m considering an experiment in social media. Instead of coming to my site, filling out a form, and awaiting moderation to get your news published, all you have to do is bookmark the page in one of the popular bookmarking sites (currently <a href="http://www.delicious.com/">Delicious </a>or <a href="http://ma.gnolia.com/">Ma.gnolia</a>, possibly more to come), give it a short description and a tag of “cssnewbienews” and voila! Your article will appear on CSS Newbie within an hour.</p>
<p>So, if you have an article that either you’ve written or you’ve found and really enjoyed, and you’d like to see it reach a wider audience, be sure to add the “cssnewbienews” tag when you bookmark it. If you use a different bookmarking service, contact me and let me know what it is, and I’ll see if I can get it added to the mix.</p>
<h3>New Advertising Options</h3>
<p>Redesigning the site allowed me to take some time to reconsider the advertising options available. I’ve made some tweaks that I think will benefit all involved&#8230; including reducing the cost of advertising. So if you have a message you want to get noticed, <a href="http://www.cssnewbie.com/advertise/">consider sponsoring CSS Newbie.</a> </p>
<h3>And Much, Much More</h3>
<p>Those are the highlights of the new site design, but there are of course many, many other tweaks and improvements scattered throughout the site. Let me know what you think! Leave a comment on this article, take the survey in the lower-right, send me a shout-out on twitter&#8230; I’m waiting to hear from you.</p>

<p><a href="http://feeds.feedburner.com/~a/cssnewbie?a=5rg2MN"><img src="http://feeds.feedburner.com/~a/cssnewbie?i=5rg2MN" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/cssnewbie?a=KcR1O"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=KcR1O" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=ms1io"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=ms1io" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=UyhHo"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=UyhHo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=1Kn5o"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=1Kn5o" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=bTemO"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=bTemO" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=45Gao"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=45Gao" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/471418165" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/css-newbie-gets-a-facelift/feed/</wfw:commentRss>
		<feedburner:awareness>http://api.feedburner.com/awareness/1.0/GetItemData?uri=cssnewbie&amp;itemurl=http%3A%2F%2Fwww.cssnewbie.com%2Fcss-newbie-gets-a-facelift%2F</feedburner:awareness><feedburner:origLink>http://www.cssnewbie.com/css-newbie-gets-a-facelift/</feedburner:origLink></item>
		<item>
		<title>Internet Explorer Bug Fix: Disappearing Positioned Anchors</title>
		<link>http://feeds.feedburner.com/~r/cssnewbie/~3/459136102/</link>
		<comments>http://www.cssnewbie.com/internet-explorer-bug-fix-disappearing-positioned-anchors/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 03:54:31 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Bugs and Fixes]]></category>

		<category><![CDATA[Floats and Positioning]]></category>

		<category><![CDATA[bug]]></category>

		<category><![CDATA[bug fix]]></category>

		<category><![CDATA[ie]]></category>

		<category><![CDATA[internet explorer]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=240</guid>
		<description><![CDATA[A while back when I was working on developing the jQuery popout tutorials, I ran across a significant and annoying bug in Internet Explorer 6 and 7. Specifically, Internet Explorer does not respect the height and width properties of block-level, absolutely positioned anchor tags if they contain no content.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.cssnewbie.com/wp-content/uploads/2008/11/clickable-beauty-400.gif" alt="" title="clickable positioned anchor tag" width="400" height="150" class="alignnone size-full wp-image-245" /></p>
<p>A while back when I was working on developing <a href="http://www.cssnewbie.com/jquery-popout-ad-part-1/">the jQuery popout tutorials,</a> I ran across a significant and annoying bug in Internet Explorer 6 and 7. Specifically, Internet Explorer does not respect the height and width properties of block-level, absolutely positioned anchor tags if they contain no content (or if that content has been moved or removed).</p>
<p>Instead of your anchors being the size you’ve specified, the size of the clickable area is limited to the size of the content inside the anchor. And therefore, if your anchor is “empty” (either because it’s an empty anchor tag, or you’ve used &#8220;display: none&#8221; or a negative margin to hide the content), your anchor tag’s clickable area is zero!</p>
<p>Let me explain a bit of what I mean. Let’s say I have a website with a very stylized banner at the top of the page, and I’ve decided to load the banner as a background image. However, in order to <a href="http://www.cssnewbie.com/4-ways-css-can-improve-your-seo/">play nice with search engines and keep my SEO high,</a> I’m still going to use an &lt;h1&gt; tag for my banner text, and then just hide its content. I also want a portion of my banner to be clickable, so I can let users get back to my homepage that way. <span id="more-240"></span></p>
<p>So let’s say this is my banner image:</p>
<p><img src="http://www.cssnewbie.com/wp-content/uploads/2008/11/clickable-banner-400.gif" alt="" title="sample banner" width="400" height="100" class="alignnone size-full wp-image-242" /></p>
<p>As you can see, the banner contains some fancy text, and I want that fancy text to act like a regular hyperlink and take people back to the front page.</p>
<p>I might write some XHTML that looks like this:</p>
<pre class="html">&lt;h1&gt;&lt;a href=&quot;/&quot;&gt;&lt;span&gt;This Is My Website&lt;/span&gt;&lt;/a&gt;&lt;/h1&gt;</pre>
<p>And some CSS to show the banner, make a portion clickable, and hide the text:</p>
<pre class="css">h1 {
	width: 800px;
	height: 200px;
	background: #fff url(mybanner.jpg) no-repeat; }
h1 a {
	position: absolute;
	top: 25px; // Move the anchor above the clickable area.
	left: 50px;
	display: block;
	width: 700px;
	height: 125px; }
h1 a span {
	display: none; }</pre>
<p>My background image is on my h1 tag, because it contains my full banner. I’ve then moved my anchor tag to sit right over the text in my image, and then hidden the text inside of the anchor tag so as not to distract from my lovely artistry. The result could be conceived thusly:</p>
<p><img src="http://www.cssnewbie.com/wp-content/uploads/2008/11/clickable-area-400.gif" alt="" title="sample banner with an invisible clickable area" width="400" height="100" class="alignnone size-full wp-image-244" /></p>
<p>So my clickable area is sitting directly over my image’s text, effectively turning it into a hyperlink. So we should be good, right? Well, in all browsers but Internet Explorer, we are. Unfortunately, because of the bug mentioned above, the anchor in IE has a clickable area of zero – my link might as well not even be there.</p>
<p>So what’s the workaround? Well, there are several.</p>
<h5>Apply a Border</h5>
<p>If, somehow, a border around your otherwise “invisible” anchor tag works well for your design, then rejoice! Your work is nearly done. Setting a border on the anchor tag forces Internet Explorer to recognize the width and height of the anchor, thereby giving it clickable area again. This fix was discovered while trying to debug the problem: adding a border to find out where the anchor was sitting on the page made it magically show up again. Go figure. So if you’re able to use a border (and perhaps chose a border color that blends into your background image?), this is the easiest fix of the bunch.</p>
<h5>Put an Image In the Anchor</h5>
<p> Another option is to simply not try to hide the contents of your anchor at all. If you simply put the image you’re trying to overlap into the anchor tag itself, you can bypass this whole messy affair:</p>
<pre class="html">&lt;h1&gt;&lt;a href=&quot;/&quot;&gt;&lt;img src=&quot;mybanner-text.jpg&quot; /&gt;&lt;/a&gt;&lt;/h1&gt;</pre>
<p>Of course, that defeats the purpose of having a nice big &lt;h1&gt; tag at the top of your page for the search engines to find. As a result, this is my least favorite solution of the bunch.</p>
<h5>Use a Background Image</h5>
<p>While debugging, I also discovered that using a background color on the anchor tag forced IE to notice the width and height of the anchor. Of course, that also obscured the text to which I was trying to link and obliterated my hopes for an invisible link. However, it turns out that background images also force IE to recognize the size of the anchor. </p>
<p>At first, I figured the best solution would be to simply slice up my banner and attach the clickable portion of the image as a background on my anchor:</p>
<pre class="css">h1 a {
	background-image: url(mybanner-slice.jpg); }</pre>
<p>And that solution is inelegant, but effective. But then I discovered that a transparent image works just as well! So then I created a 1px by 1px transparent gif and used that as my background instead:</p>
<pre class="css">h1 a {
	background-image: url(transparent.gif); }</pre>
<p>So even if the background color is transparent to human eyes, Internet Explorer can see and recognize the image as being present and thus will respect our height and width. In fact (and this gets a little strange), <em>the image doesn’t technically even have to exist</em> for this technique to work! If I tell IE that there’s a background image, but it can’t find the background image, it’ll still find our anchor size:</p>
<pre class="css">h1 a {
	background-image: url(fake_image.gif); }</pre>
<p>Now, I realize that this Internet Explorer bug only happens in a very specific use-case (absolutely positioned, empty anchors), but I’ve stumbled across it more than once in my work, so hopefully someone out there will find this workaround useful as well! Also, I should point out that none of these workarounds have any negative effect in any non-IE browsers, so go nuts!</p>

<p><a href="http://feeds.feedburner.com/~a/cssnewbie?a=Kmlbkg"><img src="http://feeds.feedburner.com/~a/cssnewbie?i=Kmlbkg" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/cssnewbie?a=Q864N"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=Q864N" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=jJo2n"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=jJo2n" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=bpuyn"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=bpuyn" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=jjZwn"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=jjZwn" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=RCR8N"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=RCR8N" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=XK66n"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=XK66n" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/459136102" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/internet-explorer-bug-fix-disappearing-positioned-anchors/feed/</wfw:commentRss>
		<feedburner:awareness>http://api.feedburner.com/awareness/1.0/GetItemData?uri=cssnewbie&amp;itemurl=http%3A%2F%2Fwww.cssnewbie.com%2Finternet-explorer-bug-fix-disappearing-positioned-anchors%2F</feedburner:awareness><feedburner:origLink>http://www.cssnewbie.com/internet-explorer-bug-fix-disappearing-positioned-anchors/</feedburner:origLink></item>
		<item>
		<title>Parla italiano? Check out CSSblog.it!</title>
		<link>http://feeds.feedburner.com/~r/cssnewbie/~3/449055118/</link>
		<comments>http://www.cssnewbie.com/check-out-cssblogit/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 02:39:55 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[review]]></category>

		<category><![CDATA[contest]]></category>

		<category><![CDATA[cssblog]]></category>

		<category><![CDATA[resource]]></category>

		<category><![CDATA[winner]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=237</guid>
		<description><![CDATA[A couple of months back, I ran a contest for my subscribers here on CSS Newbie. The prize was a copy of Eric Meyer’s pocket CSS reference book and a plug on my site. The winner of that contest was one Matthew Moro. And, finally, this is his plug.
]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.cssblog.it/'><img src="http://www.cssnewbie.com/wp-content/uploads/2008/11/cssblog-400.jpg" alt="" title="CSSblog.it" width="400" height="110" class="alignnone size-full wp-image-239" /></a></p>
<p>A couple of months back, <a href="http://www.cssnewbie.com/cssnewbie-subscriber-contest-winner-announced/">I ran a contest for my subscribers here on CSS Newbie.</a> The prize was a copy of <a href="http://www.amazon.com/exec/obidos/ASIN/0596515057/cssnewbie-20">Eric Meyer’s pocket CSS reference book</a> and a plug on my site. The winner of that contest was one Matthew Moro. Hopefully, Matthew has received his book by now. And, finally, this is his plug. :)</p>
<p>Matthew runs a website called <a href="http://cssblog.it/">CSSblog.it, a CSS-phillic resource for web developers</a> whose mastery of the Italian language (which is limited to barely deciphering the menu at our local <a href="http://www.spagworks.com/">Spaghetti Works</a>) far exceeds my own. Luckily, <a href="http://translate.google.com/translate?u=http://cssblog.it/">Google’s translation of CSSblog.it</a> seems to be fairly accurate – giving me a window into the sort of work Matthew is doing.</p>
<p>CSSblog.it is part of a larger network of tech-related blogs in the Italian language. Other blogs include <a href="http://tuxblog.it/">Tuxblog.it</a> for Linux users and <a href="http://phpblog.it/">PHPblog.it</a> for PHP aficionados (to borrow a Spanish phrase). </p>
<p><span id="more-237"></span></p>
<p>However, while Tuxblog and PHPblog both offer a large array of longer original articles, at this point CSSblog is predominantly filled with short excerpts or write-ups describing an article somewhere else on the web – although Matthew assures me his goal is to get more original content up on the site. And of course, there’s something to be said for not relying solely on original content. CSSblog.it is updated on a daily or near-daily basis (compare that to my track record of late!), while the other blogs in the “blog.it” network seem to be updated less frequently. And Matthew links back here to CSS Newbie with fair frequency, so you know he has discerning tastes.</p>
<p>All in all, <a href="http://cssblog.it/">CSSblog.it looks to be a great resource for Italian or Italian-speaking web developers</a> to keep up on their craft. If you’re linguistically inclined, or just lucky enough to be born somewhere on Europe’s boot, be sure to give CSSblog.it a look!</p>

<p><a href="http://feeds.feedburner.com/~a/cssnewbie?a=38hRxn"><img src="http://feeds.feedburner.com/~a/cssnewbie?i=38hRxn" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/cssnewbie?a=IQzaN"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=IQzaN" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=BaEon"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=BaEon" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=FRUrn"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=FRUrn" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=2nw2n"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=2nw2n" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=S53HN"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=S53HN" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=1yDkn"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=1yDkn" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/449055118" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/check-out-cssblogit/feed/</wfw:commentRss>
		<feedburner:awareness>http://api.feedburner.com/awareness/1.0/GetItemData?uri=cssnewbie&amp;itemurl=http%3A%2F%2Fwww.cssnewbie.com%2Fcheck-out-cssblogit%2F</feedburner:awareness><feedburner:origLink>http://www.cssnewbie.com/check-out-cssblogit/</feedburner:origLink></item>
		<item>
		<title>Styling Zebra Striped Tables With CSS</title>
		<link>http://feeds.feedburner.com/~r/cssnewbie/~3/441685478/</link>
		<comments>http://www.cssnewbie.com/styling-zebra-striped-tables-with-css/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 04:01:10 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Basic Techniques]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[a list apart]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[tables]]></category>

		<category><![CDATA[zebra striping]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=233</guid>
		<description><![CDATA[In this article, I will show you an easy way to create an easily scanable and aesthetically pleasing table that doesn’t require you to mess with your XHTML. In fact, you could easily apply this to tables already on your website!]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.cssnewbie.com/example/zebra-tables/'><img src="http://www.cssnewbie.com/wp-content/uploads/2008/11/zebra-400.gif" alt="" title="Zebra striped table using CSS" width="400" height="109" class="alignnone size-full wp-image-235" /></a></p>
<p>I recently spent a bit of time on <a href="http://hundredpushups.com/index.html">the OneHundredPushups website,</a> and the aspect of the site that most caught my eye (aside from ninja-girl on the front page) was the zebra-striped tables strewn throughout. (For those not in the know, zebra striping tables refers to alternating colored backgrounds on table rows, a la iTunes.) <a href="http://www.alistapart.com/articles/zebrastripingmoredataforthecase">Studies have shown</a> that there is (or at least can be) a slight performance increase associated with zebra striped tables (or at least there isn’t a decrease), and that most users prefer zebra striping to traditional lined tables.</p>
<p>I thought the tables on OneHundredPushups were fairly well done (<a href="http://hundredpushups.com/week1.html">take a look for yourself here</a>), but a glance at the code showed me that the developer had put more work than was necessary into creating his stripes. Here, I’ll show you an easy way to create a table like the one in the image above <a href="http://cssnewbie.com/example/zebra-tables/">(or on the example page here</a>) that doesn’t require you to mess with your XHTML &mdash; in fact, you could easily apply this to tables already on your website!</p>
<p>Of course, before we can dive into the CSS, we’ll need a table to style. Mine looks something like this:</p>
<pre class="html">
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;
	&lt;tr&gt;
		&lt;th&gt;State&lt;/th&gt;
		&lt;th&gt;Date of Poll&lt;/th&gt;
		&lt;th&gt;% Voting Dem.&lt;/th&gt;
		&lt;th&gt;% Voting GOP&lt;/th&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;AR&lt;/td&gt;
		&lt;td&gt;10/27&lt;/td&gt;
		&lt;td&gt;44&lt;/td&gt;
		&lt;td&gt;54&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;AZ&lt;/td&gt;
		&lt;td&gt;10/23&lt;/td&gt;
		&lt;td&gt;41&lt;/td&gt;
		&lt;td&gt;49&lt;/td&gt;
	&lt;/tr&gt;
	... and so on ...
&lt;/table&gt;
</pre>
<p>As you can see, it’s nothing out of the ordinary. I’ve used the old-school cellspacing and cellpadding attributes just to ensure consistent treatment across browsers. And otherwise, I’m using a &lt;th&gt; tag or four to distinguish my table headers from the rest of my code. Otherwise, we’ve just got rows and cells galore. You’ll notice there’s not a single class or ID present here (although if I only wanted to style <em>some</em> of the tables on my site, I’d probably give the styled ones a specific class name).</p>
<p>Next, let’s take a look at the basic CSS styles I’m using:</p>
<pre class="css">table {
	width: 100%;
	border: 1px solid #cef;
	text-align: left; }
th {
	font-weight: bold;
	background-color: #acf;
	border-bottom: 1px solid #cef; }
td,th {
	padding: 4px 5px; }</pre>
<p>I’ve set the table width to 100% to stop it from collapsing to its minimum size (the default behavior), then given it a pale blue border around the outside. I’ve also set the text alignment throughout the table to “left” &mdash; this is to prevent my table headers from centering themselves, which is the default. I prefer my headers to be aligned with my content, but your mileage may vary.</p>
<p>When it comes to the headers, I’ve done a little styling: I’ve given them a background color (a bit darker than my border), bolded the text, and given the bottom of the headings a border what matches the border around my entire table.</p>
<p>Finally, I’m just adding a bit of padding to the interiors of the table cells, to give them a little breathing room. Personally, I think an appropriate use of white (or at least negative) space can be just as critical to legibility as zebra striping &mdash; perhaps someone out there more statistically inclined than me should look into that!</p>
<p>Those styles give us our basic table layout, which looks something like this:</p>
<p><img src="http://www.cssnewbie.com/wp-content/uploads/2008/11/prezebra.gif" alt="" title="CSS styled table without zebra striping" width="400" height="107" class="alignnone size-full wp-image-236" /></p>
<p>So how do we get the alternating rows? For that, I’m creating a new class in my CSS, specifically for the odd (that is, not-even) rows of the table:</p>
<pre class="css">.odd {
	background-color: #def; }
.odd td {
	border-bottom: 1px solid #cef; }</pre>
<p>This class, once applied to alternating rows of my table, would cause every other row to gain a pale blue background color and a slightly darker bottom border. <a href="http://www.alistapart.com/articles/zebrastripingmoredataforthecase">Since this <em>A List Apart</em> study by Jessica Enders</a> suggested that alternating colored rows and underlines were two of the most aesthetically appealing ways to present tabular data, I figured&#8230; why not use both?</p>
<p>Now if I wanted, all I would need to do is go back through my HTML and apply this class to alternating rows in my tables, like the folks at OneHundredPushups have done. However, you’ll notice that my code above doesn’t have any CSS classes. That’s because I prefer to work smarter whenever I have the chance. Instead of turning back to my HTML, I’m going to look to JavaScript (specifically, <a href="http://docs.jquery.com/">jQuery</a>) to do my heavy lifting for me.</p>
<p>To apply our class automatically, all the jQuery I need is this:</p>
<pre class="js">$(document).ready(function(){
	$("tr:odd").addClass("odd");
});</pre>
<p>In layman’s terms, this tiny snippet is saying, “once the document is done loading, cycle through the page, find every ‘odd’ table row, and give it a class of ‘odd.’” Then our CSS takes over and does the rest. Oh, and for the record, you could also write a second rule like this:</p>
<pre class="js">$("tr:even").addClass("even");</pre>
<p>Which would do the exact same thing as above, only apply it to the “even” rows of the table. And just so you’re not caught off guard by this script’s behavior, it’s good to know in advance that the :odd and :even pseudo-classes start counting at zero, not one. So the first row of your table is, according to jQuery, the “0th” row, and is therefore even.</p>
<p>And there you have it! <a href="http://cssnewbie.com/example/zebra-tables/">You can see the whole thing in action here.</a> And now, go forth and make the web a more beautiful (or at least stripy-er) place.</p>

<p><a href="http://feeds.feedburner.com/~a/cssnewbie?a=oqWaWb"><img src="http://feeds.feedburner.com/~a/cssnewbie?i=oqWaWb" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/cssnewbie?a=qtOTN"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=qtOTN" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=Pg5Fn"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=Pg5Fn" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=Xxhin"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=Xxhin" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=fv31n"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=fv31n" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=R5w7N"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=R5w7N" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=kqazn"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=kqazn" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/441685478" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/styling-zebra-striped-tables-with-css/feed/</wfw:commentRss>
		<feedburner:awareness>http://api.feedburner.com/awareness/1.0/GetItemData?uri=cssnewbie&amp;itemurl=http%3A%2F%2Fwww.cssnewbie.com%2Fstyling-zebra-striped-tables-with-css%2F</feedburner:awareness><feedburner:origLink>http://www.cssnewbie.com/styling-zebra-striped-tables-with-css/</feedburner:origLink></item>
		<item>
		<title>Understanding XHTML Semantics</title>
		<link>http://feeds.feedburner.com/~r/cssnewbie/~3/421932932/</link>
		<comments>http://www.cssnewbie.com/understanding-xhtml-semantics/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 20:23:10 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Basic Techniques]]></category>

		<category><![CDATA[CSS Rules]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[Definition of CSS]]></category>

		<category><![CDATA[semantics]]></category>

		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=230</guid>
		<description><![CDATA[Today, I want to take a brief step back from our normal how-to fare to talk about why we do things the way we do them: the semantics that guide our development.]]></description>
			<content:encoded><![CDATA[<p><a href='http://flickr.com/photos/dharmasphere/2277286846/'><img src="http://www.cssnewbie.com/wp-content/uploads/2008/10/semantopoly-400.jpg" alt="\&quot;Semantopoly\&quot; photo by dharmasphere. Used under a Creative Commons license." title="semantopoly-400" width="400" height="175" class="alignnone size-full wp-image-232" /></a></p>
<p>Even those of you in the audience who are new to web development (or perhaps just new to the site) have still probably heard the word &#8220;semantics&#8221; or the phrase &#8220;semantic development&#8221; thrown about in various web-related conversations (and if not, I certainly hope you will soon!). But what does that phrase really mean? Today, I want to take a brief step back from our normal how-to fare to talk about why we do things the way we do them: the semantics that guide our development.</p>
<h5>A Definition of Semantic Development</h5>
<p>So what does this whole &#8220;semantics&#8221; thing mean? In web development, we use the term to refer to using tags that describe what something <em>is</em> instead of what it <em>looks like</em>. Or to put it another way, as Dan Cederholm states in his fantastic book <a href="http://www.amazon.com/exec/obidos/ASIN/1590593812/cssnewbie-20">Web Standards Solutions:</a></p>
<blockquote><p>[W]e&#8217;re striving to use tags that imply <em>meaning</em>, rather than a presentational instruction. Are you dealing with a list of items? Then mark it up as such. Is this a table of data? Then structure it that way.</p></blockquote>
<p>So in short, when we&#8217;re talking about semantic development we&#8217;re looking for a way of separating our structural information from our presentational information. And luckily, we have all the tools we need right in front of us. CSS is a presentational language; stylesheets affect the appearance of objects, not their underlying structure. This means we can use XHTML to create our structure (and only our structure), and move all of our presentational stuff into our CSS.</p>
<h5>Understanding Unsemantic Markup</h5>
<p>Now that we have a definition in mind, let&#8217;s look over a few examples of what semantic markup is <strong>not</strong>. Once you get comfortable playing &#8220;spot the not,&#8221; the definition will start to make a lot more sense.</p>
<p>Here&#8217;s an example of how not to create a large heading for your blog posts:</p>
<pre class="html">&lt;p&gt;&lt;b&gt;Semantics, Schemantics&lt;/b&gt;&lt;/p&gt;</pre>
<p>And here&#8217;s another:</p>
<pre class="html">&lt;div class=&quot;headingBig&quot;&gt;Why Konqueror Rocks&lt;/div&gt;</pre>
<p>Now admittedly, with the right CSS to back up your mad XHTML hackery, either one of these could end up looking like a perfectly legitimate heading on the screen. So what&#8217;s all the fuss about?</p>
<p>These examples are unsemantic for two reasons. Both of our examples are using tags (or classes) that don&#8217;t have anything to do with headings to create a heading-like effect. This is a faux pas because we <em>have</em> a tags at our disposal for the express purpose of creating headings: namely, the &lt;h1&gt; through &lt;h6&gt; tags. A good portion of writing semantic code is simply knowing the tools (tags) at your disposal and when to use them. </p>
<p>Of course, there isn&#8217;t a single tag for every use case, so sometimes we just have to do the best we can. And sometimes that causes debates within the community, because oftentimes complex problems can be solved with several different, arguably semantic, solutions &mdash; like when <a href="http://www.cssnewbie.com/list-based-css-calendar/" title="A Semantic List-Based CSS Calendar">I argued that a calendar could be represented using an unordered list instead of a table</a> (you can also <a href="http://www.cssnewbie.com/on-calendars-lists-tables-and-semantics/" title="On Calendars, Lists, Tables and Semantics">see my follow-up article here</a>).</p>
<p>Second, our first unsemantic heading example is using a presentational tag. In XHTML, at least, the &lt;b&gt; (bold) tag is generally frowned upon, precisely for the reason of semantics. The difference between a boldfaced word and a roman word is a presentational one &mdash; the bold tag doesn&#8217;t offer any semantic information about the text it wraps. That&#8217;s why XHTML offers the options of using the &lt;strong&gt; tag instead. The strong tag simply suggests that the word/phrase/whatever that it wraps is text that is somehow stronger than its surrounding text. The tag doesn&#8217;t dictate <em>how</em> that text should be strengthened&#8230; only that, semantically speaking, the text contained within is comparatively stronger. We can then turn to CSS to determine how our strong tag should be treated in our document.</p>
<h5>Tips for Semantic Markup</h5>
<p>So how can you help ensure that, moving forward, you&#8217;re generating logical, semantic markup instead of sloppy, structural-presentational code soup? Here are a few suggestions to help you along the way:</p>
<ul>
<li>Know your options. Unless you&#8217;re the guy (or gal (okay, probably guy)) that wrote the XHTML specifications, there are probably more XHTML tags out there than you know. <a href="http://csstidy.sourceforge.net/xhtml.php">This XHTML Cheat Sheet might be a nice place to start learning more.</a></li>
<li>Think structurally. When you&#8217;re writing XHTML, try to boil things down to what they truly are, instead of worrying about what they&#8217;re going to look like when your site is done. Theoretically, a well-designed structure should be able to accommodate all sorts of different designs without having to change. <a href="http://www.csszengarden.com/">That&#8217;s the idea behind the CSS Zen Garden,</a> though admittedly their XHTML is pretty darn verbose to give the designers plenty of &#8220;hooks.&#8221;</li>
<li>Code inside the box. XHTML is an amazingly flexible language, but sometimes its easier for me to code semantically if I treat my XHTML like I would a language that was going to be interpreted by machines instead of humans. Your computer doesn&#8217;t care what a heading <em>looks</em> like &mdash; it cares that it can classify certain data as headings. This has the added benefit of resulting in pages that machines (like Google&#8217;s bots) <em>do</em> understand&#8230; resulting in <a href="http://www.cssnewbie.com/4-ways-css-can-improve-your-seo/" title="4 Ways CSS can Improve Your SEO">a nice SEO boost in the end.</a></li>
</ul>
<p>If you have any more tips, things that you do to help yourself code more semantically, I&#8217;d love to hear about them in the comments. Drop me a line!</p>

<p><a href="http://feeds.feedburner.com/~a/cssnewbie?a=JYoUvs"><img src="http://feeds.feedburner.com/~a/cssnewbie?i=JYoUvs" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/cssnewbie?a=CY9yM"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=CY9yM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=2OQIm"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=2OQIm" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=Vfu3m"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=Vfu3m" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=xpesm"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=xpesm" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=o7tDM"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=o7tDM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=ezeJm"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=ezeJm" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/421932932" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/understanding-xhtml-semantics/feed/</wfw:commentRss>
		<feedburner:awareness>http://api.feedburner.com/awareness/1.0/GetItemData?uri=cssnewbie&amp;itemurl=http%3A%2F%2Fwww.cssnewbie.com%2Funderstanding-xhtml-semantics%2F</feedburner:awareness><feedburner:origLink>http://www.cssnewbie.com/understanding-xhtml-semantics/</feedburner:origLink></item>
		<item>
		<title>jQuery-Based Popout Ad: Part 3</title>
		<link>http://feeds.feedburner.com/~r/cssnewbie/~3/408777445/</link>
		<comments>http://www.cssnewbie.com/jquery-popout-ad-part-3/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 01:17:40 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Advanced Techniques]]></category>

		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=228</guid>
		<description><![CDATA[The previous article in this series explained how to take CSS- and XHTML-based advertisement we had developed and animate it using the jQuery JavaScript library. Today, we're going to expand our jQuery a bit to make our ad a little bit more user-friendly.]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.cssnewbie.com/example/popout-ad/part3.html'><img src="http://www.cssnewbie.com/wp-content/uploads/2008/10/popout-functions.gif" alt="" title="popout-functions" width="400" height="149" class="alignnone size-full wp-image-229" /></a></p>
<p><strong>Note:</strong> <a href="http://www.cssnewbie.com/jquery-popout-ad-part-1/">Part 1 of this series is available here,</a> and <a href="http://www.cssnewbie.com/jquery-popout-ad-part-2/">you can read part 2 here.</a> I&#8217;d recommend reading both of those articles before continuing on to this one.</p>
<p><a href="http://www.cssnewbie.com/jquery-popout-ad-part-2/">The previous article in this series</a> explained how to take CSS- and XHTML-based advertisement we&#8217;d developed and animate it using the <a href="http://jquery.com/">jQuery JavaScript library.</a> Today, we&#8217;re going to expand our jQuery a bit to make our ad a little bit more user-friendly (if an ad can ever be said to be user-friendly, that is).</p>
<p>We&#8217;re going to expand our functionality in two important ways. First, we&#8217;ll give the popout a memory: when the user closes the ad, it will remain closed for a predetermined number of days, unless they choose to open it again. And second, we&#8217;ll allow the user to open <strong>and</strong> close the ad by clicking the permanent sidebar cap. And before I get started, I&#8217;d like to point out that these two examples are really expandable to countless practical uses &mdash; don&#8217;t feel limited just because I&#8217;m talking about a popout here!</p>
<h5>Remembering the User</h5>
<p>The only practical way to remember whether the user has opened or closed our ad across multiple visits is by using a browser cookie. <a href="http://www.cssnewbie.com/message-box-javascript-css/" title="Perma-Closing Message Boxes with JavaScript and CSS">I&#8217;ve written about setting browser cookies here before,</a> and I&#8217;ll be honest – it&#8217;s a tedious process writing the code to make the magic happen. However, because we&#8217;re already using the jQuery framework, our job is about to get a heck of a lot easier.</p>
<p>jQuery does not come with built-in cookie-setting functionality, which is a rather large shortcoming in my opinion. Luckily, jQuery has a rather active community behind it, and a nice man by the name of <a href="http://www.stilbuero.de/2006/09/17/cookie-plugin-for-jquery/">Klaus Hartl has released a jQuery cookie plugin.</a> All we need to do is include the link to the plugin in the head of our document, underneath our call to the jQuery library, like so:</p>
<pre class="html">&lt;script language=&quot;javascript&quot; src=&quot;/js/jquery/jquery.js&quot;&gt;&lt;/script&gt;
&lt;script language=&quot;javascript&quot; src=&quot;/js/jquery/jquery.cookie.js&quot;&gt;&lt;/script&gt;</pre>
<p>And voila! Cookies have suddenly gotten a whole lot easier. You&#8217;ll see just how easy in a moment.</p>
<p>So how are we going to use these cookies? Well, what makes the most sense to me (and you&#8217;re welcome to suggest alternatives) is this: whenever the user closes the ad box, we&#8217;ll set a cookie indicating this. If the user opens the ad box again, we&#8217;ll delete the cookie. When we load the page, we&#8217;ll simply check to see if our cookie is set: if not, we&#8217;ll open the ad; if so, we&#8217;ll leave the ad closed.</p>
<p>First up, let&#8217;s give our cookie a name. For consistency&#8217;s sake, I&#8217;m going to define the name at the top of my $(document).ready function, along with the other variables:</p>
<pre class="js">var popOut = "#popout";
var adBox = "#adbox";
var adWidth = $(adBox).width() + $("#cap").width();
var adCookie = "ad-example";</pre>
<p>In this example, I&#8217;m calling my cookie &#8220;ad-example,&#8221; but you could really name it whatever you wanted.</p>
<p>Next, we&#8217;ll have to edit our openAd and closeAd functions that we developed in the last article to accommodate the setting and un-setting of cookies. Our openAd function now looks like this:</p>
<pre class="js">function openAd() {
	$(popOut).width(adWidth+"px");
	$(adBox).animate({marginLeft: "0"},1200)
	$.cookie(adCookie, null);
}</pre>
<p>You&#8217;ll note the new line at the bottom. What we&#8217;re doing here is calling the cookie function that is included in the plugin we&#8217;re using. After the user opens the ad, we look for any cookies named whatever we selected at the top of the document. If one exists, we set it to &#8220;null,&#8221; effectively destroying it.</p>
<p>Next up, we have the closeAd function:</p>
<pre class="js">function closeAd() {
	$(adBox).animate({marginLeft: "-"+adWidth+"px"},1200,"linear",
		function(){ $(popOut).width($("#cap").width() + "px"); }
	);
	$.cookie(adCookie,'closed',{expires: 28});
}</pre>
<p>Again, we&#8217;re only adding a single line to our code. You can see how easy this is compared to <a href="http://www.cssnewbie.com/message-box-javascript-css/" title="Perma-Closing Message Boxes with JavaScript and CSS">writing your own JavaScript cookie function!</a> This time, after the ad has successfully closed, we&#8217;re setting a cookie. We&#8217;re giving it a name of whatever we determined at the top of the function (&#8221;ad-example,&#8221; in our case), giving it a value of &#8220;closed,&#8221; and setting the cookie to expire in 28 days (four weeks). You could choose whatever duration you felt appropriate here.</p>
<p>And finally, we&#8217;ll want to alter the last line in our $(document).ready function, the one that opens the ad when the page loads. The line that opens the ad will now read like this:</p>
<pre class="js">if(!$.cookie(adCookie)) {
	$(popOut).animate({opacity: 1.0}, 1500, "linear", openAd);
}</pre>
<p>All we&#8217;ve done is wrap our animation function in an if statement. If the cookie does not exist (the exclamation point at the beginning of our if statement means &#8220;if the following is <em>not</em> true&#8230;&#8221;), we will execute the animation we built last time. But if there is a cookie set (meaning the user has chosen to close the ad), we don&#8217;t animate our ad &mdash; meaning it remains hidden off the edge of our page by our CSS.</p>
<h5>Developing Click Logic</h5>
<p>Next up, we want to alter the click logic on the ad cap &mdash; if the ad is closed, a click should open it. But if it&#8217;s already open, the ad should close when the user clicks. This increases the odds the user will be able to get rid of the ad when they wish, which is an important usability feature in my mind.</p>
<p>To do this, we&#8217;ll need to edit the click function set on our cap. But how do we know if the ad should be opened or closed? Easy: we just set a cookie that will give us the answer we need. If the user clicks on the cap and a cookie is already set, that means the ad is currently closed, so we should open it back up. Otherwise, if no cookie is set, that means our ad is already open. A click at that point should close our ad instead.</p>
<p>Because we went to the trouble of developing functions to open and close our ad, our code change is pretty simple. We just edit the cap&#8217;s click functionality like so:</p>
<pre class="js">$("#open").click(function() {
	if(!$.cookie(adCookie)) {
		closeAd();
	} else {
		openAd();
	}
	return false;
});</pre>
<p>All it takes is a simple if-else statement. If the cookie isn&#8217;t set, close the ad. Otherwise, open the ad like we would have originally.</p>
<p>And with those changes, we have now developed a popout box that is simultaneously eye-catching and user-friendly. Here&#8217;s the JavaScript in its entirety:</p>
<pre class="js">$(document).ready(function() {
	var popOut = "#popout";
	var adBox = "#adbox";
	var adWidth = $(adBox).width() + $("#cap").width();
	var adCookie = "ad-example";

	function openAd() {
		$(popOut).width(adWidth+"px");
		$(adBox).animate({marginLeft: "0"},1200)
		$.cookie(adCookie, null);
	}

	function closeAd() {
		$(adBox).animate({marginLeft: "-"+adWidth+"px"},1200,"linear",
			function(){ $(popOut).width($("#cap").width() + "px"); }
		);
		$.cookie(adCookie,'closed',{expires: 28});
	}

	$("#open").click(function() {
		if(!$.cookie(adCookie)) {
			closeAd();
		} else {
			openAd();
		}
		return false;
	});
	$("#close").click(function() {
		closeAd();
		return false;
	});	

	if(!$.cookie(adCookie)) {
		$(popOut).animate({opacity: 1.0}, 1500, "linear", openAd);
	}
});</pre>
<p><a href="http://www.cssnewbie.com/example/popout-ad/part3.html">And you can see a working example of our ad here.</a> If you have any questions, comments, or concerns, please leave a comment and I will do my best to address them.</p>

<p><a href="http://feeds.feedburner.com/~a/cssnewbie?a=TkB6iN"><img src="http://feeds.feedburner.com/~a/cssnewbie?i=TkB6iN" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/cssnewbie?a=6hp3M"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=6hp3M" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=8b4pm"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=8b4pm" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=ePPBm"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=ePPBm" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=b6opm"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=b6opm" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=qR7CM"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=qR7CM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=MK4jm"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=MK4jm" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/408777445" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/jquery-popout-ad-part-3/feed/</wfw:commentRss>
		<feedburner:awareness>http://api.feedburner.com/awareness/1.0/GetItemData?uri=cssnewbie&amp;itemurl=http%3A%2F%2Fwww.cssnewbie.com%2Fjquery-popout-ad-part-3%2F</feedburner:awareness><feedburner:origLink>http://www.cssnewbie.com/jquery-popout-ad-part-3/</feedburner:origLink></item>
		<item>
		<title>jQuery-Based Popout Ad: Part 2</title>
		<link>http://feeds.feedburner.com/~r/cssnewbie/~3/394787523/</link>
		<comments>http://www.cssnewbie.com/jquery-popout-ad-part-2/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 02:54:21 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Advanced Techniques]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[ads]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[popout]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=225</guid>
		<description><![CDATA[Part 2 of our series is going to build on what we accomplished last week. Namely, we’re going to take the ad we built last week and animate it, as well as provide the user with a means to open and close the ad.]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.cssnewbie.com/example/popout-ad/part2.html'><img src="http://www.cssnewbie.com/wp-content/uploads/2008/09/popout-animated.jpg" alt="" title="animated jquery based popout ad" width="400" height="363" class="alignnone size-full wp-image-226" /></a></p>
<p><strong>Note: </strong><a href="http://www.cssnewbie.com/jquery-popout-ad-part-1/">Part 1 of this series is available here.</a> Be sure to read it first, or what comes here won’t make a lot of sense. :)</p>
<p>Part 2 of our series is going to build on what we accomplished last week. Namely, we’re going to take the ad we built last week and animate it, as well as provide the user with a means to open and close the ad. We’ll be using jQuery for most of what we do, so you’ll need to include <a href="http://jquery.com/">the jQuery library script</a> at the top of your document for this to work (see the source of <a href="http://www.cssnewbie.com/example/popout-ad/part2.html">the example page</a> to see how this is done).</p>
<p>Before we get started on our JavaScript, however, we’ll need to make one tiny addendum to our CSS from last week:</p>
<pre class="css">#popout #adbox {
	margin-left: -300px;
}</pre>
<p>This bit of CSS moves our ad box (the bit we hope to animate) 300 pixels to the left of where it sits normally. And because our ad is 300 pixels wide (convenient, no?) this effectively hides the ad off the side of the screen. This way, our ad is hidden by default, and we can use jQuery to slide it back onto the screen.</p>
<p>Now let’s get started with the jQuery. We’ll wrap everything we write today in a “document ready” function, which looks like this: </p>
<pre class="js">$(document).ready(function() {
});</pre>
<p>This prevents everything we put inside from firing until the document has finished loading, which is a good thing for us: we don’t want our ad to start moving until it’s all loaded!</p>
<h5>Set Some Variables</h5>
<p>We’ll start by defining a few variables that we’ll use throughout the script:</p>
<pre class="js">var popOut = "#popout";
var adBox = "#adbox";
var adWidth = $(adBox).width() + $("#cap").width();</pre>
<p>The first variable, popOut, contains the CSS ID of the overall popout container that we built last week. popOut contains the ad and the ad’s cap both. The second variable (adBox) is the ID of just the animated bit of the ad. And finally, adWidth is a custom-built variable which gives us the total width of the area our ad takes up (the width of the ad plus the width of the cap). This variable will come in handy when we start animating our ad, to let us know how much space we have to work with.</p>
<h5>The Animation Functions</h5>
<p>Now that we’ve defined our primary variables, let’s delve into the actual animation of the ad. I’ve broken both parts of our animations (sliding in to the page and sliding back out again) into two functions. The opening function looks like this:</p>
<pre class="js">function openAd() {
	$(popOut).width(adWidth+"px");
	$(adBox).animate({marginLeft: "0"},1200);
}</pre>
<p>This tiny little function is doing a surprising amount of work (which is really the power of jQuery). The first line simply sets the width of the popout container to be the width of the ad plus the cap – making sure we have enough room to do our animation. This may seem redundant, but it’ll make more sense later.</p>
<p>The second line of our function is the real workhorse. Here, we’re using jQuery to build a custom animation, which we’re attaching to our adBox variable. We’re telling jQuery to set a left margin of zero on the adBox (to move it back to its “real” position, in other words). But instead of doing it all at once, we’re telling jQuery to slowly make the change over the course of 1200 milliseconds (or 1.2 seconds, if you prefer). Pretty powerful stuff for a single line of code, no?</p>
<p>And now that we’ve built the function to open our ad, we can build the function to close it back up again:</p>
<pre class="js">function closeAd() {
	$(adBox).animate({marginLeft: "-"+adWidth+"px"},1200,"linear",
		function(){ $(popOut).width($(".cap").width() + "px"); }
	);
}</pre>
<p>This function is obviously a little more complicated, although it wouldn’t have to be if it weren’t for a but in Internet Explorer 6.</p>
<p>The first bit looks somewhat familiar, I hope. We’re setting another animation here, this time setting the left margin of the ad  to be the <em>negative</em> of the width of the ad space, effectively hiding it off the side of the screen. And we’re doing it over the same 1.2 seconds as our last animation (though you can tweak these numbers to your heart’s content).</p>
<p>After that, things get a little more complicated. The next bit, “linear,” simply tells the animation function to maintain the same speed throughout the animation – not to slow down at the beginning or end. </p>
<p>And when the animation is finished, we’re firing off yet another function. This function sets the width of the popout area to be only as wide as the cap, since that’s the only part of the ad that is visible (hence why we have to set a width at the beginning of our openAd function). </p>
<p>This is because of a bug in Internet Explorer 6 that prevents the user from “clicking through” an empty div. What that means is, if the user tried to close your ad and then click on anything that had been previously hidden by the ad – a link in your sidebar, for example – they wouldn’t be able to click. Even though the ad is gone, IE6 would assume you were reserving the space for some greater purpose. So to get around this, we grow and shrink the popout space as necessary.</p>
<h5>Create Click Events</h5>
<p>Now that we’ve created our animation functions, we can attach them quickly and easily to the anchors we built last week for such a purpose. As you’ll recall, we included a “close” button in the corner of the ad – clicking this should obviously close the ad. And if someone ever wanted to see the ad again (we should be so lucky!), clicking the cap will bring it right back out.</p>
<pre class="css">$("#open").click(function() {
	openAd();
	return false;
});
$("#close").click(function() {
	closeAd();
	return false;
});</pre>
<p>These functions are fairly simple: We’re simply using jQuery to assign an onClick event to our cap (with a CSS ID of “open”) and our close button (which we called “#close” last week). When the user clicks on either of those elements, the function inside (openAd and closeAd, respectively) will trigger. After that, we’ve included a “return false,” which simply tells the browser not to bother following the href in our anchors (it was blank anyway, but we don’t want the page refresh that would go along with an attempt).</p>
<p>And now, one last line of jQuery magic. When we open our page, we want our ad to pop out of the side of the page, catching the user’s eye and drawing their attention to our box’s content. To do that, we use this line:</p>
<pre class="js">$(popOut).animate({opacity: 1.0}, 1500, "linear", openAd);</pre>
<p>jQuery is very powerful, but one thing it lacks is a simple “delay” function. And here’s the problem: I don’t want my ad to start animating the very instant that my document becomes “ready.” For one, I’d like the reader to be able to orient themselves on the page. For another, just because the document is ready (i.e., our code has downloaded) doesn’t mean that all of my images have finished downloading. And an animated ad without any images is far less impressive than the image-rich variety.</p>
<p>Luckily, I found <a href="http://p.karageorgakis.com/blog/jquery_simulating_a_delay_function_between_fade_in_out_effects/">a solution on a blog titled “Panagiotis Karageorgakis,”</a> and modified it to fit my needs. The basic concept is this: we animate the ad in some way that makes <em>absolutely no change whatsoever</em> on the screen, and then we chain on a second animation when we’re done.</p>
<p>So here, our animation, which will fire on load, tells jQuery to slowly set the opacity of our ad to “1.0” (opaque) over the course of 1.5 seconds. Of course, our ad was already fully opaque, so this has no effect at all. And then after the first “animation” is completed, we fire off another function: namely, our openAd function, which will do all the heavy lifting involved in actually opening our ad.</p>
<p>And that’s all there is to it! We now have a fully functioning popout ad. <a href="http://www.cssnewbie.com/example/popout-ad/part2.html">You can see it in action here.</a> And here’s the completed JavaScript, so you don’t have to hunt it down:</p>
<pre class="js">$(document).ready(function() {
	var popOut = "#popout";
	var adBox = "#adbox";
	var adWidth = $(adBox).width() + $(".cap").width();

	function openAd() {
		$(popOut).width(adWidth+"px");
		$(adBox).animate({marginLeft: "0"},1200);
	}

	function closeAd() {
		$(adBox).animate({marginLeft: "-"+adWidth+"px"},1200,"linear",
			function(){ $(popOut).width($(".cap").width() + "px"); }
		);
	}

	$("#open").click(function() {
		openAd();
		return false;
	});
	$("#close").click(function() {
		closeAd();
		return false;
	});	

	$(popOut).animate({opacity: 1.0}, 1500, "linear", openAd);
});</pre>
<p>Of course, that isn’t to say we couldn’t make our ad a little fancier than it is. Next week, we’ll go over some ways to make the ad even more advanced – like remembering whether the ad should be open or closed, or letting the user open <em>and</em> close the ad by clicking on the cap. Stay tuned!</p>
<p><strong>Note:</strong> <a href="http://www.cssnewbie.com/jquery-popout-ad-part-3/">Part 3 of this series is available here.</a> And if you missed it, <a href="http://www.cssnewbie.com/jquery-popout-ad-part-1/">here&#8217;s part 1.</a></p>

<p><a href="http://feeds.feedburner.com/~a/cssnewbie?a=tvjFjX"><img src="http://feeds.feedburner.com/~a/cssnewbie?i=tvjFjX" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/cssnewbie?a=alK5L"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=alK5L" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=fVbPl"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=fVbPl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=RTcsl"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=RTcsl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=DuPpl"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=DuPpl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=v8f3L"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=v8f3L" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=Z7gBl"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=Z7gBl" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/394787523" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/jquery-popout-ad-part-2/feed/</wfw:commentRss>
		<feedburner:awareness>http://api.feedburner.com/awareness/1.0/GetItemData?uri=cssnewbie&amp;itemurl=http%3A%2F%2Fwww.cssnewbie.com%2Fjquery-popout-ad-part-2%2F</feedburner:awareness><feedburner:origLink>http://www.cssnewbie.com/jquery-popout-ad-part-2/</feedburner:origLink></item>
		<item>
		<title>jQuery-Based Popout Ad: Part 1</title>
		<link>http://feeds.feedburner.com/~r/cssnewbie/~3/388248371/</link>
		<comments>http://www.cssnewbie.com/jquery-popout-ad-part-1/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 02:59:52 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Advanced Techniques]]></category>

		<category><![CDATA[Floats and Positioning]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[overflow]]></category>

		<category><![CDATA[positioning]]></category>

		<category><![CDATA[z-index]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=222</guid>
		<description><![CDATA[Advertisements on the web: love them or hate them, it's safe to say they're here to stay for a good long while. But advertising is a tough line to walk for a lot of websites (such as this one). Make your ads too annoying, and you'll lose readership. But make them too unobtrusive, and you might as well not even have them at all. Today I'd like to start an article series of three parts, the result of which will be a popout-style, jQuery-based box like the one pictured above, which I think strikes a nice balance on the obtrusion-scale. ]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.cssnewbie.com/example/popout-ad/'><img src="http://www.cssnewbie.com/wp-content/uploads/2008/09/popout.jpg" alt="" title="jquery-based popout ad" width="400" height="275" class="alignnone size-full wp-image-223" /></a></p>
<p>Advertisements on the web: love them or hate them, it&#8217;s safe to say they&#8217;re here to stay for a good long while. But advertising is a tough line to walk for a lot of websites (such as this one). Make your ads too annoying, and you&#8217;ll lose readership. But make them too unobtrusive, and you might as well not even have them at all. So where&#8217;s the balance?</p>
<p>Today I&#8217;d like to start an article series of three parts, the result of which will be a popout-style, jQuery-based box like the one pictured above, which I think strikes a nice balance on the obtrusion-scale. <a href="http://www.crawlspacemedia.com/">A friend of mine</a> and I first developed this box to contain advertisements, but it&#8217;s a pretty versatile little technique: we&#8217;ve also used it to hold signup forms, and it could be expanded to other uses fairly easily.<br />
<a href="http://www.cssnewbie.com/example/popout-ad/"><br />
If you&#8217;d like to see this popout ad in action, click here.</a></p>
<p>So what&#8217;s the benefit of this little popout box? First of all, it&#8217;s pretty simple to set up. In today&#8217;s article, I&#8217;ll cover the XHTML and CSS necessary to build this popout box, and you&#8217;ll see that it doesn&#8217;t take as much code as you might expect. </p>
<p>Second, it&#8217;s an eye-catching, yet not entirely annoying, technique. The ad opens after the page loads, which tends to draw the reader&#8217;s eye that direction. But if the ad isn&#8217;t for them, they can just click the close button and move it out of the way. Part 2 of this series will cover the jQuery used to make the ad function as prescribed.</p>
<p>Third, the technique easy to customize for your specific needs. In part 3 of this series, I&#8217;ll cover adding cookie support (to remember whether the ad should be open or closed) using a great jQuery plugin, generalizing your CSS to support both left- and right-aligned boxes with just one stylesheet, and even supporting multiple ads on the same page, should you decide to push the envelope.</p>
<p>Intrigued? Great! Let&#8217;s dive in to part 1.</p>
<h5>The Images Required</h5>
<p><img src="http://www.cssnewbie.com/wp-content/uploads/2008/09/our-images.jpg" alt="" title="our jquery popout ad images" width="400" height="350" class="alignnone size-full wp-image-224" /></p>
<p>Depending on how you&#8217;re using the box, you&#8217;ll need some images. For mine, I&#8217;m using two images. The first image functions as the ad &#8220;cap,&#8221; which is permanently affixed to the side of the page. Clicking this image will, once we&#8217;ve added our jQuery, cause the ad itself to open and close. </p>
<p>The second image is simply for the advertisement itself. Depending on your ad source and type, this image may or may not be necessary. If you&#8217;d like to follow along at home, <a href="http://www.cssnewbie.com/example/popout-ad/popout-ad-images.zip">you can download the image files I&#8217;m using here (Photoshop files and GIF/PNG images included).</a></p>
<h5>Writing the XHTML</h5>
<p>The XHTML is fairly simple, only requiring a few divs, images, and anchors:</p>
<pre class="html">&lt;div id=&quot;popout&quot;&gt;
	&lt;div id=&quot;cap&quot;&gt;
		&lt;a href=&quot;#&quot; id=&quot;open&quot;&gt;
			&lt;img src=&quot;images/cap.gif&quot; width=&quot;20&quot; height=&quot;350&quot; alt=&quot;Open the Ad.&quot; /&gt;
		&lt;/a&gt;
	&lt;/div&gt;
	&lt;div id=&quot;adbox&quot;&gt;
		&lt;a href=&quot;#&quot; id=&quot;close&quot; title=&quot;Close this ad.&quot;&gt;
			&lt;span&gt;Close&lt;/span&gt;
		&lt;/a&gt;
		&lt;a href=&quot;#&quot; id=&quot;ad&quot;&gt;
			&lt;img src=&quot;images/ad.png&quot; width=&quot;300&quot; height=&quot;330&quot; alt=&quot;&quot; /&gt;
		&lt;/a&gt;
	&lt;/div&gt;
&lt;/div&gt;</pre>
<p>The main div, &#8220;popout,&#8221; acts as a wrapper for the whole shebang. It contains all the other elements, and comes in handy when writing our jQuery and our CSS.</p>
<p>Next up comes the &#8220;cap&#8221; div. Technically, this div isn&#8217;t even 100% necessary &mdash; you could just as easily attach your CSS and jQuery scripts to the anchor tag it contains. But I find it&#8217;s useful to think of the cap as a wholly distinct unit from the advertisement, so I&#8217;ve put it in a separate div to help me think of it as such.</p>
<p>Inside the cap div is an anchor, &#8220;open,&#8221; which in turn contains the image of our cap. The anchor tag serves a critical role: it&#8217;s what we use in our jQuery later on to trigger the opening and closing of the ad.</p>
<p>After the cap comes the &#8220;adbox&#8221; div, which contains the real guts of our popout ad. First up is the &#8220;close&#8221; anchor, which functions as a close box. As you can see from the image above, I&#8217;ve built a close box into my ad itself: if you preferred, you could make the close button a standalone image and absolutely position it over your ad&#8230; but for the sake of simplicity in this tutorial, I&#8217;ve chosen not to here.</p>
<p>And finally, we have the &#8220;ad&#8221; anchor, which contains the advertisement itself. I can get away with just an anchor and an image because I&#8217;ve developed this ad myself, and am hosting it locally. If you were using a different ad type, such as one that were pulled in dynamically using JavaScript or the like, you&#8217;d put that code here instead (probably wrapped in a div to keep it contained).</p>
<p>And that&#8217;s all the XHTML you&#8217;ll need! So let&#8217;s move on to the CSS.</p>
<h5>Adding the CSS</h5>
<p>The first thing we need to do is establish our containing popout div on the page:</p>
<pre class="css">#popout {
	margin: 0;
	padding: 0;
	width: 320px;
	height: 350px;
	position: absolute;
	top: 200px;
	left: 0;
	z-index: 100;
	overflow: hidden; }</pre>
<p>The first couple of rules simply nullify any margins or padding that might be hanging around in other places in your CSS: the last thing we need is a rogue rule crimping our style. If you&#8217;re sure none exist, you can eliminate those lines.</p>
<p>Our width and height rules are pretty simple: they state the height of the ad (which in our case is actually the height of the cap, as our ad is slightly shorter) and the maximum width the ad will take up (when the ad is closed, it takes up much less space).</p>
<p>Next up, we&#8217;re positioning the ad on the page. These rules are useful for two reasons. First, it allows us to position the ad wherever we want on the page. I&#8217;ve chosen to start the ad 200 pixels down on the left hand side, but you can really place it wherever you want. Second, positioning the popout wrapper allows us to <a href="http://www.cssnewbie.com/harnessing-positioning-1/" title="Harnessing CSS Positioning">absolutely position elements within that wrapper,</a> which will come in handy shortly.</p>
<p>We finish up with two less common rules: z-index and overflow. The z-index is helping to ensure our ad is on top of any other content on your page: elements with a lower z-index (1 is the default) will show up below our wrapper. The overflow rule doesn&#8217;t do a lot for us initially, but is critical for our jQuery to do its magic. We&#8217;ll cover that in part 2.</p>
<p>With our popout wrapper in place, we can start styling its innards, starting with some general rules:</p>
<pre class="css">#popout a, #popout a img {
	text-decoration: none;
	border: 0;
	outline: 0; }
#popout a span {
	display: none; }</pre>
<p>The first set of rules ensures that none of our anchors or images have any borders, outlines, or underlines from our anchors and the images they contain. Normally you wouldn&#8217;t want to eliminate any sign that something had been or could be clicked, but because this is an advertisement we&#8217;re building, I think we&#8217;re allowed to bend the rules of usability for the sake of aesthetics. If you disagree, feel free to remove that rule.</p>
<p>Next up, we&#8217;re setting a general rule that comes in handy for me: any span within anchor tags will be magically disappeared. In our example, this only pertains to the &#8220;Close&#8221; text inside its corresponding anchor, but in theory you could have more text in your popout wrapper that you&#8217;d want to hide. For example, when building these ads I often load the cap image as a background image and have text inside of the anchor.</p>
<p>With the generalities out of the way, let&#8217;s start in on specifics, starting with the cap:</p>
<pre class="css">#popout #cap {
	width: 20px;
	height: 350px;
	position: relative;
	left: 0;
	z-index: 102; }</pre>
<p>Pretty basic stuff, huh? We&#8217;re setting a width and height first, which just ensures our div doesn&#8217;t take up any more space than is necessary. Then, we relatively position the ad. This is mostly done so that we can specify a z-index. Our z-index here says that we want it to be even higher than the popout ad; and you&#8217;ll see why shortly.</p>
<p>Next up, we position our close button:</p>
<pre class="css">#popout a#close {
	position: absolute;
	top: 0;
	background: transparent url(transparent.gif);
	left: 240px;
	height: 20px;
	width: 60px; }</pre>
<p>Here, we&#8217;re absolutely positioning the close button in the top-right corner of our popout wrapper div. If you&#8217;ll recall, the top-right corner is where I&#8217;d placed the close button in our image. This just ensures the close button is in the right spot, even though its contents were rendered invisible by that previous display:none rule. But you&#8217;ll notice that I&#8217;m using the &#8220;left&#8221; property to <em>push</em> our button right, instead of just positioning against the right-hand side with the &#8220;right&#8221; property. This is to take into account a bug in Opera that causes our close button to be positioned improperly when aligned along the right-hand side of our animated box (you can <a href="http://www.cssnewbie.com/jquery-popout-ad-part-2/#comment-8417">read all the juicy details in the comment thread of part 2 of this series</a>)</p>
<p>I&#8217;m also specifying a height and width &mdash; be sure to adjust yours to the size of your close button. Technically you could use a percentage or em value for the width, but I&#8217;m using pixels to make the math involved in pushing it from the left easier.</p>
<p>I&#8217;ve also added a fix to the CSS above to take care of an Internet Explorer bug. IE shrinks the clickable area of an anchor tag to be the size of its content, even if we&#8217;ve specified a width and height that gives the anchor a different size. Because we are hiding the content of this anchor using a &#8220;display: none&#8221; rule, this means the anchor is effectively unclickable in Internet Explorer. However, IE does recognize the size of the link if it&#8217;s filled with a background image. Thus, by adding a transparent background image to our anchor (I&#8217;m using a 1&#215;1 pixel transparent gif), the size and shape of the anchor is respected.</p>
<p>And finally, we&#8217;re ready to position our advertisement itself:</p>
<pre class="css">#popout #adbox {
	position: absolute;
	top: 10px;
	left: 20px;
	z-index: 101; }</pre>
<p>Our position of absolute allows us to move the ad right into position: 10 pixels from the top of the popout wrapper (because my ad is 20 pixels shorter than the cap, this centers it nicely) and 20 pixels from the left (which happens to be the exact width of the cap). And finally, we&#8217;ve set a z-index of 101, which is 1 less that the z-index of our cap. This means that our cap is &#8220;above&#8221; our ad &mdash; when we use jQuery to animate the ad in part 2, this will come in handy, allowing us to slip the ad behind the cap.</p>
<p>And that brings us to the end of part 1. <a href="http://www.cssnewbie.com/example/popout-ad/part1.html">You can see the results of our efforts (without any jQuery magic) here.</a> Stay tuned for parts 2 and 3, when things really start to get fun!</p>
<p><strong>Note:</strong> <a href="http://www.cssnewbie.com/jquery-popout-ad-part-2/">Part 2 of this series is now available here.</a> And when you&#8217;re ready, <a href="http://www.cssnewbie.com/jquery-popout-ad-part-3/">part 3 is available here.</a></p>

<p><a href="http://feeds.feedburner.com/~a/cssnewbie?a=F2LThB"><img src="http://feeds.feedburner.com/~a/cssnewbie?i=F2LThB" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/cssnewbie?a=qfZtL"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=qfZtL" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=twV0l"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=twV0l" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=s91Zl"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=s91Zl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=29eml"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=29eml" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=BMHnL"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=BMHnL" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=7p8yl"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=7p8yl" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/388248371" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/jquery-popout-ad-part-1/feed/</wfw:commentRss>
		<feedburner:awareness>http://api.feedburner.com/awareness/1.0/GetItemData?uri=cssnewbie&amp;itemurl=http%3A%2F%2Fwww.cssnewbie.com%2Fjquery-popout-ad-part-1%2F</feedburner:awareness><feedburner:origLink>http://www.cssnewbie.com/jquery-popout-ad-part-1/</feedburner:origLink></item>
		<item>
		<title>CSSnewbie Subscriber Contest Winner Announced</title>
		<link>http://feeds.feedburner.com/~r/cssnewbie/~3/381890714/</link>
		<comments>http://www.cssnewbie.com/cssnewbie-subscriber-contest-winner-announced/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 01:48:54 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Site News]]></category>

		<category><![CDATA[announcement]]></category>

		<category><![CDATA[contest]]></category>

		<category><![CDATA[winner]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=220</guid>
		<description><![CDATA[It's been a great, if absurdly busy, August for me, and I hope the same can be said for you. But all good things (including the month of August) must come to an end, and so to ends the <a href="http://www.cssnewbie.com/cssnewbie-subscriber-contest/">CSSnewbie Subscriber Contest.</a>]]></description>
			<content:encoded><![CDATA[<p><a href='http://flickr.com/photos/ohadby/175144072/'><img src="http://www.cssnewbie.com/wp-content/uploads/2008/09/racing.jpg" alt="" title="Photo by Ohad. Used under a Creative Commons license." width="400" height="247" class="alignnone size-full wp-image-221" /></a></p>
<p>It&#8217;s been a great, if absurdly busy, August for me, and I hope the same can be said for you. But all good things (including the month of August) must come to an end, and so to ends the <a href="http://www.cssnewbie.com/cssnewbie-subscriber-contest/">CSSnewbie Subscriber Contest.</a></p>
<p>The contest has ended, and a winner has been selected by the true random integer generator at <a href="http://www.random.org/">random.org.</a> Each contestant was assigned a number based on the order in which I received their email (see &mdash; you&#8217;re more than an email address to me! You&#8217;re a number as well!), and a number was chosen randomly from that total.</p>
<p><strong>The winner of the subscriber contest</strong> is Italy&#8217;s own <a href="http://www.matteomoro.net/">Matteo Moro,</a> who writes on <a href="http://cssblog.it/">CSSblog.it.</a> Matteo will be receiving a copy of <a href="http://www.amazon.com/exec/obidos/ASIN/0596515057/cssnewbie-20">Eric Meyer&#8217;s <em>CSS Pocket Reference</em></a> as well as a website review here on CSSnewbie (date/type to be determined).</p>
<p>Thanks to all of you who entered CSSnewbie&#8217;s first-ever contest. I had a lot of fun reading the quips everyone tended to include in the emails they sent me &mdash; it made me check my contest inbox probably more than was necessary. The success of this contest suggests that I might hold another in the future&#8230; as soon as I come up with something new worth celebrating. August only comes around once a year, sadly.</p>
<p>If  you have any feedback on this contest, or on any future contests I might hold, feel free to either email me or leave a comment on this article. I&#8217;d love to hear what you have to say.</p>
<p>To all those who didn&#8217;t win: thanks for playing, thanks even more for reading, and I hope you stick around! I have more great articles lined up for September, including my first multi-part tutorial, which will combine elements of XHTML, CSS and JavaScript to great effect. Stay tuned!</p>

<p><a href="http://feeds.feedburner.com/~a/cssnewbie?a=ZFsdOn"><img src="http://feeds.feedburner.com/~a/cssnewbie?i=ZFsdOn" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/cssnewbie?a=HMhxtL"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=HMhxtL" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=jrWiel"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=jrWiel" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=1bmLWl"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=1bmLWl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=fxqwdl"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=fxqwdl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=3JNu4L"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=3JNu4L" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=Qb7zkl"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=Qb7zkl" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/381890714" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/cssnewbie-subscriber-contest-winner-announced/feed/</wfw:commentRss>
		<feedburner:awareness>http://api.feedburner.com/awareness/1.0/GetItemData?uri=cssnewbie&amp;itemurl=http%3A%2F%2Fwww.cssnewbie.com%2Fcssnewbie-subscriber-contest-winner-announced%2F</feedburner:awareness><feedburner:origLink>http://www.cssnewbie.com/cssnewbie-subscriber-contest-winner-announced/</feedburner:origLink></item>
		<item>
		<title>5 Great Uses for the CSS Display Property</title>
		<link>http://feeds.feedburner.com/~r/cssnewbie/~3/369392663/</link>
		<comments>http://www.cssnewbie.com/5-great-uses-for-the-css-display-property/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 22:01:04 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Basic Techniques]]></category>

		<category><![CDATA[Quick Tip]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=219</guid>
		<description><![CDATA[Despite the display property's seemingly limited use, you'd be surprised how many CSS techniques rely on this little workhorse to get the job done. Here are five CSS techniques I've written about in the past that wouldn't exist without the help of the display property.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cssnewbie.com/horizontal-dropdown-menus/"><img src="http://www.cssnewbie.com/wp-content/uploads/2008/05/horizontalmenu-400.gif" alt="" border="0" /></a></p>
<p>The display property is a bit of an unheralded workhorse in the CSS world. Even though <a href="http://www.w3schools.com/css/pr_class_display.asp">the list of theoretical display property values</a> is quite long, only three of them ever see any use (primarily due to poor browser support on the others): inline, block, and none. </p>
<p>The inline value allows you to define an element to behave as though it were an inline element (like a span or an anchor tag). Conversely, the block value lets you force block-level behavior (like a div or a paragraph). And &ldquo;display: none&rdquo; simply causes an element to not display at all.</p>
<p>But despite the display property&#8217;s seemingly limited use, you&#8217;d be surprised how many CSS techniques rely on this little workhorse to get the job done. Here are five CSS techniques I&#8217;ve written about in the past that wouldn&#8217;t exist without the help of the display property.</p>
<h5>Showing/Hiding Content</h5>
<p><a href="http://www.cssnewbie.com/showhide-content-css-javascript/"><img src="http://www.cssnewbie.com/wp-content/uploads/2008/05/showhide-400.gif" alt="" /></a></p>
<p>One popular technique that relies on the display property is the <a href="http://www.cssnewbie.com/showhide-content-css-javascript/">Show/Hide Content technique (explained in much greater detail here)</a>, which uses CSS and JavaScript to show or hide additional content when the users clicks on a button.  The ability to &ldquo;hide&rdquo; content on a page is a cornerstone of the modern web: too many options at once leaves a user feeling overwhelmed, but too few options can leave your audience feeling constrained. This technique allows you to get the best of both worlds.</p>
<h5>Making Closeable DIVs</h5>
<p><a href="http://www.cssnewbie.com/message-box-javascript-css/"><img src="http://www.cssnewbie.com/wp-content/uploads/2008/04/messagebox-400.gif"/ alt=""></a></p>
<p>In-document message boxes can be quite useful when used for the powers of good &mdash; and not, say, to create annoying pop-in ads right in the middle of a page you&#8217;re trying to read. Luckily, whether used for good or evil, most all in-document popups come with a &ldquo;close&rdquo; option: and that close option is almost always the work of the &ldquo;display: none&rdquo; rule. <a href="http://www.cssnewbie.com/message-box-javascript-css/">Learn more about creating in-document message boxes here.</a></p>
<h5>Creating RSS-Only Content</h5>
<p><a href="http://www.cssnewbie.com/hiding-content-in-your-rss-feed/"><img src="http://www.cssnewbie.com/wp-content/uploads/2008/07/rssfeed.gif" alt="" /></a></p>
<p>As I wrote about in a recent article, <a href="http://www.cssnewbie.com/hiding-content-in-your-rss-feed/">hiding content in your RSS feed</a> doesn&#8217;t have to require a fancy plug-in &mdash; which is good for people who aren&#8217;t relying on a fancy content management system to generate their pages. Instead, producing RSS-only content can be as simple as hiding your content in your page with the display property &mdash; which is then ignored when picked up by RSS feed readers.</p>
<h5>Building Dropdown Menus</h5>
<p><a href="http://www.cssnewbie.com/easy-css-dropdown-menus/"><img src="http://www.cssnewbie.com/wp-content/uploads/2008/05/dropdown-400.gif" alt="" /></a></p>
<p>Without the CSS display property, fancy dropdown menus would be limited to the realm of JavaScript. However, by combining CSS&#8217;s display property and the :hover pseudo-class, you can create beautiful dropdown menus without a single line of JavaScript. Want to learn how? <a href="http://www.cssnewbie.com/easy-css-dropdown-menus/">Here&#8217;s a tutorial on creating easy CSS dropdown menus,</a> and <a href="http://www.cssnewbie.com/horizontal-dropdown-menus/">here&#8217;s a second tutorial on creating special horizontal dropdowns.</a></p>
<h5>Fixing Bugs</h5>
<p><a href="http://www.cssnewbie.com/double-margin-float-bug/"><img src="http://www.cssnewbie.com/wp-content/uploads/2008/06/doublemargin-400.gif" alt="" /></a></p>
<p>If you work on web development long enough, sooner or later some browser is going to throw a bug your way (Internet Explorer 6, I&#8217;m looking at you). But just because there&#8217;s a bug in the browser doesn&#8217;t mean that the fix has to be complicated. In fact, two of the most common Internet Explorer bugs out there &mdash; <a href="http://www.cssnewbie.com/fixing-ie6-whitespace-bug/">the IE6 Whitespace Bug</a> and <a href="http://www.cssnewbie.com/double-margin-float-bug/">the IE Double Margin Float Bug</a> &mdash; both use the &ldquo;display: inline&rdquo; property to make IE behave properly. Click the bug names for more in-depth information. </p>
<p>So when you get right down to it, the display property is a pretty useful little guy, even if only three of its values are supported. Just imagine how prolific it&#8217;d be if all its values were available!</p>

<p><a href="http://feeds.feedburner.com/~a/cssnewbie?a=qh2Fga"><img src="http://feeds.feedburner.com/~a/cssnewbie?i=qh2Fga" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/cssnewbie?a=b1yoEK"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=b1yoEK" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=RcjEMk"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=RcjEMk" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=8yKlik"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=8yKlik" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=EyCMfk"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=EyCMfk" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=5C99WK"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=5C99WK" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=otz4lk"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=otz4lk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/369392663" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/5-great-uses-for-the-css-display-property/feed/</wfw:commentRss>
		<feedburner:awareness>http://api.feedburner.com/awareness/1.0/GetItemData?uri=cssnewbie&amp;itemurl=http%3A%2F%2Fwww.cssnewbie.com%2F5-great-uses-for-the-css-display-property%2F</feedburner:awareness><feedburner:origLink>http://www.cssnewbie.com/5-great-uses-for-the-css-display-property/</feedburner:origLink></item>
	<feedburner:awareness>http://api.feedburner.com/awareness/1.0/GetFeedData?uri=cssnewbie</feedburner:awareness></channel>
</rss>
