<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
   <title>Ask the CSS Guy</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/" />
   <link rel="self" type="application/atom+xml" href="http://www.askthecssguy.com/atom.xml" />
   <id>tag:www.askthecssguy.com,2008://1</id>
   <updated>2008-09-13T02:54:48Z</updated>
   <subtitle>Providing CSS assistance and tutorials to whoever asks - askthecssguy@gmail.com</subtitle>
   <generator uri="http://www.sixapart.com/movabletype/">Movable Type 3.33</generator>

<entry>
   <title>Pardon the mess</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/2008/09/pardon_the_mess.html" />
   <id>tag:www.askthecssguy.com,2008://1.53</id>
   
   <published>2008-09-04T19:39:51Z</published>
   <updated>2008-09-13T02:54:48Z</updated>
   
   <summary>I&apos;m gutting some movable type html, and along with that, I&apos;ll need to rebuild the CSS file as well. If you keep seeing fresh articles in your feed reader, this is why. This will take a few days. Sep 12,...</summary>
   <author>
      <name></name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://www.askthecssguy.com/">
      <![CDATA[<p>I'm gutting some movable type html, and along with that, I'll need to rebuild the CSS file as well.  If you keep seeing fresh articles in your feed reader, this is why.  This will take a few days.</p>

<div class="updates">
<p><strong>Sep 12, 2008:</strong> I suppose it could be considered subjective, but the 'mess' has been straightened up.  I still have some entries to edit to bring up to column standards (why didn't I do this sooner?), but things are falling into place, and I'm learning plenty in the process.  I've got a vacation coming up, but hope to get some articles currently in the works on the site soon after my return.</p>
</div>]]>
      
   </content>
</entry>
<entry>
   <title>A page curling tip</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/2008/08/a_page_curling_tip.html" />
   <id>tag:www.askthecssguy.com,2008://1.52</id>
   
   <published>2008-08-22T00:24:52Z</published>
   <updated>2008-09-10T23:51:19Z</updated>
   
   <summary>Some have asked how to do the page curl effect for the figures in the article I wrote for Smashing Magazine, which included figures with page curls. The answer is Veerle&apos;s tutorial. There is one extra tip I&apos;d like to...</summary>
   <author>
      <name></name>
      
   </author>
         <category term="popcorn" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.askthecssguy.com/">
      <![CDATA[<p>Some have asked how to do the page curl effect for the figures in the <a href="http://www.smashingmagazine.com/2008/08/18/7-principles-of-clean-and-optimized-css-code/">article I wrote for Smashing Magazine</a>, which included figures with page curls.</p>

<p>The answer is <a href="http://veerle.duoh.com/blog/comments/creating_a_page_curl_in_photoshop/">Veerle's tutorial</a>.</p>

<p>There is one extra tip I'd like to offer.</p>

<p>In Step 2 of Veerle's directions, she states the following:</p>

<blockquote><p>"Since this curl doesn't show the back of our photo, it doesn't really look realistic. The only way I'm aware of to achieve this effect is that <em>we draw it ourself</em>. Select the Pen tool from the Toolbox and draw a path on top of the picture. <em>Follow the borders of the curl you just transformed as guidance</em>. ..."</p></blockquote>

<p>Emphasis mine.</p>

<p>Tracing the curl with the Pen tool can be difficult when the contrast between the curled edge and the 'facing' edge of the photo is too faint.  For instance, if you went through the tutorial with a blank beige square, your progress as you get to step 2 may look like this:</p>

<p>Stage 1: Drawing the marquee</p>
<p><img src="http://askthecssguy.com/images/080821_fig1.gif" alt="" /></p>

<p>Stage 2:  Select to warp</p>
<p><img src="http://askthecssguy.com/images/080821_fig2.gif" alt="" /></p>

<p>Stage 3:  Drag the corner</p>
<p><img src="http://askthecssguy.com/images/080821_fig3.gif" alt="" /></p>

<p>Stage 4: Hit enter</p>
<p><img src="http://askthecssguy.com/images/080821_fig4.gif" alt="" /></p>

<p>Uh-oh!  Now what do we trace to make the curl? You can make it up if you're so inclined, but if you want a guide to trace, do the following:</p>

<ol>
<li>Take a screen grab just <em>before you hit enter</em>.</li>
<li>Press enter to commit your warp.</li>
<li>Paste in your screen grab over your working page layer.</li>
<li>Change the opacitiy of the screen grab layer so you can line it up with the layer underneath.</li>
<li>Now you should have guides to draw your curl.</li>
</ol>

<p><img src="http://askthecssguy.com/images/080821_fig5.gif" alt="" /></p>

<p>Once you've drawn your curl with the pen tool, you can trash the layer and go about the other steps in Veerle's tutorial to finish out the effect.</p>]]>
      
   </content>
</entry>
<entry>
   <title>Adding classes to input tags as a matter of course</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/2008/07/adding_classes_to_input_tags_a.html" />
   <id>tag:www.askthecssguy.com,2008://1.51</id>
   
   <published>2008-07-09T21:21:42Z</published>
   <updated>2008-09-11T04:52:32Z</updated>
   
   <summary><![CDATA[I felt like sharing a practice that I've been doing for a while now when marking up form elements. I always assign a class to every input that is the same to the input's type. &lt;input type="text" class="text" /&gt; &lt;input...]]></summary>
   <author>
      <name></name>
      
   </author>
         <category term="ringmaster" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.askthecssguy.com/">
      <![CDATA[<p>I felt like sharing a practice that I've been doing for a while now when marking up form elements.</p>

<p>I always assign a class to every input that is the same to the input's type.</p>

<pre><code>&lt;input
  type="text"
  class="text" /&gt;

&lt;input
  type="checkbox"
  class="checkbox" /&gt;

&lt;input
  type="radio"
  class="radio" /&gt;

&lt;input
  type="button"
  class="button" /&gt;</code></pre>

<p>For input types that would be similar in presentation, I double up:</p>

<pre><code>&lt;input
  type="submit"
  class="submit button" /&gt;

&lt;input
  type="password"
  class="password text" /&gt;</code></pre>


<p>It's not uncommon for a project to require specified padding, width, and border colors for text inputs.  I don't want to target all input tags, as it could have some unintended consequences for elements I don't want changed.  So this practice has helped me greatly.  Its html file size impact is miniscule, and it's also easy to remember, since the type value is always the class value.</p>

<h3>Attribute selectors vs. class names</h3>
<p>Attribute selectors almost remove the need for me to do this, but not quite.  By attribute selectors, I mean the following:</p>

<pre><code>input[type="text"] { border:1px solid #000; }</code></pre>

<p>... in which the value of the 'type' attribute is used instead of a class or id.</p>

<p>The main reason attribute selectors don't do the trick is that IE6 doesn't support them.  And though I can be persuaded to let a little IE6 wonkiness slip through for some parts of web site projects, forms are where I draw the line.  After all, forms are how get feedback and money from customers - why screw with that?</p>

<p>The secondary reason can be found from the password input example above.  I want password inputs to inherit the same presentational treatment as text inputs.  Using the class names defined above lets me do that.</p>

<p>For me, this practice has proven pretty effective.  Your mileage may vary, but I'd love to hear any other tips you have in mind.</p>



<p>See also:</p>
<ul>
<li>Eric Meyer's <a href="http://meyerweb.com/eric/thoughts/2007/05/15/formal-weirdness/">Formal Wierdness</a></li>
<li>Roger Johansson's <a href="http://www.456bereastreet.com/archive/200705/why_styling_form_controls_with_css_is_problematic/
">Why styling form controls with CSS is problematic</a></li>
</ul>]]>
      
   </content>
</entry>
<entry>
   <title>Kotatsu - a simple html table generator</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/2008/04/kotatsu_a_simple_html_table_ge.html" />
   <id>tag:www.askthecssguy.com,2008://1.50</id>
   
   <published>2008-04-25T17:05:54Z</published>
   <updated>2008-09-10T23:51:22Z</updated>
   
   <summary>It&apos;s been a long time since I&apos;ve used Dreamweaver for web development. I only find myself missing it when I need to create a table, especially when I want to have all cells in a particular column have a class....</summary>
   <author>
      <name></name>
      
   </author>
         <category term="tiger" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.askthecssguy.com/">
      <![CDATA[<p>It's been a long time since I've used Dreamweaver for web development.  I only find myself missing it when I need to create a table, especially when I want to have all cells in a particular column have a class.  (I'm well aware of <code>&lt;colgroup&gt;</code>, I just don't subscribe.)</p>

<p>So I created a tool to help create a table and throw in column classes quickly.  I gave it a name so I can put it out there and let others use it, too.</p>

<p>It's called <a href="/kotatsu/index.html">kotatsu</a>.</p>]]>
      
   </content>
</entry>
<entry>
   <title>Prasun asks the CSS Guy how to switch the &quot;on&quot; state of navigation links for dynamic pages</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/2008/04/prasun_asks_the_css_guy_how_to_1.html" />
   <id>tag:www.askthecssguy.com,2008://1.49</id>
   
   <published>2008-04-21T19:26:26Z</published>
   <updated>2008-09-11T04:53:40Z</updated>
   
   <summary>Prasun writes: I have a list of links in an unordered list. What I want is that when I click a list item, its color should change, and when I click some other list item, the color of the item...</summary>
   <author>
      <name></name>
      
   </author>
         <category term="popcorn" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.askthecssguy.com/">
      <![CDATA[<p>Prasun writes:</p>

<blockquote>
<p>I have a list of links in an unordered list. What I want is that when I click a list item, its color should change, and when I click some other list item, the color of the item which I clicked previously should return to its original state.</p>

<p>Can you help me in this regard?</p>
</blockquote>

<p>Yes, I can help.</p>

<p>More advanced readers, move along.  This is JavaScript beginner territory, but this is one of those steps that is really rich in DOM scripting nutrients, so I'm very pleased to discuss it.</p>

<p>What Prasun is describing, just by itself, is the behavior of a set of radio buttons.  You click one, and it takes on the selected state.  Then you click on another one, and the new one now becomes selected, while the previous one returns to an unselected state.</p>

<p>But radio buttons are form elements, not navigational elements, and upon clarifying with Prasun, it's navigation that we're after.</p>

<p>This is the fundamental behavior of a site that uses ajax for navigation or tabs, where each "page" is created by loading new content into the content section of the current page.</p>

<p>This is a relatively easy way to get your feet wet with DOM scripting.  So I'll first show how to do it with some very basic JavaScript functions.  Also, I'll show how to do it with jQuery.</p>

<h3>First, the HTML</h3>
<p>Let's start with an unordered list of links.</p>
<pre><code>&lt;ul&gt;
  &lt;li&gt;&lt;a href="#"&gt;Heartbreak Hotel&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#"&gt;Blue Suede Shoes&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#"&gt;Hound Dog&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#"&gt;Don't Be Cruel&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#"&gt;Teddy Bear&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>

<p>See <a href="/examples/prasun/example1.html">example 1</a>.</p>

<p>Who are we kidding?  Let's see it with some basic styling - <a href="/examples/prasun/example2.html">example 2</a>.</p>

<p>Since we're going to be changing around selected links, let's establish what a selected state looks like, and mark one item as selected by default.  I'm going to do this by applying <code>class="selected"</code> to one of the links.</p>

<pre><code>&lt;ul&gt;
  &lt;li&gt;&lt;a href="#"&gt;Heartbreak Hotel&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#"&gt;Blue Suede Shoes&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#" <strong>class="selected"</strong>&gt;Hound Dog&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#"&gt;Don't Be Cruel&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#"&gt;Teddy Bear&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>

<p>See <a href="/examples/prasun/example3.html">example 3</a>.</p>

<h3>The JavaScript</h3>

<p>Here's what we want to do in English.  When someone clicks a link, remove class="selected" from any of the other links, and assign it to this one.</p>

<p>Another way to say that is "When someone clicks a link, run a function" and later I can be more specific about what that function is.  Here's how I'll put that statement in the html.</p>

<pre><code>&lt;ul&gt;
  &lt;li&gt;&lt;a <strong>onclick="applySelectedTo(this);"</strong> href="#"&gt;Heartbreak Hotel&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a <strong>onclick="applySelectedTo(this);"</strong> href="#"&gt;Blue Suede Shoes&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a <strong>onclick="applySelectedTo(this);"</strong> href="#" class="selected"&gt;Hound Dog&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a <strong>onclick="applySelectedTo(this);"</strong> href="#"&gt;Don't Be Cruel&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a <strong>onclick="applySelectedTo(this);"</strong> href="#"&gt;Teddy Bear&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>

<p>The "this" mentioned in the parentheses refers to the link that is being clicked.  I'm thinking ahead here - I know that I'll want to do something with the link being clicked (assign it class="selected"), so I'm going to go ahead and pass that link as a <em>parameter</em> to the function.  The term <em>this</em> is great for that sort of thing.</p>

<p>The function will be called "applySelectedTo()", and I'll write it in just a second.  It's going to do exactly what it says it will do: Apply class="selected" to whatever link is given to it.  It will also live in head of the document.</p>

<p>Notice that in the html, I'm passing the parameter <em>this</em>.  And when I write the function, I'm using a made up term to help tell me what <em>this</em> was - the word <em>link</em>.</p>

<pre><code>&lt;script type="text/javascript"&gt;
function applySelectedTo(link) {
  link.className = "selected";
}
&lt;/script&gt;</code></pre>

<p>Check out <a href="/examples/prasun/example4.html">Example 4</a> to see it in action.</p>

<h3>Oh, but we're not done</h3>

<p>All that JavaScript function did was add class="selected" to the new link.  It didn't remove class="selected" from previously selected links.  We need to fix that.  Also, when we click a link, it adds the hash mark (#) to our url, and if our page were really long, it would jump to the top of the page again.</p>

<p>We'll tackle the second problem first.  That hash mark is telling me something: it's indicating that the link is behaving like a link is supposed to behave.  That behavior normally means that it will find the <code>id</code> of whatever I specified after the hash mark and the browser will bring that part of the page in focus.  But in this case, we would rather ignore the default behavior of the link, so I'm going to tell my links to ignore their default behavior when clicked.</p>

<pre><code>&lt;ul&gt;
  &lt;li&gt;&lt;a onclick="applySelectedTo(this);<strong>return false;</strong>" href="#"&gt;Heartbreak Hotel&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a onclick="applySelectedTo(this);<strong>return false;</strong>" href="#"&gt;Blue Suede Shoes&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a onclick="applySelectedTo(this);<strong>return false;</strong>" href="#" class="selected"&gt;Hound Dog&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a onclick="applySelectedTo(this);<strong>return false;</strong>" href="#"&gt;Don't Be Cruel&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a onclick="applySelectedTo(this);<strong>return false;</strong>" href="#"&gt;Teddy Bear&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>

<p><a href="/examples/prasun/example5.html">Example 5</a></p>

<p>And back to the first problem - removing class="selected" from other links when a new link is selected.  How do we get the link that already has class="selected", and remove the class?  Well, to make it easy, I'm just going to say remove class="selected" from <strong>all</strong> links, <em>then</em> I'll add class="selected" to the one just clicked.</p>

<pre><code>&lt;script type="text/javascript"&gt;
function applySelectedTo(link) {
  <strong>var ul = document.getElementsByTagName("ul")[0];
  var allLinks = ul.getElementsByTagName("a");
  for (var i=0; i&lt;allLinks.length; i++) { 
    allLinks[i].className = ""; 
  }</strong>
  link.className = "selected"; 
}
&lt;/script&gt;</code></pre>

<p>And so there you have it, <a href="/examples/prasun/example6.html">Example 6 - final example</a>.</p>

<p>And if you're so inclined, <a href="/examples/prasun/example7.html">make it do something</a>.</p>

<h3>We could go much further</h3>

<p>Ideally, you wouldn't even have an onclick attribute in the markup.  That kind of thing can be inserted dynamically using more DOM scripting.  It makes your html lots more readable and reusable, as well as separating behavior from structure.</p>

<p>Also, for kicks, <a href="/examples/prasun/example8.html">here's one final example</a> of doing the things mentioned in this article, but using the jQuery library instead of self-written scripts.  In the instance that you are already pulling in a hefty JavaScirpt library into your web site, you might as well make use of it.</p>]]>
      
   </content>
</entry>
<entry>
   <title>Can deprecated tags become undeprecated?</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/2008/04/can_deprecated_tags_become_und.html" />
   <id>tag:www.askthecssguy.com,2008://1.48</id>
   
   <published>2008-04-01T15:02:39Z</published>
   <updated>2008-09-11T04:54:07Z</updated>
   
   <summary><![CDATA[When certain tags become deprecated, they become so because they are replaced by more favorable ways of achieving their original purpose. (In the case of &lt;blink&gt;, being annoying helped it along the path of deprecation.) But there's one tag that...]]></summary>
   <author>
      <name></name>
      
   </author>
         <category term="ringmaster" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.askthecssguy.com/">
      <![CDATA[<p>When certain tags become deprecated, they become so because they are replaced by more favorable ways of achieving their original purpose.  (In the case of <code>&lt;blink&gt;</code>, being annoying helped it along the path of deprecation.)  But there's one tag that may be coming back to life.</p>

<h3>The value of &lt;u&gt;</h3>

<p>The <code>&lt;u&gt;</code>, whose sole purpose was to underline inline text, was deprecated in HTML 4.01, and was destined to remain unsupported in future versions of HTML.  However, arguments have recently been made to revive it in HTML 5, warning that <code>&lt;u&gt;</code> has a specific value that no other tag has, and that we never should've given <code>&lt;u&gt;</code> up.  Watch <a href="http://www.youtube.com/watch?v=eBGIQ7ZuuiU">Tim Berners-Lee</a> defend this proposition to the World Wide Web Consortium in a heated March 2008 discussion.</p>]]>
      
   </content>
</entry>
<entry>
   <title>One pixel notched corners as used by Google Analytics</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/2008/03/one_pixel_notched_corners_as_u.html" />
   <id>tag:www.askthecssguy.com,2008://1.47</id>
   
   <published>2008-03-28T21:09:48Z</published>
   <updated>2008-09-10T23:51:24Z</updated>
   
   <summary>I use Google Analytics, and I noticed that their left nav has an interesting characteristic: instead of each option being boxed in a clickable rectangle, there is a one pixel notch in each corner. It&apos;s not necessarily a curved corner,...</summary>
   <author>
      <name></name>
      
   </author>
         <category term="tiger" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.askthecssguy.com/">
      <![CDATA[<p>I use Google Analytics, and I noticed that their left nav has an interesting characteristic: instead of each option being boxed in a clickable rectangle, there is a one pixel notch in each corner.  It's not necessarily a curved corner, but it is a little softer than a normal box.</p>

<p><img src="/images/080328_analyticsnav.gif" alt="Google Analytics Nav uses has a one pixel notch in each corner." /></p>

<p>I would've naturally thought that if someone is going to use background images to create a capsule effect, they would have used anti-aliased images.  But upon closer inspection, no background images were used at all.  Instead, a couple of nested tags within the link help create the effect.  Instead of this:</p>

<pre><code>&lt;ul&gt;
  &lt;li&gt;
    &lt;a href="/"&gt;
      Visitors
    &lt;/a&gt;
  &lt;/li&gt;
&lt;/ul&gt;</code></pre>

<p>Some <code>&lt;b&gt;</code> tags are added (likely chosen because because of their length - one letter):</p>

<pre><code>&lt;ul&gt;
  &lt;li&gt;
    &lt;a href="/"&gt;
      <strong>&lt;b&gt;
        &lt;b&gt;
          &lt;b&gt;</strong>
            Visitors
          <strong>&lt;/b&gt;
        &lt;/b&gt;
      &lt;/b&gt;</strong>
    &lt;/a&gt;
  &lt;/li&gt;
&lt;/ul&gt;</code></pre>

<p>Now whether or not this is the purest thing to do is not the subject of this article.  Obviously, I don't support <em>over</em>nesting of tags.  But the Analytics designers did this for a specific design purpose.  Nesting one tag is quite common for achieving sliding-doors rounded tabs.  Perhaps the reasoning was, 'Why not nest two more and drop the use of images?'</p>

<p>Also, similar techniques exist out there to get rounded borders with a greater radius than just one pixel.  However, those techniques involve much more extra markup (or javascript to create it for them) in the form of empty tags, where success comes in the form of a pixelated curve reminiscent of an 8-bit Nintendo display.  (I exaggerate, <a href="http://www.cssplay.co.uk/boxes/snazzy.html">but still</a>.)   In the case of a one pixel notch, the effect at least looks intentional. </p>

<p>The notched corner is created by modifying the nested tags' border and position properties.</p>

<p>Here's the CSS:</p>

<pre><code>li a {
  display:block; <span style="color:#999;">/* a must */</span>
  border: solid #666;
  border-width: 0 1px; <span style="color:#999;">/* left and right borders only */</span>
  text-decoration: none;
  outline:none; <span style="color:#999;">/* so as not to distract from the effect */</span>
  color: #000;
  background: #e4e4e4;
}
li a b {
  display: block; <span style="color:#999;">/* another must */</span>
  position:relative; <span style="color:#999;">/* because the child elements are positioned */</span>
  top: -1px; <span style="color:#999;">/* drag it up a little, creates the top notches */</span>
  left: 0;
  border:solid #666;
  border-width:1px 0 0; <span style="color:#999;">/* top border only */</span>
  font-weight:normal;
}
li a b b {
  border-width:0 0 1px; <span style="color:#999;">/* bottom border only */</span>
  top: 2px; <span style="color:#999;">/* pushed down a little to create the bottom notches */</span>
}
li a b b b { <span style="color:#999;">/* i don't think three-deep tag is even necessary */</span>
  top:-1px;
  padding: 1px 6px;
  border-width: 0;
}</code></pre>

<p>To just get the notch, the third-deep <code>&lt;b&gt;</code> tag isn't needed.  I think Google Analytics included it because they wanted to add some background images with it on their buttons.  I think this effect can be achieved with one less nested <code>&lt;b&gt;</code>.</p>

<pre><code>&lt;ul&gt;
  &lt;li&gt;
    &lt;a href="/"&gt;
      <strong>&lt;b&gt;
        &lt;b&gt;</strong>
          Visitors
        <strong>&lt;/b&gt;
      &lt;/b&gt;</strong>
    &lt;/a&gt;
  &lt;/li&gt;
&lt;/ul&gt;</code></pre>

<p>In my <a href="/examples/notchedcorners/index.html">example page</a>, I left it at two deep.</p>]]>
      
   </content>
</entry>
<entry>
   <title>New CSS Off Contest April 5</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/2008/03/new_css_off_contest_april_4.html" />
   <id>tag:www.askthecssguy.com,2008://1.46</id>
   
   <published>2008-03-21T18:46:47Z</published>
   <updated>2008-09-10T23:51:24Z</updated>
   
   <summary>I&apos;m excited about the upcoming CSS Off contest, even though I won&apos;t be judging this time around. Brad Colbow is the guest designer. I&apos;ve seen a sneak peak of the design, and it looks like it will be a fun...</summary>
   <author>
      <name></name>
      
   </author>
         <category term="popcorn" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.askthecssguy.com/">
      <![CDATA[<p>I'm excited about the <a href="http://cssoff.com/2008/03/20/next-contest-is-april-4-2008/">upcoming CSS Off contest</a>, even though I won't be judging this time around.  <a href="http://bradcolbow.com/">Brad Colbow</a> is the guest designer.  I've seen a sneak peak of the design, and it looks like it will be a fun challenge.  If you want to exercise your markup skills, get feedback on your approach, and possibly win a little something for your favorite charity, consider giving it a go on April 5 (Saturday).</p>

<p>It's free and open to everyone of any skill level.</p>

<p><strong>Update (23 Mar 2008):</strong> I updated the title with the correct date, April 5.</p>]]>
      
   </content>
</entry>
<entry>
   <title>I&apos;m redoing previous articles to use jQuery, you know, just for fun</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/2008/03/im_redoing_previous_articles_t_1.html" />
   <id>tag:www.askthecssguy.com,2008://1.45</id>
   
   <published>2008-03-08T04:24:55Z</published>
   <updated>2008-09-10T23:51:24Z</updated>
   
   <summary>I like using the jQuery library so much, I started converting my old article examples to use it. I thought it would be interesting to see how much less scripting I would have to write. (A little less, but not...</summary>
   <author>
      <name></name>
      
   </author>
         <category term="ringmaster" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.askthecssguy.com/">
      <![CDATA[<p>I like using the jQuery library so much, I started converting my old article examples to use it.  I thought it would be interesting to see how much less scripting I would have to write.  (A little less, but not much - my examples were never heavy on the scripting anyway).  I think it made some more readable, too, in that I can glance at the script code and tell what's going on.</p>

<p><a href="/examples/examplesUsingjQuery/index.html">Here's a list of what I have converted so far</a>, with a downloadable zip.</p>

<p>The obligatory disclaimer - using any library's methods is no substitute for learning JavaScript basics.  If you haven't already added JavaScript to your list of things to learn as a web designer, stop mucking around and pick up Jeremy Keith's <i>DOM Scripting</i>.</p>

<p>For a seasoned html/css person, learning jQuery is arguably much easier than learning JavaScript from scratch, since its selector syntax is based on CSS selectors.  Since I'm the CSS Guy, it is my library of choice, <em>but only when a library is needed</em>.  Some pages require so little DOM manipulation that self-written functions easily fit the bill, as well as saving some downloaded bits.</p>

<p>On a related note, someone turned my favicon article example into a <a href="http://www.babylon-design.com/site/index.php/2008/03/06/221-plugin-jquery-faviconize">jQuery plugin</a>.</p>]]>
      
   </content>
</entry>
<entry>
   <title>Pushing a shopping cart full of tea with CSS and JavaScript</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/2007/12/pushing_a_shopping_cart_full_o_1.html" />
   <id>tag:www.askthecssguy.com,2007://1.44</id>
   
   <published>2007-12-14T00:57:18Z</published>
   <updated>2008-09-11T04:55:43Z</updated>
   
   <summary>While brainstorming for a recent project, I toyed with the idea of having a shopping cart that follows the user on a scrolling page. The idea was partly inspired by Derek Allard&apos;s entry, &quot;Conditionally Sticky Sidebar&quot;. The idea would be...</summary>
   <author>
      <name></name>
      
   </author>
         <category term="tiger" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.askthecssguy.com/">
      <![CDATA[<p>While brainstorming for a recent project, I toyed with the idea of having a shopping cart that follows the user on a scrolling page.  The idea was partly inspired by Derek Allard's entry, "<a href="http://www.derekallard.com/blog/post/conditionally-sticky-sidebar/">Conditionally Sticky Sidebar</a>".</p>

<p>The idea would be that the cart would only start following the scrolling page if it had a product in it; an empty cart would not.  I ended up not using the feature for a variety fo reasons, but I thought I could still share the logic behind the effect.</p>

<p>For those who like to skip ahead: <a href="/examples/tea/shop4.html">view the final example</a> or <a href="/examples/tea/teaParty07.zip">download a zip</a> with all the html, CSS, JavaScript, and supporting images.</p>

<h3>First, a storefront</h3>
<p>To start off, <a href="/examples/tea/shop1.html">here's example 1 - a very basic storefront</a>.  In this example, our storefront sells tea.  The shopping cart, pictured with some items inside, is on the right.  The shopping cart is 200 pixels wide, and I've reserved the right-side 200 pixels all the way down the page to serve as the shopping cart 'aisle'.</p>

<h3>HTML</h3>
<pre><code>&lt;div id="shoppingCartAisle"&gt;
  &lt;div id="shoppingCart"&gt;
    &lt;h3&gt;Shopping Cart&lt;/h3&gt;
    &lt;ul&gt;
      &lt;li&gt;product 1&lt;/&gt;
      &lt;li&gt;product 2&lt;/&gt;
      &lt;li&gt;product 3&lt;/&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
&lt;/div&gt;</code></pre>

<h3>CSS</h3>
<pre><code>...
#shoppingCartAisle {
  width:200px;
  float:left;
}
#shoppingCartAisle #shoppingCart {
  width:200px;
  position:absolute;
  top:0;
  background:transparent url(images/bottom.gif) no-repeat bottom left;
}
#shoppingCartAisle #shoppingCart h3 	{
  background:transparent url(images/top.gif) no-repeat top left;
  margin-top:0;
  padding:4px;
 }
...</code></pre>

<p>Notice that I have a 'shoppingCartAisle', which is the container for the 'shoppingCart' div.  #shoppingCartAisle is set to position relative, and #shoppingCart is absolutely positioned to stick to the top of #shoppingCartAisle.  (I'm using absolute positioning because I'm setting up what is to come.)</p>

<h3>Using position:fixed</h3>
<p>To illustrate the cart running up and down the page, <a href="/examples/tea/shop2.html">I've created example 2</a>, which has #shoppingCart using position:fixed; instead of position:absolute;.  As the user scrolls, the shoppingCart follows the browser.  Unfortunately, it overlaps the header area as well.  I'd rather my cart stay in the aisle.</p>

<h3>Deciding how to do this</h3>
<p>This is where Derek Allard's article proved to be of great reference. I varied from his approach in two ways:</p>
<ol>
<li>My cart does not hug the side of the browser, but instead stays within the right column of a fixed-width layout.</li>
<li>I planned for the distance from the top of the browser to the cart to vary based on promotional messages or whatnot that may/may not line the top of the page, so it was important for the cart to be positioned absolute to the aisle, not the browser window.</li>
</ol>

<p>It's helpful for me to state what I want to happen in English before writing the JavaScript. When the browser scrolls, determine if it has scrolled down past where the 'shoppingCartAisle' begins.  If so, change the 'shoppingCart' to position:fixed so that it follows the user down the page.  If the browser scrolls back up to where 'shoppingCartAisle' starts, then switch 'shoppingCart' back to position:absolute so that it doesn't go into the header space of the page.</p>

<h3>The fun part - JavaScript</h3>
<p>To determine where the shoppingCartAisle begins, I have a function called establishTopPosition(), which is the first of two functions you see below.  The second function, pushMyCart(), does what the above paragraph describes in English.  For the parts that look weird, just know that Derek Allard figured that stuff out for me.</p>
<pre><code>&lt;script type="text/javascript"&gt;
function establishTopPosition() {
  var shoppingCartAisle = document.getElementById('shoppingCartAisle');
  var y = 0;
  while (shoppingCartAisle!=null) {
    y += shoppingCartAisle.offsetTop
    shoppingCartAisle = shoppingCartAisle.offsetParent;
  }
    return y;
}
function pushMyCart() {
  var shoppingCart = document.getElementById('shoppingCart');
  var topPos = establishTopPosition();
  if( window.XMLHttpRequest ) { // IE 6 hates position fixed
    if (document.documentElement.scrollTop &gt; topPos  || self.pageYOffset &gt; topPos) {
      shoppingCart.style.position = 'fixed';
    } else {
      shoppingCart.style.position = 'absolute';
    }
  }
}
&lt;/script&gt;</code></pre>

<p>And I want JavaScript to pushMyCart() when the page is scrolling, so add this to the onscroll event of the body:</p>

<pre><code>&lt;body onscroll="pushMyCart();"&gt;</code></pre>

<p><a href="/examples/tea/shop3.html">See example 3</a> where JavaScript is pushing my cart.</p>

<h3>Let's enhance it some more</h3>
<p>I only want a rolling shopping cart if there are products in the cart.  If it's empty, I just want it to stay put.</p>

<p>To do this, I'm going to add a class to the shopping cart called 'rollingCart' when a product is added.  Then I will tweak my JavaScript to only roll the cart if it has a class of 'rollingCart'.</p>
<p>I also need a way to clear out the items from my cart, so I've provided a link, 'Empty Cart', than when clicked, removes the class of 'rollingCart' from the shopping cart.</p>
<p>Once again, I'm relying on the great work of others to accomplish this, namely <a href="http://www.robertnyman.com/">Robert Nyman</a>, who wrote the very helpful functions getElementsByClassName, addClassName, and removeClassName, and also one <a href="http://simonwillison.net/">Simon Willison</a>, who wrote the addLoadEvent function. (Yes, I know there are libraries that can do this, but this assumes there are none being used.)</p>

<p>Here are the functions I wrote to accomplish my new task.  The first one sets up the 'add to cart' links so that once clicked, they give a 'rollingCart' class to the cart, then tell the browser to push my cart.  The second function sets up the 'clear cart' link, so that once clicked, it removes the 'rollingCart' class, then tells the browser to parkMyCart().  parkMyCart() attaches the cart to the top of the shoppingCartAisle element again.</p>

<pre><code>function addToCartLinks() {
  var links = getElementsByClassName('addToCart','a',document);
  var cart = document.getElementById('shoppingCart');
  for (var i=0; i&lt;links.length; i++) {
    links[i].onclick = function() {
      addClassName(cart,'rollingCart');
      pushMyCart();
      return false;
    }
  }
}

function clearCart() {
  var dumpit = document.getElementById('clearCart');
  var cart = document.getElementById('shoppingCart');
  dumpit.onclick = function() {
    removeClassName(cart,'rollingCart');
    parkMyCart();
    return false;
  }
}

function parkMyCart() {
  var cart = document.getElementById('shoppingCart');
  cart.style.position = 'absolute';
}</code></pre>

<p><a href="/examples/tea/shop4.html">See it in action with example 4</a> - remember to 'add to cart' and 'clear cart' to see the effect.  Feel free to <a href="/examples/tea/teaParty07.zip">download the zip</a> as well.</p>

<p>Note that I kept these functions simple for the sake of demonstration - no products are added or removed from the cart when links are clicked; just the class name changes.  Also, this doesn't work in IE6, and the JavaScript allows IE6 to 'gracefully degrade' by always having a positioned absolute cart.</p>

<p>I hope you find the post helpful.  I am no JavaScript genius, so if you see anything that could make this better, please leave a comment.</p>

<h3>Why tea?</h3>
<p>This post is so themed to raise awareness for Ron Paul in honor of this weekend's fundraiser event, which purposefully coincides with the anniversary of the Boston Tea Party.  If you don't know who Ron Paul is, I encourage you to google him or search YouTube for supporter-made videos.  Or start with these: <a href="http://www.youtube.com/watch?v=FG_HuFtP8w8">one</a>, <a href="http://www.youtube.com/watch?v=FG2PUZoukfA">two</a>, <a href="http://www.youtube.com/watch?v=yCM_wQy4YVg">three</a>. Thanks.</p>]]>
      
   </content>
</entry>
<entry>
   <title>Mike asks the CSS Guy for recommendations on rounded corners</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/2007/11/mike_asks_the_css_guy_for_reco_1.html" />
   <id>tag:www.askthecssguy.com,2007://1.43</id>
   
   <published>2007-11-15T04:23:48Z</published>
   <updated>2008-09-10T23:51:25Z</updated>
   
   <summary>Mike writes: I have a request: could you PLEASE tackle the rounded corner issue? I seem to get a request all the time to add some rounded corners to sites and I have looked at at least a dozen different...</summary>
   <author>
      <name></name>
      
   </author>
         <category term="popcorn" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.askthecssguy.com/">
      <![CDATA[<p>Mike writes:</p>

<blockquote><p>I have a request: could you PLEASE tackle the rounded corner issue? I seem to get a request all the time to add some rounded corners to
sites and I have looked at at least a dozen different solutions and
was never happy. What do you recommend? How do you create rounded
corners?
</p></blockquote>

<p>Let's cut to the chase - I have no new or special method for rounded corners.  Also, there is no one way that I can recommend, as some methods are better suited than others based on context and need. I have no intention of doing a rundown of every method, but I'd still be happy to share how I've created rounded corners in the past.</p>

<h4>Simplest way I know</h4>

<p>I've been fortunate enough to work on projects that have only required rounded corners on elements with a fixed width and a solid color (no gradients).  That makes it pretty easy for me - I just use a giant gif.</p>

<p>Gif's are relatively light-weight, even big ones if it's a solid color.  For this example, I'll create one at a fixed width of 380px, and make it long - 780px.  <a href="/examples/roundedCorners/roundBox.gif">See example</a>.</p>

<p>Then I'll markup my box.</p>

<pre><code>&lt;div class="roundBox"&gt;
  &lt;p&gt;beautifully-encapsulated paragraph&lt;/p&gt;
&lt;/div&gt;</code></pre>

<p>And give it the background.</p>

<pre><code>.roundBox {
  background:transparent url(roundBox.gif) no-repeat top left;
  width:340px;
  padding:20px;
}</code></pre>

<p>Note that the width of my box is set to 340px in the CSS, because I have left and right padding of 20px, totalling the width of my image: 380px.</p>

<p>To get the bottom corners to show up, more markup is needed:</p>

<pre><code>&lt;div class="roundBox"&gt;
  &lt;p&gt;beautifully-encapsulated paragraph&lt;/p&gt;
  <strong>&lt;div class="boxBottom"&gt;&lt;/div&gt;</strong>
&lt;/div&gt;</code></pre>

<p>The 'boxBottom' div should be styled to fit at the bottom and stretch to the full 380px.</p>

<pre><code>.roundBox .boxBottom {
  background:white url(roundBox.gif) no-repeat bottom left;
  font-size:1px;
  line-height:1px;
  height:14px;
  margin:0 -20px -20px -20px;
}</code></pre>

<p>And now <a href="/examples/roundedCorners/index.html">I've got a rounded corner box</a> that can stretch down pretty far - in this case, 780px.</p>

<h4>Other methods I've used (besides... um... tables)</h4>

<p>Another way I've made rounded corners is illustrated on this very website, in the upper right-hand corner of the content.  It's using the -moz-border-radius-topright, and since it's just a trivial presentational dollop, I couldn't care less than it's mozilla-only.</p>

<p>In the past, I've attempted to use absolutely positioned divs with negative margins to make each corner of a bordered box, but that didn't go well with IE (not even 7), so IE didn't get rounded corners that day.  When I redid the project, I used the gif method described above.</p>

<h4>Flexible alternative</h4>

<p>If dynamic width and height are required, I'd recommend checking out <a href="http://www.456bereastreet.com/lab/flexible_custom_corners_borders/">this article</a>.</p>]]>
      
   </content>
</entry>
<entry>
   <title>Job Opportunity in Memphis, Tennessee</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/2007/11/job_opportunity_in_memphis_ten.html" />
   <id>tag:www.askthecssguy.com,2007://1.42</id>
   
   <published>2007-11-07T03:17:45Z</published>
   <updated>2008-09-10T23:51:25Z</updated>
   
   <summary>I work at Hilton Hotels, and for a big project, we&apos;re needing help for front-end web development. We need someone who can write HTML, CSS, and JavaScript. The well-structured, valid, semantic, accessible, progressive enhancement/graceful degradation kind of stuff. It&apos;s a...</summary>
   <author>
      <name></name>
      
   </author>
         <category term="ringmaster" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.askthecssguy.com/">
      <![CDATA[<p>I work at Hilton Hotels, and for a big project, we're needing help for front-end web development.</p>

<p>We need someone who can write HTML, CSS, and JavaScript.  The well-structured, valid, semantic, accessible, progressive enhancement/graceful degradation kind of stuff.</p>

<p>It's a plus, but not a requirement, if you're familiar with jQuery and have worked on gargantuan international travel web sites.</p>

<p>It's full-time work, but a temporary position, lasting a minimum of six months. The candidate must play well with others, and must be able to commute to Memphis, TN.</p>

<p>Send a resumes, links to some of your work (descriptions would be helpful), and hourly rates to askthecssguy+hiltonjob@gmail.com.</p>

<p><strong>Update Nov 7, 2007:</strong> time frame added.</p>
<p><strong>Update Nov 23, 2007:</strong> The position has been filled.</p>
]]>
      
   </content>
</entry>
<entry>
   <title>Sangeeta asks the CSS Guy how to create a table like Orbitz&apos;s airline flights scheduling and pricing matrix</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/2007/09/sangeeta_asks_the_css_guy_how_1.html" />
   <id>tag:www.askthecssguy.com,2007://1.41</id>
   
   <published>2007-09-23T06:05:06Z</published>
   <updated>2008-09-10T23:51:25Z</updated>
   
   <summary>Sangeeta wrote about a matrix she&apos;d like to create that would give an indication of relationships among the information provided. She elaborates: ...For example - clicking on a cell should highlight the associated cell in the top row and left...</summary>
   <author>
      <name></name>
      
   </author>
         <category term="tiger" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.askthecssguy.com/">
      <![CDATA[<p>Sangeeta wrote about a matrix she'd like to create that would give an indication of relationships among the information provided.  She elaborates:</p>

<blockquote>
<p>...For example - clicking on a cell should highlight the associated cell in the top row and left most column.</p>

<p>One good example is <a href="http://www.orbitz.com/">orbitz.com</a>.</p>

<p>(You have to actually perform a search to see the actual matrix.) The top row consist of the airline names and the left column is non-stop, 1 stop or 2 stop flight...as you move your cursor, the color  of the associated top cell and left most cell changes to yellow...</p>
</blockquote>


<p>Nice idea.  I'll cover one way to create the effect using JavaScript and CSS. (For those who have been here before, I realize there is lots of repeated material here from my <a href="http://www.askthecssguy.com/2007/08/creating_a_table_with_dynamica.html">previous post</a>, but that's the good thing about reusable JavaScript... it's reusable in different situations!)</p>

<p><img src="/images/070923_orbitz.gif" alt="Orbitz's Flight Stops and Price Table" /></p>

<p>For those who like to skip ahead: <a href="/examples/orbitz/example05.html">view the final example</a></p>

<h4>Getting Started</h4>

<p>A table of this type has headings across the top as well as down the left side.  I'll use a <code>thead</code> with <code>th</code>'s across the top, line the left column of the <code>tbody</code> with <code>th</code>'s, too. like so:</p>

<p><img src="/images/070923_tablestructure.gif" alt="A basic table with a thead and tbody, with some table heading cells being the first cell of each table row in the tbody" /></p>

<p><a href="/examples/orbitz/example01.html">View example 1, the bare table</a>.</p>
<p>Who are we kidding?  <a href="/examples/orbitz/example02.html">View example 2, a <em>styled</em> table</a>.</p>
<h4>Next Step: Add class</h4>
<p>To help establish the relationship between cells, add classes.  (This will be used by the JavaScript to know which cells to highlight.</p>
<pre><code>&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th <strong>class="null"</strong>&gt;
      &lt;th <strong>class="stones"</strong>&gt;
      &lt;th <strong>class="u2"</strong>&gt;
      &lt;th <strong>class="crue"</strong>&gt;
    &lt;tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;th&gt;
      &lt;td <strong>class="stones"</strong>&gt;
      &lt;td <strong>class="u2"</strong>&gt;
      &lt;td <strong>class="crue"</strong>&gt;
    &lt;/tr&gt;
    ...
  &lt;/tbody&gt;
&lt;/table&gt;</code></pre>

<p><a href="/examples/orbitz/example03.html">View example 3, classes added</a>. (Or don't, since there is not much visually different yet).</p>

<h4>Next Step: Establish what an selected state looks like</h4>
<p>I'm going to use <code>class="on"</code> again to add the highlight to the appropriate cells.</p>
<pre><code>&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      ...
      &lt;th class="u2 <strong>on</strong>&gt;
      ...
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
  ...
    &lt;tr&gt;
      &lt;th <strong>class="on"</strong>&gt;
      &lt;td class="stones"&gt;
      &lt;td class="u2 <strong>on</strong>"&gt;
      &lt;td class="crue"&gt;
    &lt;/tr&gt;
   ...
  &lt;/tbody&gt;
&lt;/table&gt;</code></pre>

<p>and the CSS...</p>
<pre><code>tbody td.on {background:#f3f0e4;}
thead th.on {background:#ffe068;}
tbody th.on {background:#ffe068;}</code></pre>
<p><a href="/examples/orbitz/example04.html">View example 4, the selected state</a>.</p>

<h4>Next Step: Using JavaScript</h4>
<p>We can't really use <code>:hover</code> to make this stuff work.  Instead, we're going to highlight the appropriate cells using <code>onmouseover</code> and <code>onmouseout</code> events.</p>
<p>In English, here's what we want to happen:</p>
<ol>
	<li>When someone hovers over the Nikki Sixx table cell</li>
	<li>add class="on" to the Nikki Sixx cell</li>
	<li>as well as adding class="on" to the "M&ouml;tley Cr&uuml;e" and "Bass Guitar" cells.</li>
	<li>When someone moves their mouse away from that cell, remove class="on" from all of those cells we just added to previously.</li>
</ol>
<p>Here are the tools needed to do that:</p>
<ul>
<li>A javascript function called getElementsByClassName, which allows us to target elements based on their class value. (via <a href="http://www.robertnyman.com/2006/11/07/ej-the-only-javascript-library-youll-ever-need/">Robert Nyman</a>)</li>
<li>A javascript function called addClassName (via <a href="http://www.robertnyman.com/">Robert Nyman</a>). This function will be used to add "on" as a class name to our desired cells.</li>
<li>A javascript function called removeClassName, (via <a href="http://www.robertnyman.com/2006/11/07/ej-the-only-javascript-library-youll-ever-need/">Robert Nyman</a>).   This is used to unselect cells by removing the "on" value from their class attributes</li>
<li>A custom javascript function to tie the behavior together.</li>
<li>A javascript function called addLoadEvent (via <a href="http://simonwillison.net/2004/May/26/addLoadEvent/">Simon Willison</a>), which is just a way of attaching these behaviors when the page loads instead of putting onmouseover and onmouseout event attributes to every cell by hand.</li>
</ul>

<p>And here's the end result - <a href="/examples/orbitz/example05.html">view example 5, the final product</a>. Just view source to copy it and take it with you.</p>

<h4>See also</h4>
<p>I could see how someone could want to apply highlights to entire rows and entire columns (as opposed to just the header cell of that row or column)... it wouldn't be a long stretch from <a href="http://www.askthecssguy.com/examples/rowlock/example5.html">this</a> (corresponding how-to post found <a href="http://www.askthecssguy.com/2006/12/row_locking_with_css_and_javas.html">here</a>).</p>
<p>Also, <a href="http://www.askthecssguy.com/2006/10/bowmans_super_doublehover_list_1.html">here's a way</a> to indicate relationships similarly to what is described above, but without JavaScript.</p>]]>
      
   </content>
</entry>
<entry>
   <title>Creating a table with dynamically highlighted columns like Crazy Egg&apos;s pricing table</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/2007/08/creating_a_table_with_dynamica.html" />
   <id>tag:www.askthecssguy.com,2007://1.40</id>
   
   <published>2007-08-28T05:17:46Z</published>
   <updated>2008-09-10T23:51:25Z</updated>
   
   <summary><![CDATA[Update Aug 29, 2007: Examples 9 and 10, and the downloadable zip now accommodate for JavaScript-disabled browsers. Update Aug 28, 2007: links to examples fixed. Again. I like Crazy Egg's pricing table on their Pricing &amp; Signup page. When you...]]></summary>
   <author>
      <name></name>
      
   </author>
         <category term="popcorn" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.askthecssguy.com/">
      <![CDATA[<p><strong>Update Aug 29, 2007</strong>: Examples 9 and 10, and the downloadable zip now accommodate for JavaScript-disabled browsers.</p>
<p><strong>Update Aug 28, 2007</strong>: links to examples fixed.  Again.</p>

<p>I like <a href="http://www.crazyegg.com">Crazy Egg</a>'s pricing table on their <a href="https://crazyegg.com/pay/plans">Pricing &amp; Signup</a> page.  When you click on "Sign Up" for an option, that plan's column highlights, the other plans vanish, and a signup form takes their place.  There is a number of impressive things happening within this small area. I wanted to try and recreate the behavior step by step, and share the power of combining CSS, JavaScript, and images in clever ways.</p>

<p>If you just clicked over to look at Crazy Egg's site, then clicked back, consider visiting there again when you're finished reading this tutorial.  If you're as impressed with the way their site is put together as I am, you, or someone you know/work with, could probably benefit from Crazy Egg's amazing click tracking visualization tools.  Their prices sure make it easy to get started, so give it a consideration while you're giving them traffic.</p>

<p><img src="/images/070822_crazyeggpricingtable.gif" alt="Crazy Egg's Pricing Table" /></p>

<p>For those who like to skip ahead: <a href="/examples/crazyegg/example10.html">view the final example</a> or <a href="/examples/crazyegg/soundsquirt-dynamic-table-example.zip">download a zip</a> with all the html, CSS, JavaScript, and supporting images used in this article.</p>

<h4>Getting Started</h4>

<p>First I need a table, and I'll model my example off of Crazy Egg.  I'll use a left column for the descriptions, a top row for headings, and a matrix of features in the body. We're going to make use of <code>thead</code>, <code>tfoot</code>, and <code>tbody</code>.

<pre><code>&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;'s go here
    &lt;tr&gt;
  &lt;/thead&gt;
  &lt;tfoot&gt;
    &lt;tr&gt;
      &lt;td&gt;'s go here
    &lt;/tr&gt;
  &lt;/tfoot&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;'s go here
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;</code></pre>

<p><a href="/examples/crazyegg/example01.html">View example 1, the bare table</a>.</p>
<h4>Next Step: Add class</h4>
<p>By default, all the table cells look alike.  To establish that cells in each column are related, I need to add classes to all the <code>&lt;td&gt;</code> and  <code>&lt;th&gt;</code> tags.</p>
<pre><code>&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th <strong>class="desc"</strong>&gt;
      &lt;th <strong>class="choiceA"</strong>&gt;
      &lt;th <strong>class="choiceB"</strong>&gt;
      ...
    &lt;tr&gt;
  &lt;/thead&gt;
  &lt;tfoot&gt;
    &lt;tr&gt;
      &lt;td <strong>class="desc"</strong>&gt;
      &lt;td <strong>class="choiceA"</strong>&gt;
      &lt;td <strong>class="choiceB"</strong>&gt;
    &lt;/tr&gt;
  &lt;/tfoot&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td <strong>class="desc"</strong>&gt;
      &lt;td <strong>class="choiceA"</strong>&gt;
      &lt;td <strong>class="choiceB"</strong>&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;</code></pre>
<p><a href="/examples/crazyegg/example02.html">View example 2, adding class</a>, which also shows the checkbox added. Here's a screenshot.</p>
<p><img src="/images/070822_crazyeggcolumnclass.gif" alt="Showing how columns are assigned a class" /></p>

<h4>Next Step: Establish what a selected state looks like</h4>
<p>We'd like to indicate a selected column by adding <code>class="on"</code> to the appropriate cells. Since all cells already have a class name assigned, the <code>on</code> class name will added to the class attribute value with a space.</p>
<pre><code>&lt;table&gt;
  ...
  &lt;tbody&gt;
  ...
    &lt;tr&gt;
      &lt;td class="desc"&gt;
      &lt;td class="choiceA <strong>on</strong>"&gt;
      &lt;td class="choiceB"&gt;
    &lt;/tr&gt;
   ...
  &lt;/tbody&gt;
&lt;/table&gt;</code></pre>
<p><a href="/examples/crazyegg/example03.html">View example 3, the selected state</a>.</p>
<p><img src="/images/070822_crazyeggselected.gif" alt="Selected state is indicated by adding class='on'" /></p>

<h4>Next Step: Switching selected columns with JavaScript</h4>
<p>When someone hits the "Choose" button in a particular column, we want that entire column to take on the selected state. We need a JavaScript for that.</p>
<p>In English, here's what we want to happen:</p>
<ol>
	<li>When someone clicks "Choose" for choice A</li>
	<li>remove the class name of "on" from all other cells</li>
	<li>then, take every cell with the class for choice A</li>
	<li>and add " on" to it.</li>
</ol>
<p>Here are the tools needed to do that:</p>
<ul>
<li>A javascript function called getElementsByClassName, which allows us to target elements based on their class value. (I'm using one written by <a href="http://www.robertnyman.com/2006/11/07/ej-the-only-javascript-library-youll-ever-need/">Robert Nyman</a>)</li>
<li>A javascript function called addClassName (also via <a href="http://www.robertnyman.com/">Robert Nyman</a>, although the one I'm using he hasn't placed on his web site yet.  This function will be used to add "on" as a class name to the selected columns.</li>
<li>A javascript function called removeClassName, which is used to unselect cells by removing the "on" value from their class attributes (via <a href="http://www.robertnyman.com/2006/11/07/ej-the-only-javascript-library-youll-ever-need/">Robert Nyman</a>)</li>
<li>A custom javascript function to tie the behavior together.</li>
</ul>
<p>Attach the custom function to the "Choose" link's onclick event:</p>
<pre><code>...
&lt;tfoot&gt;
  &lt;tr&gt;
    ...
    &lt;td class="choiceA"&gt;
      &lt;a href="#" <strong>onclick="activateThisColumn('choiceA');return false;"</strong>&gt;
        Choose
      &lt;/a&gt;
    &lt;/td&gt;
    &lt;td class="choiceB"&gt;
      &lt;a href="#" <strong>onclick="activateThisColumn('choiceB');return false;"</strong>&gt;
        Choose
      &lt;/a&gt;
    &lt;/td&gt;
    ...
  &lt;/tr&gt;
&lt;/tfoot&gt;
...</code></pre>
<p><a href="/examples/crazyegg/example04.html">View example 4, selectable columns</a>.  Try it - it works!</p>

<h4>Next Step: Introducing Images</h4>
<p>If we were just changing background colors, it wouldn't have nearly the same coolness as the Crazy Egg table, whose selected column seems to pop out, or extend beyond the boundaries of the table.</p>
<p><img src="/images/070822_crazyeggth_image.gif" alt="" /></p>
<p>It's obvious that a background image is used with the selected table header cell.  What isn't obvious is that the neighboring table header cells are also using background images, which have a solid color on the bottom, and white along the top.  This is evident when turning on cell outlines using Firefox's Web Developer toolbar:</p>
<p><img src="/images/070822_crazyeggth_image2.gif" alt="" /></p>
<p>I'm going to make some images that accomplish the same thing.  Here are the images I'll be using:</p>
<table>
<tr>
<td>regular &lt;th&gt;</td>
<td><img alt="" src="/examples/crazyegg/i/bg_th.gif" /></td>
</tr>
<tr>
<td>selected &lt;th&gt;</td>
<td><img alt="" src="/examples/crazyegg/i/bg_th_on.gif" /></td>
</tr>
<tr>
<td>left column &lt;th&gt;</td>
<td><img alt="" src="/examples/crazyegg/i/bg_th_side.gif" /></td>
</tr>
<tr>
<td>regular &lt;td&gt;</td>
<td><img alt="" src="/examples/crazyegg/i/bg_td.gif" /></td>
</tr>
<tr>
<td>selected &lt;td&gt;</td>
<td><img alt="" src="/examples/crazyegg/i/bg_td_on.gif" /></td>
</tr>
<tr>
<td>left column &lt;td&gt;</td>
<td><img alt="" src="/examples/crazyegg/i/bg_td_side.gif" /></td>
</tr>
<tr>
<td>regular &lt;td&gt; in tfoot</td>
<td><img alt="" src="/examples/crazyegg/i/bg_foot_td.gif" /></td>
</tr>
<tr>
<td>selected &lt;td&gt; in tfoot</td>
<td><img alt="" src="/examples/crazyegg/i/bg_foot_td_on.gif" /></td>
</tr>
<tr>
<td>left side &lt;td&gt; in tfoot</td>
<td><img alt="" src="/examples/crazyegg/i/bg_foot_td_side.gif" /></td>
</tr>
<tr>
<td>choose button</td>
<td><img alt="" src="/examples/crazyegg/i/choose.gif" /></td>
</tr>
</table>
<p><a href="/examples/crazyegg/example05.html">View example 5, images and cell dimensions in place</a>.  Looking good - we now have a decent-looking table with some dynamic behavior.</p>

<p>But we can't stop.  Let's introduce even more dynamic behavior.</p>
<h4>Next Step: Showing a form, hiding some table columns.</h4>
<p>On Crazy Egg, when a column is selected, all the other columns disappear, the selected column moves to the left, and a form appears in the space to the right.  The cancel button of the form then reshows all the other previously hidden columns.</p>
<p>First, I'll draw out the form that will exist outside the table.</p>
<p><a href="/examples/crazyegg/example06.html">View example 6, a form is born</a>.</p>
<p>Then we must style the form to take up the exact dimensions of the four unselected columns.</p>
<p><a href="/examples/crazyegg/example07.html">View example 7, a form is styled and dimensionalized</a>.</p>
<p>The form will have to be absolutely positioned over table.  So we'll introduce a container element to both the form and the table to be our relative positioned parent.</p>
<pre><code>&lt;div id="prices"&gt;

  &lt;div id="formcontainer"&gt;
  ...
  &lt;/div&gt;
  
  &lt;table id="pricetable"&gt;
  ...
  &lt;/table&gt;
  
&lt;/div&gt;</code></pre>
<p><a href="/examples/crazyegg/example08.html">View example 8, a form is positioned</a>.</p>

<p>Ooops!  The form shouldn't show by default, and we need to have all other cells except the cells in the selected column and cells in the far left column. We'll make use of a new function, <code>hasclass</code>, that checks for class="side".  We'll modify our JavaScript function "activateThisColumn" to only hide and show the appropriate cells.</p>
<pre><code>function activateThisColumn(column) {
  var table = document.getElementById('pricetable');
  var form = document.getElementById('formcontainer');

  // first, remove the 'on' class from all other th's
  var ths = table.getElementsByTagName('th');
  for (var g=0; g&lt;ths.length; g++) {
    removeClassName(ths[g], 'on');
    <strong>if (!hasclass(ths[g],'side')) {
      ths[g].style.display = 'none';
    }</strong>
  }
  // then, remove the 'on' class from all other td's
  var tds = table.getElementsByTagName('td');
  for (var m=0; m&lt;tds.length; m++) {
    removeClassName(tds[m], 'on');
    <strong>if (!hasclass(tds[m],'side')) {
      tds[m].style.display = 'none';
    }</strong>
  }

  // now, add the class 'on' to the selected th
  var newths = getElementsByClassName(column, 'th', table);
  for (var h=0; h&lt;newths.length; h++) {
    addClassName(newths[h], 'on');
    <strong>newths[h].style.display = '';
    // not all browsers like display = 'block' for cells</strong>
  }
    // and finally, add the class 'on' to the selected td
  var newtds = getElementsByClassName(column, 'td', table);
  for (var i=0; i&lt;newtds.length; i++) {
    addClassName(newtds[i], 'on');
    <strong>newtds[i].style.display = '';
    // not all browsers like display = 'block' for cells</strong>
  }
  // show the form!
  <strong>form.style.display = 'block';</strong>
}</code></pre>

<p><a href="/examples/crazyegg/example09.html">View example 9, a form is revealed when requested</a>.</p>

<p>But we still need to hide the form and keep our selected columns when the form is cancelled. We'll add a function to the onclick event of the cancel button.</p>

<pre></code>&lt;input
  type="image"
  alt="Cancel"
  src="i/button_cancel.gif"
  <strong>onclick="hideTheForm();return false;"</strong> /></code></pre>

<p>And the function says:</p>

<pre><code>function hideTheForm() {
  // get the form
  var form = document.getElementById('formcontainer');
  // hide the form
  form.style.display = 'none';

  // now get the hidden table cells and show them again
  var table = document.getElementById('pricetable');
  var tds = table.getElementsByTagName('td');
  for (var i=0; i&lt;tds.length; i++) {
    tds[i].style.display = '';
  }
  var ths = table.getElementsByTagName('th');
  for (var k=0; k&lt;ths.length; k++) {
    ths[k].style.display = '';
  }
}</code></pre>

<p><a href="/examples/crazyegg/example10.html">View example 10, a form is revealed when requested, and dismissed from view when cancelled</a>.</p>

<p><img src="/images/070822_soundsquirt.gif" alt="The finished product" /></p>

<p><a href="/examples/crazyegg/soundsquirt-dynamic-table-example.zip">Download a zip</a> with all the html, CSS, JavaScript, and supporting images.</p>

<p>There's more going on with Crazy Egg's form than what I've mentioned in this article.  Mainly, Crazy Egg invokes a JavaScript library to animate the form's appearance rather than switching from 'none' to 'block' and back again so bluntly.  That extra step is beyond the scope of this article, but that kind of detail and work put into the form gives a clear indication that the folks at Crazy Egg really know what they are doing.  (Also, IE has some display issues for my form, but those could easily be overcome with conditional comments.) </p>

<p>I hope you enjoy the post, and see what some scripting packaged with images and CSS can accomplish in a small amount of space.</p>]]>
      
   </content>
</entry>
<entry>
   <title>Karen asks the CSS Guy about CSS tooltips without Javascript that show on click instead of hover</title>
   <link rel="alternate" type="text/html" href="http://www.askthecssguy.com/2007/07/karen_asks_the_css_guy_about_c.html" />
   <id>tag:www.askthecssguy.com,2007://1.39</id>
   
   <published>2007-07-12T23:34:33Z</published>
   <updated>2008-09-10T23:51:25Z</updated>
   
   <summary>Karen writes I am working on developing a reporting form for a mobile device as a part of NASA&apos;s Constellation project and I&apos;m trying to figure out how to do entirely CSS tooltip pop-ups onclick instead of a hover effect,...</summary>
   <author>
      <name></name>
      
   </author>
         <category term="ringmaster" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.askthecssguy.com/">
      <![CDATA[<p>Karen writes</p>
<blockquote><p>I am working on developing a reporting form for a mobile device as a part of NASA's Constellation project and I'm trying to figure out how to do entirely CSS tooltip pop-ups onclick instead of a hover effect, without use of Javascript DOM since it is not supported in IE Mobile 5. I've been trying to figure out ways but so far haven't found a good method. Do you have any ideas? </p></blockquote>
<p>Yes, I have ideas, but I have no way of testing this in IE Mobile 5.</p>
<p>We could start with a <a href="http://psacake.com/web/jl.asp">basic CSS hover tooltip example</a>.  My first thought is to tweak it to work with :focus instead of :hover.</p>
<p>Here's a <a href="/examples/focustips/example1.html">simplified :hover example</a>.</p>
<p>If we just swap out :hover with :focus, <a href="/examples/focustips/example2.html">we get a method</a> that works in Firefox, but not in IE6 or IE7 (or Safari).</p>
<p><a href="/examples/focustips/example3.html">Let's try :active instead of focus.</a>  It works fine in IE7, but not the other browsers.</p>
<p>Let's combine :active and :focus and <a href="/examples/focustips/example4.html">see what happens</a>.  It works fine in IE7 and Firefox, but not in IE6 or Safari.</p>

<p>In conclusion, not only do I know next to nothing about the mobile world, I can't find an example that works in all regular browsers consistently.  Perhaps you know your target audience well enough that you know you just need it to work in IE5 Mobile and no other browser.  In that instance, my only suggestion would be to test one of the above methods to see if they work.  If they don't, I've got nothing further to offer, but I would appreciate hearing your results.</p>

<p>If anyone else knows a possible solution, feel free to share.</p>]]>
      
   </content>
</entry>

</feed>
