<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: CSS Computed Style</title>
	<atom:link href="http://blog.stchur.com/2006/06/21/css-computed-style/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.stchur.com/2006/06/21/css-computed-style/</link>
	<description>web / programming / javascript / css / html</description>
	<lastBuildDate>Thu, 11 Mar 2010 00:46:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Rob</title>
		<link>http://blog.stchur.com/2006/06/21/css-computed-style/comment-page-1/#comment-11416</link>
		<dc:creator>Rob</dc:creator>
		<pubDate>Sun, 15 Mar 2009 17:30:39 +0000</pubDate>
		<guid isPermaLink="false">http://stchur.com/blog2/2006/06/21/css-computed-style/#comment-11416</guid>
		<description>I had a similar problem the other day requiring the computed style in px not the currentStyle or style value The following function seems to correctly convert the style to px and ems and also handles styles in % and child elements where the parent is in % but the child is set to &quot;auto&quot;.

http://www.strictly-software.com/CSSStyleObject.asp</description>
		<content:encoded><![CDATA[<p>I had a similar problem the other day requiring the computed style in px not the currentStyle or style value The following function seems to correctly convert the style to px and ems and also handles styles in % and child elements where the parent is in % but the child is set to &#034;auto&#034;.</p>
<p><a href="http://www.strictly-software.com/CSSStyleObject.asp" rel="nofollow">http://www.strictly-software.com/CSSStyleObject.asp</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dynamic Background Image &#171; My Vietnam</title>
		<link>http://blog.stchur.com/2006/06/21/css-computed-style/comment-page-1/#comment-10153</link>
		<dc:creator>Dynamic Background Image &#171; My Vietnam</dc:creator>
		<pubDate>Sun, 08 Feb 2009 11:09:16 +0000</pubDate>
		<guid isPermaLink="false">http://stchur.com/blog2/2006/06/21/css-computed-style/#comment-10153</guid>
		<description>[...] https://developer.mozilla.org/en/DOM/window.getComputedStyle  http://blog.stchur.com/2006/06/21/css-computed-style  http://www.hanselman.com/blog/jQueryToShipWithASPNETMVCAndVisualStudio.aspx  [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="https://developer.mozilla.org/en/DOM/window.getComputedStyle" rel="nofollow">https://developer.mozilla.org/en/DOM/window.getComputedStyle</a>  <a href="http://blog.stchur.com/2006/06/21/css-computed-style" rel="nofollow">http://blog.stchur.com/2006/06/21/css-computed-style</a>  <a href="http://www.hanselman.com/blog/jQueryToShipWithASPNETMVCAndVisualStudio.aspx" rel="nofollow">http://www.hanselman.com/blog/jQueryToShipWithASPNETMVCAndVisualStudio.aspx</a>  [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bookmarklet to de-cache CSS and images - Version 2 &#171; Zeroed &#38; Noughted</title>
		<link>http://blog.stchur.com/2006/06/21/css-computed-style/comment-page-1/#comment-8819</link>
		<dc:creator>Bookmarklet to de-cache CSS and images - Version 2 &#171; Zeroed &#38; Noughted</dc:creator>
		<pubDate>Wed, 07 Jan 2009 23:35:38 +0000</pubDate>
		<guid isPermaLink="false">http://stchur.com/blog2/2006/06/21/css-computed-style/#comment-8819</guid>
		<description>[...] Getting the current values of styles set via CSS can be a pain. Unless they were explicitly set via JavaScript, we can only fetch them using currentStyle or getComputedStyle, complete of course with their own browser idiosyncrasies. Therefore, the first thing we need is a function to do this for us in a cross-browser fashion. I have amended a version I found on Incoherent Babble. [...]</description>
		<content:encoded><![CDATA[<p>[...] Getting the current values of styles set via CSS can be a pain. Unless they were explicitly set via JavaScript, we can only fetch them using currentStyle or getComputedStyle, complete of course with their own browser idiosyncrasies. Therefore, the first thing we need is a function to do this for us in a cross-browser fashion. I have amended a version I found on Incoherent Babble. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Melody Pedzisai</title>
		<link>http://blog.stchur.com/2006/06/21/css-computed-style/comment-page-1/#comment-1461</link>
		<dc:creator>Melody Pedzisai</dc:creator>
		<pubDate>Thu, 10 Jul 2008 20:47:03 +0000</pubDate>
		<guid isPermaLink="false">http://stchur.com/blog2/2006/06/21/css-computed-style/#comment-1461</guid>
		<description>Yes you are correct. Its a lot neater to do it that way. Thanks much for your help. I am all setup now with a few tweaks on the GWT side.</description>
		<content:encoded><![CDATA[<p>Yes you are correct. Its a lot neater to do it that way. Thanks much for your help. I am all setup now with a few tweaks on the GWT side.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sstchur</title>
		<link>http://blog.stchur.com/2006/06/21/css-computed-style/comment-page-1/#comment-1449</link>
		<dc:creator>sstchur</dc:creator>
		<pubDate>Wed, 09 Jul 2008 21:27:18 +0000</pubDate>
		<guid isPermaLink="false">http://stchur.com/blog2/2006/06/21/css-computed-style/#comment-1449</guid>
		<description>Melody,

Re: the property name has to be passed as an ecmascript binding value

That is true if you use .getPropertyValue, but I have found that using [styleProperty] has worked well for me in most cases, and all browsers use the property name in camelCase (without the dash), I believe.</description>
		<content:encoded><![CDATA[<p>Melody,</p>
<p>Re: the property name has to be passed as an ecmascript binding value</p>
<p>That is true if you use .getPropertyValue, but I have found that using [styleProperty] has worked well for me in most cases, and all browsers use the property name in camelCase (without the dash), I believe.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Melody Pedzisai</title>
		<link>http://blog.stchur.com/2006/06/21/css-computed-style/comment-page-1/#comment-1446</link>
		<dc:creator>Melody Pedzisai</dc:creator>
		<pubDate>Wed, 09 Jul 2008 16:16:26 +0000</pubDate>
		<guid isPermaLink="false">http://stchur.com/blog2/2006/06/21/css-computed-style/#comment-1446</guid>
		<description>OK so the site is defensive I cant show you the html. You get the idea</description>
		<content:encoded><![CDATA[<p>OK so the site is defensive I cant show you the html. You get the idea</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Melody Pedzisai</title>
		<link>http://blog.stchur.com/2006/06/21/css-computed-style/comment-page-1/#comment-1445</link>
		<dc:creator>Melody Pedzisai</dc:creator>
		<pubDate>Wed, 09 Jul 2008 16:15:26 +0000</pubDate>
		<guid isPermaLink="false">http://stchur.com/blog2/2006/06/21/css-computed-style/#comment-1445</guid>
		<description>I noticed that the HTML is not showing so I am trying to paste it without surrounding with &lt;code&gt;&lt;/code&gt; blocks

Here:



	        
	getComputedStyle table margin bug
	
	table{margin:100px;}
	.wrapper {      
		margin: 5px;
		padding: 10px 10px 10px 10px;    
		background-color:#dfe8f6;/*#c3daf9*/
		border: 1px solid magenta; /*TODO*/  
		display: block;
		width: 1920px;width: 1920px !important;
		height: 1022px;height: 1022px !important;
    }
	
    
	function getStyle(oElm, strCssRule){
	var strValue = &quot;&quot;;
	if(document.defaultView &amp;&amp; document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, &quot;&quot;).getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

	

</description>
		<content:encoded><![CDATA[<p>I noticed that the HTML is not showing so I am trying to paste it without surrounding with <code></code> blocks</p>
<p>Here:</p>
<p>	getComputedStyle table margin bug</p>
<p>	table{margin:100px;}<br />
	.wrapper {<br />
		margin: 5px;<br />
		padding: 10px 10px 10px 10px;<br />
		background-color:#dfe8f6;/*#c3daf9*/<br />
		border: 1px solid magenta; /*TODO*/<br />
		display: block;<br />
		width: 1920px;width: 1920px !important;<br />
		height: 1022px;height: 1022px !important;<br />
    }</p>
<p>	function getStyle(oElm, strCssRule){<br />
	var strValue = &#034;&#034;;<br />
	if(document.defaultView &amp;&amp; document.defaultView.getComputedStyle){<br />
		strValue = document.defaultView.getComputedStyle(oElm, &#034;&#034;).getPropertyValue(strCssRule);<br />
	}<br />
	else if(oElm.currentStyle){<br />
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){<br />
			return p1.toUpperCase();<br />
		});<br />
		strValue = oElm.currentStyle[strCssRule];<br />
	}<br />
	return strValue;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Melody Pedzisai</title>
		<link>http://blog.stchur.com/2006/06/21/css-computed-style/comment-page-1/#comment-1444</link>
		<dc:creator>Melody Pedzisai</dc:creator>
		<pubDate>Wed, 09 Jul 2008 16:13:26 +0000</pubDate>
		<guid isPermaLink="false">http://stchur.com/blog2/2006/06/21/css-computed-style/#comment-1444</guid>
		<description>Thanks sstchur.
I tried it in a watered down html page and it works just fine in IE and fireFox. I think there is a problem with the CSS styles on the element when I pass it from GWT to JavaScript using JSNI. It simply wont recognize any properties. 

Back to square one!

The one thing that I would just add that seems not too clear in your code is that in fireFox, the property name has to be passed as an ecmascript binding value ie. border-bottom, whereas in IE you have to pass the property name without the dash ie. borderBottom. So I found some code somewhere for removing the dash and making the letter after it uppercase. 

&lt;code&gt;



	        
	getComputedStyle table margin bug
	
	table{margin:100px;}
	.wrapper {      
		margin: 5px;
		padding: 10px 10px 10px 10px;    
		background-color:#dfe8f6;/*#c3daf9*/
		border: 1px solid magenta; /*TODO*/  
		display: block;
		width: 1920px;width: 1920px !important;
		height: 1022px;height: 1022px !important;
    }
	
    
	function getStyle(oElm, strCssRule){
	var strValue = &quot;&quot;;
	if(document.defaultView &amp;&amp; document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, &quot;&quot;).getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

	




  
   
            
      
      
          
      
        
             YYYYYYYYYYYYYYYY
         

Actual margin is set to 100px

var foo = document.getElementById(&#039;wrapper&#039;);
alert(&#039;Padding-Right: &#039;+ getStyle(foo, &#039;padding-right&#039;));
alert(&#039;Margin-Right: &#039;+ getStyle(foo, &#039;margin-right&#039;));



&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Thanks sstchur.<br />
I tried it in a watered down html page and it works just fine in IE and fireFox. I think there is a problem with the CSS styles on the element when I pass it from GWT to JavaScript using JSNI. It simply wont recognize any properties. </p>
<p>Back to square one!</p>
<p>The one thing that I would just add that seems not too clear in your code is that in fireFox, the property name has to be passed as an ecmascript binding value ie. border-bottom, whereas in IE you have to pass the property name without the dash ie. borderBottom. So I found some code somewhere for removing the dash and making the letter after it uppercase. </p>
<p><code></code></p>
<p>	getComputedStyle table margin bug</p>
<p>	table{margin:100px;}<br />
	.wrapper {<br />
		margin: 5px;<br />
		padding: 10px 10px 10px 10px;<br />
		background-color:#dfe8f6;/*#c3daf9*/<br />
		border: 1px solid magenta; /*TODO*/<br />
		display: block;<br />
		width: 1920px;width: 1920px !important;<br />
		height: 1022px;height: 1022px !important;<br />
    }</p>
<p>	function getStyle(oElm, strCssRule){<br />
	var strValue = "";<br />
	if(document.defaultView &amp;&amp; document.defaultView.getComputedStyle){<br />
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);<br />
	}<br />
	else if(oElm.currentStyle){<br />
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){<br />
			return p1.toUpperCase();<br />
		});<br />
		strValue = oElm.currentStyle[strCssRule];<br />
	}<br />
	return strValue;<br />
}</p>
<p>             YYYYYYYYYYYYYYYY</p>
<p>Actual margin is set to 100px</p>
<p>var foo = document.getElementById('wrapper');<br />
alert('Padding-Right: '+ getStyle(foo, 'padding-right'));<br />
alert('Margin-Right: '+ getStyle(foo, 'margin-right'));</p>
<p></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sstchur</title>
		<link>http://blog.stchur.com/2006/06/21/css-computed-style/comment-page-1/#comment-1441</link>
		<dc:creator>sstchur</dc:creator>
		<pubDate>Wed, 09 Jul 2008 14:06:44 +0000</pubDate>
		<guid isPermaLink="false">http://stchur.com/blog2/2006/06/21/css-computed-style/#comment-1441</guid>
		<description>Melody:

I&#039;m not that familiar with GWT (not at all really), but I wonder if, as you pointed out, the -moz specific CSS could be having an effect.

&lt;p&gt;Have you tried just created a plain HTML page with some similar CSS and tried using my getComputedStyle function in that context?  I&#039;d be interested to see if this is somehow related to GWT, or if this is truly a bug in my code (if it&#039;s the latter, it definitely needs ot be fixed, but so far it has worked for me).&lt;/p&gt;

&lt;p&gt;The Gimme version comes packaged with the Gimme library:  http://codeplex.com/gimme/&lt;/p&gt;

&lt;p&gt;However, you could probably rip out that function by pulling it from the source:  http://www.codeplex.com/gimme/SourceControl/FileView.aspx?itemId=168513&amp;changeSetId=18894&lt;/p&gt;

&lt;p&gt;You will also need to grab the function, convertToPixels, as getStyle uses it.&lt;/p&gt;

&lt;p&gt;I would suggest doing some troubleshooting in a plain HTML page first though, before going any further.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Melody:</p>
<p>I&#039;m not that familiar with GWT (not at all really), but I wonder if, as you pointed out, the -moz specific CSS could be having an effect.</p>
<p>Have you tried just created a plain HTML page with some similar CSS and tried using my getComputedStyle function in that context?  I&#039;d be interested to see if this is somehow related to GWT, or if this is truly a bug in my code (if it&#039;s the latter, it definitely needs ot be fixed, but so far it has worked for me).</p>
<p>The Gimme version comes packaged with the Gimme library:  <a href="http://codeplex.com/gimme/" rel="nofollow">http://codeplex.com/gimme/</a></p>
<p>However, you could probably rip out that function by pulling it from the source:  <a href="http://www.codeplex.com/gimme/SourceControl/FileView.aspx?itemId=168513&#038;changeSetId=18894" rel="nofollow">http://www.codeplex.com/gimme/SourceControl/FileView.aspx?itemId=168513&#038;changeSetId=18894</a></p>
<p>You will also need to grab the function, convertToPixels, as getStyle uses it.</p>
<p>I would suggest doing some troubleshooting in a plain HTML page first though, before going any further.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Melody Pedzisai</title>
		<link>http://blog.stchur.com/2006/06/21/css-computed-style/comment-page-1/#comment-1440</link>
		<dc:creator>Melody Pedzisai</dc:creator>
		<pubDate>Wed, 09 Jul 2008 13:30:34 +0000</pubDate>
		<guid isPermaLink="false">http://stchur.com/blog2/2006/06/21/css-computed-style/#comment-1440</guid>
		<description>Thanks.

My code is not pure JavaScript (its GWT JSNI) but here its is. 

The JSNI code
&lt;code&gt;
public static native String JSNIGetStyleProperty(Element _elem, String _style)  /*-{
      if (_style==&#039;width&#039;) {
          return _elem.offsetWidth;                                                                                    
      }
      if (_style==&#039;height&#039;) {
          return _elem.offsetHeight ;                                                                                    
       }                                                                                    
      var computedStyle;
      if (typeof _elem.currentStyle != &#039;undefined&#039;)
      { 
         computedStyle = _elem.currentStyle; 
         return computedStyle[_style]; 
      }
      else
      {
         computedStyle = document.defaultView.getComputedStyle(_elem, null);   
         return computedStyle[_style];                    
      }                                                                                        
    }-*/;        
&lt;/code&gt;


The client code that calls the JSNI code. This is Java (GWT)code
&lt;code&gt;
 public static int getElementMarginAndBorderAndPaddingHorz(Element e) {                   
        int tp = JSNIUtils.getIntStyleProperty(e, &quot;paddingLeft&quot;);                
        int bp= JSNIUtils.getIntStyleProperty(e, &quot;paddingRight&quot;);
        int tbw = JSNIUtils.getIntStyleProperty(e, &quot;borderLeftWidth&quot;);
        int bbw = JSNIUtils.getIntStyleProperty(e, &quot;borderRightWidth&quot;);        
        tp  += JSNIUtils.getIntStyleProperty(e, &quot;marginLeft&quot;);                
        bp  += JSNIUtils.getIntStyleProperty(e, &quot;marginRight&quot;);        
        int w = (tp + bp) + (tbw + bbw);
        return w;     
   }
&lt;/code&gt;


And the CSS style for the element for which I am trying to determine the element&#039;s edges 

&lt;code&gt;
.wrapper {      
    margin: 5px;
    padding: 5px 5px 5px 5px;    
    background-color:#dfe8f6;
    border: 1px solid magenta;
}
&lt;/code&gt;


Also the top of the CSS file says has some magic that may be relevant. The CSS file itself is huge so I will just show snippets of the area that applies.

&lt;code&gt;
@charset &quot;utf-8&quot;;
*{
    -moz-box-sizing:border-box;box-sizing:border-box;margin:0px;padding:0px;
}
body {
  color: #000000;
  font-family: Tahoma, Arial, Helvetica, sans-serif;
  font-size:  76%;
  margin: 0px 0px 0px 0px;
}
&lt;/code&gt;


Where can I find the version you are referring to?

Thanks, 

Melody</description>
		<content:encoded><![CDATA[<p>Thanks.</p>
<p>My code is not pure JavaScript (its GWT JSNI) but here its is. </p>
<p>The JSNI code<br />
<code><br />
public static native String JSNIGetStyleProperty(Element _elem, String _style)  /*-{<br />
      if (_style=='width') {<br />
          return _elem.offsetWidth;<br />
      }<br />
      if (_style=='height') {<br />
          return _elem.offsetHeight ;<br />
       }<br />
      var computedStyle;<br />
      if (typeof _elem.currentStyle != 'undefined')<br />
      {<br />
         computedStyle = _elem.currentStyle;<br />
         return computedStyle[_style];<br />
      }<br />
      else<br />
      {<br />
         computedStyle = document.defaultView.getComputedStyle(_elem, null);<br />
         return computedStyle[_style];<br />
      }<br />
    }-*/;<br />
</code></p>
<p>The client code that calls the JSNI code. This is Java (GWT)code<br />
<code><br />
 public static int getElementMarginAndBorderAndPaddingHorz(Element e) {<br />
        int tp = JSNIUtils.getIntStyleProperty(e, "paddingLeft");<br />
        int bp= JSNIUtils.getIntStyleProperty(e, "paddingRight");<br />
        int tbw = JSNIUtils.getIntStyleProperty(e, "borderLeftWidth");<br />
        int bbw = JSNIUtils.getIntStyleProperty(e, "borderRightWidth");<br />
        tp  += JSNIUtils.getIntStyleProperty(e, "marginLeft");<br />
        bp  += JSNIUtils.getIntStyleProperty(e, "marginRight");<br />
        int w = (tp + bp) + (tbw + bbw);<br />
        return w;<br />
   }<br />
</code></p>
<p>And the CSS style for the element for which I am trying to determine the element&#039;s edges </p>
<p><code><br />
.wrapper {<br />
    margin: 5px;<br />
    padding: 5px 5px 5px 5px;<br />
    background-color:#dfe8f6;<br />
    border: 1px solid magenta;<br />
}<br />
</code></p>
<p>Also the top of the CSS file says has some magic that may be relevant. The CSS file itself is huge so I will just show snippets of the area that applies.</p>
<p><code><br />
@charset "utf-8";<br />
*{<br />
    -moz-box-sizing:border-box;box-sizing:border-box;margin:0px;padding:0px;<br />
}<br />
body {<br />
  color: #000000;<br />
  font-family: Tahoma, Arial, Helvetica, sans-serif;<br />
  font-size:  76%;<br />
  margin: 0px 0px 0px 0px;<br />
}<br />
</code></p>
<p>Where can I find the version you are referring to?</p>
<p>Thanks, </p>
<p>Melody</p>
]]></content:encoded>
	</item>
</channel>
</rss>
