<?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>crimulus-dot-com &#187; tag</title>
	<atom:link href="http://www.crimulus.com/tag/tag/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.crimulus.com</link>
	<description>A blog; ineptly autobiographical</description>
	<lastBuildDate>Sun, 29 Jan 2012 10:20:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CSS Vertical Centering on Variable Dimensions!</title>
		<link>http://www.crimulus.com/2009/02/11/css-vertical-centering-on-variable-dimensions/</link>
		<comments>http://www.crimulus.com/2009/02/11/css-vertical-centering-on-variable-dimensions/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 00:51:04 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css style]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[div element]]></category>
		<category><![CDATA[divs]]></category>
		<category><![CDATA[element]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[HECK]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[style text]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[variable width]]></category>
		<category><![CDATA[vertical centering]]></category>
		<category><![CDATA[vertical-align]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[width]]></category>

		<guid isPermaLink="false">http://www.coffeecuphalfmoons.com/?p=62</guid>
		<description><![CDATA[So maybe you&#8217;ve asked yourself, how in the HECK do I do vertical centering with variable width objects inside variable width objects?  It is insanely impossible.  Maybe you haven&#8217;t asked yourself the question, but you&#8217;re about to learn the answer. Many people who wrote HTML back in the day remember the valign=&#8221;middle&#8221; tag from tables.  [...]]]></description>
			<content:encoded><![CDATA[<p>So maybe you&#8217;ve asked yourself, how in the HECK do I do vertical centering with variable width objects inside variable width objects?  It is insanely impossible.  Maybe you haven&#8217;t asked yourself the question, but you&#8217;re about to learn the answer.</p>
<p>Many people who wrote HTML back in the day remember the valign=&#8221;middle&#8221; tag from tables.  It was always easy to handle centering in tables.  In divs and boxes, however, it&#8217;s not so straight forward.  In face, the only somewhat relevant css tag is &#8220;vertical-align.&#8221;</p>
<p>Of course, many many people completely misunderstands what the vertical align tag is for.  It has nothing to do with vertical centering within an object.  It refers to how side-by-side objects center related to one another.</p>
<p>This article really has nothing to do with what vertical-align means, but it is certainly relevant to the above solution.  If you&#8217;re having trouble with vertical-align, google it and you&#8217;ll find a bajillions explanations.</p>
<p>So, the little snippet of brilliance I want you to see here is that, in fact, CSS DOES provide a way to do vertical centering.  What?  Didn&#8217;t you just say that it doesn&#8217;t?  I did.  But there is a pretty easy exploit, thanks to vertical-align.</p>
<p>So without any further buildup, here is the solution:</p>
<p>1.)  Use a strict doctype, because if you don&#8217;t, you&#8217;re an idiot.  <img src='http://www.crimulus.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   j/k &#8212; if you don&#8217;t understand, check google.  I personally prefer HTML 1.0 strict, but use as you wish.</p>
<p>2.) Create a &#8220;div&#8221; element &#8212; any size, but definitely use a set width and height (px, em, % &#8212; it&#8217;s irrelevant).  It should have the css style &#8220;text-align: center; white-space: nowrap;&#8221; (I&#8217;m presuming, of course, that you want horizontal centering as well.  If not, substitute left or right &#8212; it makes no difference.)</p>
<p>3.) Create an element inside the div with the following style:  &#8220;vertical-align: middle&#8221;  Woohoo we&#8217;re done right??  No &#8230; not yet.  The object now has to be vertically centered to something.  And, intuitively, if somehow there were an object that is 100% in height and we were vertically centered to that, we&#8217;d be in business.</p>
<p>HEY WAIT A MINUTE!!!</p>
<p>4.) Now create a div inside your element with the following css style:  &#8220;display: inline-block; height: 100%; width: 0px; vertical-align: middle;&#8221;.</p>
<p><code>&lt;div style="width: 150px; height: 90px; position: relative; text-align: center; background-color: pink; white-space: nowrap;"&gt;<br />
&lt;div style="display: inline-block; height: 100%; width: 0px; vertical-align: middle"&gt;&lt;/div&gt;<br />
&lt;div style="width: 22%; height: 11%; background-color: skyblue; vertical-align: middle;"&gt;&lt;/div&gt;<br />
&lt;/div&gt;</code></p>
<p>That will give you a blue box horizontally and vertically centered inside the main div.</p>
<p>You may ask yourself how it&#8217;s any better than just using margin-top: 44%; &#8212; and it&#8217;s not for a fixed width object, but it will work for a VARIABLE WIDTH OR HEIGHT object.  (Think images!)</p>
<p>So there you go.  That&#8217;s the solution.  Exploit the one little vertical align ability CSS gives you &#8212; vertical align with the adjacent object that is 100% tall, bam &#8212; fluid vertical centering with variable dimension.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crimulus.com/2009/02/11/css-vertical-centering-on-variable-dimensions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

