<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/css/fallback.css" ?>
<?xml-stylesheet type="text/xsl" href="/xsl/layout.xsl" ?>
<e:CONTENT xmlns:e="http://www.echoofeden.com/schema/e" xmlns="http://www.w3.org/1999/xhtml" start="6" days="30" month="June" root="DIGEST" level1="mit" level2="2007" level3="06" level4="11" level5="ie7-uncle-double-class-selector-bug">
	<h2 class="xslError"><a href="no-xsl/">Enter Here</a></h2>

		<e:TITLE url="http://www.echoofeden.com/digest/mit/2007/06/11/ie7-uncle-double-class-selector-bug/">IE7 Uncle Double Class Selector Bug</e:TITLE>
	<e:AUTHOR>Mit The Destroyer</e:AUTHOR>
	<e:HTML>
		<div class="entry" id="post-257">
			<p>While debugging some code on a site I work on. I discovered a new double class bug in IE7. The weird thing about it is the code that causes the double class bug to appear is not even related to it. <a href="/htmlTests/IE7UncleDoubleClassBug/">Sample Test case:</a></p>
<p><code><br/>
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"<br/>
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;<br/>
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;<br/>
&lt;head&gt;<br/>
	&lt;title&gt;IE7 Uncle Double Class Selector Bug&lt;/title&gt;<br/>
	&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;<br/>
	&lt;meta http-equiv="Content-Style-Type" content="text/css" /&gt;<br/>
	&lt;style type="text/css" media="screen"&gt;<br/>
		p {<br/>
			color: red;<br/>
		}<br/>
		.class1.class2 p {<br/>
			color: green;<br/>
		}<br/>
		.foo + p { }<br/>
	&lt;/style&gt;<br/>
&lt;/head&gt;<br/>
&lt;body&gt;<br/>
	&lt;div class="class1 class2"&gt;<br/>
		&lt;p&gt;I’m Green&lt;/p&gt;<br/>
		&lt;p&gt;I’m Green Too&lt;/p&gt;<br/>
	&lt;/div&gt;<br/>
	&lt;p&gt;I’m red&lt;/p&gt;<br/>
&lt;/body&gt;<br/>
&lt;/html&gt;<br/>
</code></p>
<p>I’ve set all paragraphs to default to the color red. However, due to the double class selector changing its children’s paragraphs to green, and also creating a select any element that has the class foo, whose siblings are paragraphs (doesn’t matter if you set styles or not in that selector, or if the .foo is changed to * or to an element selector that is the same element as the parent with the double class selector [e.g. * + p {}, or div + {}]) it will cause IE7 to create a symbiotic relationship between “.class1.class2 p:last-child” and “.class1.class2 + p:first-of-type”. Thus, if you set styles on “.class1.class2 + p:first-of-type” it will cause “.class1.class2 p:last-child” to get those same styles (and visa versa). Luckily there are a couple work a rounds (ordered by effectiveness).</p>
<ol>
<li>Don’t use any sibling selectors in your styles</li>
<li>Add any type of DOM node between .class1.class2 and it’s sibling p, so long as it’s not a plain text node (e.g. you can use a comment tag or empty element node with style set to display: none;). </li>
<li>Add an inline style declaration on the effected element that overrides the style set on the “.class1.class2 p” selector.</li>
<li>Change the “.class3 + p” selector to be an element + p selector, so long as the element to the left of the + is not the same element type that would get selected by the double class selector. In other words with the test case above you can use any element + p combination  except for div + p</li>
<li>Change the “.foo + p” selector to ” #foo + p” selector</li>
<li>Change the double class selector to a single class selector (e.g. change “.class1.class2 p” to “.class2 p” or “.class1 p” (this solution only works so long as you don’t have any * + p selectors).</li>
</ol>
		<ul class="meta">
			<li class="date">2007/06/11</li>
			<li class="time">1702</li>
			<li class="cat">
					<a href="/digest/category/technology/" title="View all posts in Technology" rel="category tag">Technology</a></li>
			<li class="cmt"> 
			Comments Closed					
			</li>
		</ul>
		</div>
				<p class="nocomments">Comments are closed.</p>
			 
	</e:HTML>
	<e:CALENDAR><table id="wp-calendar">
    <caption>June 2007</caption>
    <thead>
    <tr>
		<th abbr="Sunday" scope="col" title="Sunday">S</th>
		<th abbr="Monday" scope="col" title="Monday">M</th>
		<th abbr="Tuesday" scope="col" title="Tuesday">T</th>
		<th abbr="Wednesday" scope="col" title="Wednesday">W</th>
		<th abbr="Thursday" scope="col" title="Thursday">T</th>
		<th abbr="Friday" scope="col" title="Friday">F</th>
		<th abbr="Saturday" scope="col" title="Saturday">S</th>
    </tr>
    </thead>
    <tfoot>
    <tr>
		<td abbr="March" colspan="3" id="prev"><a href="http://www.echoofeden.com/digest/mit/2007/03/" title="View posts for March 2007">« Mar</a></td>
		<td class="pad"/>
		<td abbr="August" colspan="3" id="next"><a href="http://www.echoofeden.com/digest/mit/2007/08/" title="View posts for August 2007">Aug »</a></td>
    </tr>
    </tfoot>
    <tbody>
    <tr>
		<td colspan="5" class="pad"/><td>1</td><td>2</td>
	</tr>
	<tr>
		<td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td>
	</tr>
	<tr>
		<td>10</td><td><a href="http://www.echoofeden.com/digest/mit/2007/06/11/" title="IE7 Uncle Double Class Selector Bug">11</a></td><td>12</td><td>13</td><td>14</td><td>15</td><td>16</td>
	</tr>
	<tr>
		<td>17</td><td>18</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td>
	</tr>
	<tr>
		<td>24</td><td>25</td><td>26</td><td>27</td><td>28</td><td>29</td><td>30</td>
	</tr>
	</tbody>
	</table></e:CALENDAR>
</e:CONTENT>
