<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss1full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
<channel rdf:about="http://www.decodize.com">
	<title>Decodize</title>
	<link>http://www.decodize.com</link>
	<description>Bits of front-end development</description>
	<dc:date>2012-02-19T11:49:40Z</dc:date>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
	<admin:generatorAgent rdf:resource="http://wordpress.org/?v=3.3.1" />
	<items>
		<rdf:Seq>
					<rdf:li rdf:resource="http://www.decodize.com/css/centering-an-element-with-percentage-height-width-using-css/" />
					<rdf:li rdf:resource="http://www.decodize.com/uncategorized/world-2/" />
				</rdf:Seq>
	</items>
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rdf+xml" href="http://feeds.feedburner.com/Decodize" /><feedburner:info uri="decodize" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>Decodize</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname></channel>
<item rdf:about="http://www.decodize.com/css/centering-an-element-with-percentage-height-width-using-css/">
	<title>Centering an element with percentage height &amp; width using CSS [Experiment]</title>
	<link>http://feedproxy.google.com/~r/Decodize/~3/a2SjxB-94Bk/</link>
	 <dc:date>2012-02-19T11:49:40Z</dc:date>
	<dc:creator>admin</dc:creator>
			<dc:subject><![CDATA[CSS]]></dc:subject>
		<dc:subject><![CDATA[HTML]]></dc:subject>
	<description>Its just a quick post on a small issue I came across, when trying to center a div using absolute. There are couple of methods to make an element center. Quick way is to make it absolute &amp; give 50% … <a href="http://www.decodize.com/css/centering-an-element-with-percentage-height-width-using-css/">Continue reading <span class="meta-nav">→</span></a></description>
	<content:encoded><![CDATA[<p>Its just a quick post on a small issue I came across, when trying to center a div using absolute. There are couple of methods to make an element center. Quick way is to make it absolute &#038; give 50% top &#038; left and negate margin top &#038; left with a value half of the width &#038; height of the element. </p>
<p><strong>Eg:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*CSS*/</span>
<span style="color: #cc00cc;">#box</span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-100px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">-100px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&lt;!-- HTML --<span style="color: #00AA00;">&gt;</span>
&lt;div id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;box&quot;</span><span style="color: #00AA00;">&gt;</span>
&nbsp;
&lt;/div<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p>Above code will work in all browsers flawlessly. But consider the following css.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*CSS*/</span>
<span style="color: #cc00cc;">#box</span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*Changed to percentage width*/</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*Changed to percentage height*/</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-25%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">-25%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&lt;!-- HTML --<span style="color: #00AA00;">&gt;</span>
&lt;div id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;box&quot;</span><span style="color: #00AA00;">&gt;</span>
&nbsp;
&lt;/div<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p>This code will fail in Firefox &#038; Opera. Other browsers it just works fine. There is a work around to make it center. Check the following code.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*CSS*/</span>
<span style="color: #cc00cc;">#box</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-25%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#newBox</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">-50%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">green</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&lt;!-- HTML --<span style="color: #00AA00;">&gt;</span>
&lt;div id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;box&quot;</span><span style="color: #00AA00;">&gt;</span>
     &lt;div id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;newBox&quot;</span><span style="color: #00AA00;">&gt;</span>
      &lt;/div<span style="color: #00AA00;">&gt;</span>
&lt;/div<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p>This code will center the newBox in all browsers. Responsive centering. Automatically adjust with container width.</p>
<p><a href="http://jsfiddle.net/cEDXx/12/" title="http://jsfiddle.net/cEDXx/12/">Check it on jsFddle</a></p>
<img src="http://feeds.feedburner.com/~r/Decodize/~4/a2SjxB-94Bk" height="1" width="1"/>]]></content:encoded>
	<feedburner:origLink>http://www.decodize.com/css/centering-an-element-with-percentage-height-width-using-css/</feedburner:origLink></item>
<item rdf:about="http://www.decodize.com/uncategorized/world-2/">
	<title>Hello World!!</title>
	<link>http://feedproxy.google.com/~r/Decodize/~3/mY812ZxyDR0/</link>
	 <dc:date>2011-12-31T19:56:59Z</dc:date>
	<dc:creator>admin</dc:creator>
			<dc:subject><![CDATA[Uncategorized]]></dc:subject>
	<description>After a long time I’m again starting my blog. This theme is Splendio 1.1 developed by DesignDisease (Elena &amp; Vlad Scanteie). I have customized it a bit. To know about me check here.</description>
	<content:encoded><![CDATA[<p>After a long time I&#8217;m again starting my blog. This theme is Splendio 1.1 developed by DesignDisease (Elena &#038; Vlad Scanteie). I have customized it a bit. To know about me check <a href="http://www.decodize.com/about/">here</a>.</p>
<img src="http://feeds.feedburner.com/~r/Decodize/~4/mY812ZxyDR0" height="1" width="1"/>]]></content:encoded>
	<feedburner:origLink>http://www.decodize.com/uncategorized/world-2/</feedburner:origLink></item>
</rdf:RDF>

