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

<channel>
	<title>Skull Jackpot &#187; ie</title>
	<atom:link href="http://skulljackpot.com/tagged-as/ie/feed/" rel="self" type="application/rss+xml" />
	<link>http://skulljackpot.com</link>
	<description>Various thoughts of minimal interest to others</description>
	<lastBuildDate>Fri, 25 Feb 2011 16:22:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Super CSS Selector Support with jQuery</title>
		<link>http://skulljackpot.com/2009/04/19/super-css-selector-support-with-jquery/</link>
		<comments>http://skulljackpot.com/2009/04/19/super-css-selector-support-with-jquery/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 22:18:47 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Under the hood]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[selector]]></category>

		<guid isPermaLink="false">http://skulljackpot.com/?p=61</guid>
		<description><![CDATA[Tired of having to add classes in your markup to work around lousy CSS selector support in legacy browsers? Try SuperSelectors - a jQuery plugin enabling great CSS selector support, even in IE6.]]></description>
			<content:encoded><![CDATA[<p>CSS provides a wide array of selectors to specify which elements should be subject to a particular style. CSS 2.1 gives web designers even more granularity when targeting specific elements. This is great in theory. But browser support for these selectors has lagged behind, and IE6 support is limited to only the most basic selectors. This has led to most folks working in the real world stashing the more advanced selectors away for rainy-day experimentation, or idle dreams about the eventual time when we can <em>use</em> these tools.</p>
<h2>Current State of Affairs</h2>
<p>Web folks are a clever bunch, though. If browser support for CSS won&#8217;t give us a way to target a particular element, a common solution is to make classes do the heavy lifting for us. Going through files to add <code>class="text"</code> to <strong>every</strong> text input is an all-too-common experience for web designers.</p>
<p>Adding the classes allows us to target elements on all browsers, but is labor-intensive and potentially error-prone. Moreover, if your site includes content (like comments or blog posts) which will entered by users, you have no easy way to ensure those classes are added appropriately.</p>
<h2>A Glimmer of Hope</h2>
<p>jQuery is one of several great javascript frameworks which have burst onto the scene in the past year or so. One of the reasons jQuery has gotten a lot of attention from web designers is the way it allows you to select elements &#8211; in many cases, jQuery selectors are <em>identical</em> to CSS selectors. jQuery is also extremely extensible. If there&#8217;s functionality you need which isn&#8217;t provided by the core framework, you can easily add it via a plugin (or by extending jQuery directly).</p>
<p>In the course of a recent project, I used jQuery to add a <code>first-child</code> class to some <code>&lt;li&gt;</code> elements in our top navigation, to shore up IE6 CSS support without having to alter the markup. After seeing how easy jQuery made that, I realized it&#8217;s be possible to write a plugin allowing <em>any</em> browser supported by jQuery capable of supporting <strong>all</strong> CSS 2.1 selectors. So I wrote SuperSelectors. It goes through your site&#8217;s stylesheets, dynamically adding classes to elements so that even IE6 can bask in the glow of properly supporting CSS selectors like <code>ul li:first-child li:nth-child(odd) a:hover</code>.</p>
<h2>Pencils out</h2>
<p>Before we can start to determine which elements ought to have classes added, we&#8217;ll need a way to access each stylesheet being used by a given page. Fortunately, the <code>document.styleSheets</code> array does exactly what we want. Unfortunately, we have to incur a little bit of overhead here. Since browsers will silently excise rules they don&#8217;t understand, we have to re-request the CSS files via javascript, and parse <em>those</em> for matches.</p>
<p>Now, the fact that jQuery supports CSS selector syntax comes in really handy. We can pass the matching CSS rules directly to jQuery, and add classes appropriately. Then, any browser supported by jQuery can properly target elements, even useful-but-not-broadly-supported CSS rules like <code>ul li:first</code>. All we need to do to have classes added to match any of the rules in our CSS is include jQuery and the SuperSelectors plugin, and add the following javascript:</p>
<pre>$(document).ready(function() {
  $(document).superSelectify();
});</pre>
<p>This is a great start, but some of us are maintaining sites with established conventions for element classnames. Maybe you&#8217;re working on an educational site, and the <code>child</code> is already reserved for another context. No problem. SuperSelectors will allow custom classes to be passed in, while still providing sensible defaults. You can override any (or all) of the default classnames. If you need to alter the class attached to child elements to be <code>child-element</code>, your javascript would just change to be:</p>
<pre>$(document).ready(function() {
  $(document).superSelectify({childClass: "child-element"});
});</pre>
<h2>Attribution needed</h2>
<p>What about special cases which fall outside the normal advanced selectors? Maybe we need to have styles applied conditionally, based on attributes. For example, maybe the links in your file download list should have an icon based on the extension of the file they&#8217;re pointing to. CSS 2.1 allows us to target elements based on attribute values &#8211; we can even match against substrings within the attribute value, which is a perfect fit for finding the file extensions of our links. The number of potential choices for attribute selectors alone is more than we can reasonably build into a single plugin, but fortunately SuperSelectors supports arbitrary selectors through the <code>additionalElementHash</code> attribute. This can be done with or without overriding the default classnames. A setup which addressed the file-type requirement mentioned above would look like this:</p>
<pre>$(document).ready(function() {
  $(document).superSelectify({additionalElementHash: {jpeg: 'a[href$=".jpg"]', pdf: 'a[href$=".pdf"]', doc: 'a[href$=".doc"]', gif: 'a[href$=".gif"]', xls: 'a[href$=".xls"]', png: 'a[href$=".png"]'}});
});</pre>
<p>A little more effort than the no-argument invocation, but that will enable matching almost any elements you can think of &#8211; you&#8217;re only limited by jQuery&#8217;s selector support, which is one of the best out there.</p>
<h2>Hovercraftiness</h2>
<p>It&#8217;s probably time to acknowledge the elephant in the room &#8211; specifically, the fact that IE6 only supports the <code>:hover</code> pseudo-selector for anchor tags. Through the years, there have been a variety of approaches to add this in, including Peter Nederlof&#8217;s <a href="http://www.xs4all.nl/~peterned/csshover.html">whatever:hover</a>. This is all well and good, but it&#8217;d be nice to be able to have one-stop shopping for all our CSS needs. Fortunately, jQuery makes it easy for us to add this functionality into Super Selectors. Declare your <code>:hover</code> rules normally, add an equivalent rule using the <code>hover</code> class, and SuperSelectors will take care of adding / removing the classnames from elements on mouseover.</p>
<h2>Faster, faster</h2>
<p>Things are really shaping up nicely. Any browser which jQuery supports can now use virtually any legitimate CSS selector, but we can still do better. If we know which advanced selectors our site will need to support, it seems wasteful to have to re-request all those CSS files, and then scan them for matches. In fact, on slow connections, or with sufficiently-large amount of CSS, users could see a page without the added classes for a fraction of a second, similar to the old <a href="http://en.wikipedia.org/wiki/Flash_of_unstyled_content">Flash of Unstyled Content</a> bug.</p>
<p>SuperSelectors makes it simple to avoid the unnecessary request/parsing overhead and display properly-classed markup right away. You just need to pass in all your selectors via the <code>manualSelectors</code> attribute, as a comma-delimited list. As with everything else, it can be used solo or in combination with any other arguments.:</p>
<pre>$(document).ready(function() {
  $(document).superSelectify({childClass: "child-element", manualSelectors: 'div.example > ul, ul.sample li:first, input[type="text"], input[type="password"]'}});
});</pre>
<p>For complex CSS needs, this may require a fair amount of work. However, this approach saves us from having to re-request and parse all the CSS files in use. Consequently, it will be <em>much</em> faster &#8211; especially for sites with large (or large numbers of) CSS files. <a href="http://sandbox.skulljackpot.com/superselectors/demo/">Check out the example</a>.</p>
<h2>One caveat</h2>
<p>SuperSelectors does a lot to help enable better CSS selector support across browsers, but it can&#8217;t do everything for us. We still need rules in our CSS which use the classes SuperSelectors will add.</p>
<p>Because Internet Explorer will discard the entire rule if it doesn&#8217;t understand one of the selectors, we do have to do a little duplication in our CSS. That means that, instead of</p>
<pre>div.example > ul,
div.example ul.child {
background: #0f0;
color: #f0f;
}</pre>
<p>You should write:</p>
<pre>div.example > ul {
background: #0f0;
color: #f0f;
}

div.example ul.child {
background: #0f0;
color: #f0f;
}</pre>
<h2>In Closing</h2>
<p>The goal of SuperSelectors is to make it possible for all of us to start using CSS 2.1 selectors in our everyday work. It doesn&#8217;t have CSS3 support (yet), but SuperSelectors will automatically benefit as jQuery adds support for CSS3 selectors.</p>
<p>You can download SuperSelectors as a <a href="http://github.com/chrispatterson/jquery-super-selectors/zipball/master">zip</a> or <a href="http://github.com/chrispatterson/jquery-super-selectors/tarball/master">tarball</a>. Github also hosts <a href="http://github.com/chrispatterson/jquery-super-selectors/tree/master">the official SuperSelectors repository</a>, if you&#8217;re interested in helping make SuperSelectors even better.</p>
]]></content:encoded>
			<wfw:commentRss>http://skulljackpot.com/2009/04/19/super-css-selector-support-with-jquery/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Negative margins and Internet Explorer: a cautionary tale</title>
		<link>http://skulljackpot.com/2008/10/09/negative-margins-and-internet-explorer-a-cautionary-tale/</link>
		<comments>http://skulljackpot.com/2008/10/09/negative-margins-and-internet-explorer-a-cautionary-tale/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 22:12:01 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Under the hood]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[negative margin]]></category>
		<category><![CDATA[renderbug]]></category>

		<guid isPermaLink="false">http://skulljackpot.com/?p=14</guid>
		<description><![CDATA[<p>When we were getting ready to launch the <a href="http://www.livablestreets.com/">LivableStreets</a> website earlier this year, I ran into an odd renderbug which I've finally had time to write up. The issue I found was that Internet Explorer would cut off portions of an element when negative margins caused it to extend beyond its parent.</p>]]></description>
			<content:encoded><![CDATA[<p>When we were getting ready to launch the <a href="http://www.livablestreets.com/">LivableStreets</a> website earlier this year, I ran into an odd renderbug which I&#8217;ve finally had time to write up. The issue I found was that Internet Explorer would cut off portions of an element when negative margins caused it to extend beyond its parent.</p>
<p>An example will probably help make the issue more clear.</p>
<p>The structure we&#8217;ll use is simple. A &#8220;container&#8221; div wth an explicit width will contain all our content. Each test case will be a &#8220;holder&#8221; div, which contains the paragraphs with negative margins to pull them beyond the boundaries of both parent elements.</p>
<p>In a standards-compliant rendering, elements can be caused to extend beyond containing elements, through the use of negative margins:</p>
<div class="thumbnail"><a href="http://skitch.com/dimmerswitch/2ym1/negative-margin-renderbug-ff3"><img src="http://img.skitch.com/20081009-knxryy3d6f9yfk46742uxxxt11.preview.jpg" alt="negative-margin-renderbug-ff3" /></a></div>
<p>Internet Explorer, of course, plays by different rules. Let&#8217;s start by looking at IE6:</p>
<div class="thumbnail"><a href="http://skitch.com/dimmerswitch/2ypf/microsoft-windows-xp"><img src="http://img.skitch.com/20081009-kq9w6wk27pkucpewy2fpgqj3tm.preview.jpg" alt="Microsoft Windows XP" /></a></div>
<p>When no width is set for the holder div, the paragraphs with negative margins are shown to extend beyond their holder div, but are clipped at the edge of the container div. However, when we explicitly set the width of the holder div to 100%, the paragraphs are clipped at the edge of the <em>holder</em> div &#8211; they&#8217;re not allowed to extend past <strong>any</strong> of the containing elements (more correctly, the <em>content</em> does extend past, but it&#8217;s inappropriately truncated, as though <code>overflow: hidden;</code> were declared on holder divs).</p>
<p>The same results are obtained in our second result set. When we declare the width in pixels, the paragraphs are clipped at the edge of the holder div. When we explicitly declare the width to be auto (same as the default property for block-level elements), content is clipped at the edge of the container div:</p>
<div class="thumbnail"><a href="http://skitch.com/dimmerswitch/2ypt/microsoft-windows-xp"><img src="http://img.skitch.com/20081009-mh75aa2fcbdrsgnkr146jdarpw.preview.jpg" alt="Microsoft Windows XP" /></a></div>
<p>With Internet Explorer 7, we get yet another curveball. IE7 does properly honor the negative left margin in all cases, regardless of whether (or how) we declare a width for the holder div. The <em>right</em> negative-margin isn&#8217;t so lucky. It still gets truncated exactly the same way as IE6:</p>
<div class="thumbnail"><a href="http://skitch.com/dimmerswitch/2ym6/microsoft-windows-xp"><img src="http://img.skitch.com/20081009-m6baux3bxd9mh8hub7tr4qt51x.preview.jpg" alt="Microsoft Windows XP" /></a></div>
<div class="thumbnail"><a href="http://skitch.com/dimmerswitch/2ycq/microsoft-windows-xp"><img src="http://img.skitch.com/20081009-mbeeufx1ij782b1r3f7p9nu76f.preview.jpg" alt="Microsoft Windows XP" /></a></div>
<p>It&#8217;s almost like the dev team created a unit test for left negative margins and decided they were all set.</p>
<p>To their credit, the IE8 team has fixed right negative margins, based on the current beta:</p>
<div class="thumbnail"><a href="http://skitch.com/dimmerswitch/2fpn/microsoft-windows-xp"><img src="http://img.skitch.com/20081009-brudmpxtmjx9bdmxp3mbbwwrhr.preview.jpg" alt="Microsoft Windows XP" /></a></div>
<p>So, if your site has sizable numbers of IE users (which, I think, is most of us), be aware that negative margins can cause unexpected consequences. Explicitly declaring <code>overflow: visible;</code> on holder and container has no impact on the resulting page renders. For the LSN launch, I ended up using relative positioning to achieve the desired affect.</p>
<p>Have a different workaround? I&#8217;d love to hear about it. In the meantime, <a href="http://skulljackpot.com/wp-content/uploads/2008/10/negativemarginrenderbug.html">here&#8217;s the testcase</a> I put together.</p>
]]></content:encoded>
			<wfw:commentRss>http://skulljackpot.com/2008/10/09/negative-margins-and-internet-explorer-a-cautionary-tale/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 4.247 seconds -->

