<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Computed vs Cascaded Style</title>
	<atom:link href="http://erik.eae.net/archives/2007/07/27/18.54.15/feed/" rel="self" type="application/rss+xml" />
	<link>http://erik.eae.net/archives/2007/07/27/18.54.15/</link>
	<description>The Weblog of Erik Arvidsson</description>
	<pubDate>Thu, 28 Aug 2008 23:42:21 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: xErath</title>
		<link>http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-103035</link>
		<dc:creator>xErath</dc:creator>
		<pubDate>Wed, 26 Mar 2008 11:53:36 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-103035</guid>
		<description>Why all the trouble of defining document.defaultView.document.defaultView.document.defaultView.document.defaultView.document.defaultView ??

use .getComputedStyle directly</description>
		<content:encoded><![CDATA[<p>Why all the trouble of defining document.defaultView.document.defaultView.document.defaultView.document.defaultView.document.defaultView ??</p>
<p>use .getComputedStyle directly</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Melikoth</title>
		<link>http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102937</link>
		<dc:creator>Melikoth</dc:creator>
		<pubDate>Fri, 15 Feb 2008 13:49:39 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102937</guid>
		<description>For some reason when I use this it returns "auto" for top and left values.  The object I am interrogating has no styling applied, but I was hopinh it would tell me where it was located.</description>
		<content:encoded><![CDATA[<p>For some reason when I use this it returns &#8220;auto&#8221; for top and left values.  The object I am interrogating has no styling applied, but I was hopinh it would tell me where it was located.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dimitri Glazkov</title>
		<link>http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102509</link>
		<dc:creator>Dimitri Glazkov</dc:creator>
		<pubDate>Wed, 29 Aug 2007 13:23:12 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102509</guid>
		<description>Sorry, I should've escaped the markup:

&#60;body&#62;
&#60;div&#62;
&#60;h1&#62;Yo&#60;/h1&#62;
&#60;/div&#62;
&#60;/body&#62;</description>
		<content:encoded><![CDATA[<p>Sorry, I should&#8217;ve escaped the markup:</p>
<p>&lt;body&gt;<br />
&lt;div&gt;<br />
&lt;h1&gt;Yo&lt;/h1&gt;<br />
&lt;/div&gt;<br />
&lt;/body&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dimitri Glazkov</title>
		<link>http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102508</link>
		<dc:creator>Dimitri Glazkov</dc:creator>
		<pubDate>Wed, 29 Aug 2007 13:21:51 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102508</guid>
		<description>Another interesting tidbit is that computed style does not take into account margin collapse. For instance, the marginTop value reported does not necessarily represent the actual margin value in effect. Quick example:



Yo



Using just default styles, the computed style on body will be 8, but it's not very useful, because the effective margin is 21 (body margin collapsed in favor of h1).</description>
		<content:encoded><![CDATA[<p>Another interesting tidbit is that computed style does not take into account margin collapse. For instance, the marginTop value reported does not necessarily represent the actual margin value in effect. Quick example:</p>
<p>Yo</p>
<p>Using just default styles, the computed style on body will be 8, but it&#8217;s not very useful, because the effective margin is 21 (body margin collapsed in favor of h1).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Links for 8/6/07 [my NetNewsWire tabs]</title>
		<link>http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102354</link>
		<dc:creator>Links for 8/6/07 [my NetNewsWire tabs]</dc:creator>
		<pubDate>Mon, 06 Aug 2007 14:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102354</guid>
		<description>[...] erik’s weblog » Blog Archive » Computed vs Cascaded Style [...]</description>
		<content:encoded><![CDATA[<p>[...] erik’s weblog » Blog Archive » Computed vs Cascaded Style [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yn</title>
		<link>http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102312</link>
		<dc:creator>yn</dc:creator>
		<pubDate>Sat, 04 Aug 2007 04:17:55 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102312</guid>
		<description>Papandreou: In any other browser it's trivial to get the real background color, via getComputedStyle. IE is the only one that makes this a bit of a challenge. 

To create a cross-browser function simply check if the getComputedStyle method exists (FF, Opera, etc.), and if so use it, otherwise see if the createTextRange method exists (IE), and if so use it.

A *real* challenge would be to get the cascaded value ("red", "highlight", etc.) set in external CSS in Firefox.

BTW, Erik: Your article is mistaken. Opera supports .currentStyle properly, allowing you to get the cascaded style (from the article: "Only IE has a way to get the cascaded style.").</description>
		<content:encoded><![CDATA[<p>Papandreou: In any other browser it&#8217;s trivial to get the real background color, via getComputedStyle. IE is the only one that makes this a bit of a challenge. </p>
<p>To create a cross-browser function simply check if the getComputedStyle method exists (FF, Opera, etc.), and if so use it, otherwise see if the createTextRange method exists (IE), and if so use it.</p>
<p>A *real* challenge would be to get the cascaded value (&#8221;red&#8221;, &#8220;highlight&#8221;, etc.) set in external CSS in Firefox.</p>
<p>BTW, Erik: Your article is mistaken. Opera supports .currentStyle properly, allowing you to get the cascaded style (from the article: &#8220;Only IE has a way to get the cascaded style.&#8221;).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Papandreou</title>
		<link>http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102305</link>
		<dc:creator>Papandreou</dc:creator>
		<pubDate>Fri, 03 Aug 2007 14:21:38 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102305</guid>
		<description>@yn: Your getRealBackgroundColor function is really interesting. For different reasons, I've been looking for a way to get the rrggbb values corresponding to a user's CSS system colors, but I actually gave up a while ago.

However, I can only get your code to work in IE. Any chance you know a cross-browser way of accomplishing this?</description>
		<content:encoded><![CDATA[<p>@yn: Your getRealBackgroundColor function is really interesting. For different reasons, I&#8217;ve been looking for a way to get the rrggbb values corresponding to a user&#8217;s CSS system colors, but I actually gave up a while ago.</p>
<p>However, I can only get your code to work in IE. Any chance you know a cross-browser way of accomplishing this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik Arvidsson</title>
		<link>http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102298</link>
		<dc:creator>Erik Arvidsson</dc:creator>
		<pubDate>Mon, 30 Jul 2007 15:52:06 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102298</guid>
		<description>yn: Thanks, the queryCommandValue is a great example how to do this.</description>
		<content:encoded><![CDATA[<p>yn: Thanks, the queryCommandValue is a great example how to do this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yn</title>
		<link>http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102297</link>
		<dc:creator>yn</dc:creator>
		<pubDate>Sun, 29 Jul 2007 12:52:09 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102297</guid>
		<description>Erik: It's not about finding cases where offset* and client* won't be enough, they certainly exist. It's about what's more useful to have if you had to choose one. Why would you need the pixel value of a font set in points? I really can't think of such a scenario. If you want the height of the line in pixels, which would make more sense, that's easy to do. 

On the other hand, I can easily think of multiple scenarios requiring the actual cascaded properties and I've been constantly bumping against these cases, as mentioned above.

Btw, to answer your specific questions:

function getRealBackgroundColor(el) {
    var oRG=document.body.createTextRange();
    oRG.moveToElementText(el);
    var iClr=oRG.queryCommandValue("BackColor");
    return "rgb("+(iClr &#38; 0xFF)+","+((iClr &#38; 0xFF00)&#62;&#62;8)+","+((iClr &#38; 0xFF0000)&#62;&#62;16)+")";
}

Your other question was already answered by Dean, his function can take any value in any unit (except % in some cases) and return it in pixels, it's not limited to .left, he's just using it to do the conversion. so getPixelValue(document.body,"12pt") will give you the pixel value for your font under your setup.

Again, I'm not saying anything everywhere can be converted to an absolute value, I'm just saying that currentStyle is a lot more useful.</description>
		<content:encoded><![CDATA[<p>Erik: It&#8217;s not about finding cases where offset* and client* won&#8217;t be enough, they certainly exist. It&#8217;s about what&#8217;s more useful to have if you had to choose one. Why would you need the pixel value of a font set in points? I really can&#8217;t think of such a scenario. If you want the height of the line in pixels, which would make more sense, that&#8217;s easy to do. </p>
<p>On the other hand, I can easily think of multiple scenarios requiring the actual cascaded properties and I&#8217;ve been constantly bumping against these cases, as mentioned above.</p>
<p>Btw, to answer your specific questions:</p>
<p>function getRealBackgroundColor(el) {<br />
    var oRG=document.body.createTextRange();<br />
    oRG.moveToElementText(el);<br />
    var iClr=oRG.queryCommandValue(&#8221;BackColor&#8221;);<br />
    return &#8220;rgb(&#8221;+(iClr &amp; 0xFF)+&#8221;,&#8221;+((iClr &amp; 0xFF00)&gt;&gt;8)+&#8221;,&#8221;+((iClr &amp; 0xFF0000)&gt;&gt;16)+&#8221;)&#8221;;<br />
}</p>
<p>Your other question was already answered by Dean, his function can take any value in any unit (except % in some cases) and return it in pixels, it&#8217;s not limited to .left, he&#8217;s just using it to do the conversion. so getPixelValue(document.body,&#8221;12pt&#8221;) will give you the pixel value for your font under your setup.</p>
<p>Again, I&#8217;m not saying anything everywhere can be converted to an absolute value, I&#8217;m just saying that currentStyle is a lot more useful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: All in a days work&#8230;</title>
		<link>http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102294</link>
		<dc:creator>All in a days work&#8230;</dc:creator>
		<pubDate>Sun, 29 Jul 2007 01:26:17 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102294</guid>
		<description>[...] Computed vs Cascaded Style The offset* and client* functions provide nearly everything you want for getting the pixel values, and the difference between them helps you calculate padding/border values. I’ve rarely seen anyone opt for computed style in such situations, even for FF. [...]</description>
		<content:encoded><![CDATA[<p>[...] Computed vs Cascaded Style The offset* and client* functions provide nearly everything you want for getting the pixel values, and the difference between them helps you calculate padding/border values. I’ve rarely seen anyone opt for computed style in such situations, even for FF. [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
