<?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>Fritz Thomas &#187; inline-block</title>
	<atom:link href="http://fritzthomas.com/tags/inline-block/feed/" rel="self" type="application/rss+xml" />
	<link>http://fritzthomas.com</link>
	<description></description>
	<lastBuildDate>Fri, 23 Jul 2010 08:02:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to vertically align text and block elements</title>
		<link>http://fritzthomas.com/overall/418-how-to-vertically-align-text-and-block-elements/</link>
		<comments>http://fritzthomas.com/overall/418-how-to-vertically-align-text-and-block-elements/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 12:42:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Overall]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[inline-block]]></category>
		<category><![CDATA[vertical-align]]></category>

		<guid isPermaLink="false">http://fritzthomas.com/?p=418</guid>
		<description><![CDATA[You may know the CSS declarations text-align and vertical-align. Perhaps you tried alredy to vertically align inline span elements within a div block element but did not succeed yet. I will try explain how to achieve this with a simple button example. Before: After: Lets begin with the markup for the buttons: 1 2 3 [...]]]></description>
			<content:encoded><![CDATA[<p>You may know the CSS declarations text-align and vertical-align. Perhaps you tried alredy to vertically align inline span elements within a div block element but did not succeed yet. I will try explain how to achieve this with a simple button example.<br />
Before:<img style="vertical-align:middle" class="alignnone size-full wp-image-420" title="screenshot14" src="http://fritzthomas.com/wp-content/uploads/2009/02/screenshot14.png" alt="screenshot14" width="115" height="24" /><br />
After: <img style="vertical-align:middle" class="alignnone size-full wp-image-419" title="screenshot13" src="http://fritzthomas.com/wp-content/uploads/2009/02/screenshot13.png" alt="screenshot13" width="112" height="25" /><br />
<span id="more-418"></span><br />
 Lets begin with the markup for the buttons:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;buttons&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add button&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;icon&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add.png&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span>&gt;</span>Add<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;delete button&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;icon&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;delete.png&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span>&gt;</span>Delete<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>Each Button is within a single div. Every button has its icon and a button text. Image and Text are in a span tag. the &#8220;add&#8221; and &#8220;delete&#8221; class is added to differentiate the buttons. This is useful if you want to add some behavior in JavaScript.<br />
<div style="width:100%;text-align:center;padding:0;margin:0;border:0;overflow:hidden;clear:both;"><script type="text/javascript"><!--
google_ad_client = "pub-1963733382421272";
google_ui_features = "rc:0";
google_ad_width = 234;
google_ad_height = 60;
google_ad_format = "234x60_as";
google_ad_type = "text_image";
google_alternate_ad_color = "ffffff";
google_color_border = "ffffff";
google_color_bg = "ffffff";
google_color_link = "319BD8";
google_color_text = "666666";
google_color_url = "319BD8";

//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</div></p>
<p>Next, the CSS styles:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.buttons</span> <span style="color: #6666ff;">.button</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/** important **/</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</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;">4px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#a1a1a1</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ffffff</span><span style="color: #00AA00;">;</span>
  border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/** CSS3 **/</span>
  -moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/** Mozilla specific **/</span>
  -webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/** Make a guess ;-) **/</span>
  <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> hand<span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.buttons</span> <span style="color: #6666ff;">.button</span> <span style="color: #6666ff;">.icon</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> inline-<span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/** important **/</span>
  <span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">middle</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/** important **/</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</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;">2px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.buttons</span> <span style="color: #6666ff;">.button</span> <span style="color: #6666ff;">.text</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> inline-<span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/** important **/</span>
  <span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">middle</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/** important **/</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p><div style="float:left;margin-left:0,margin-right:4px;margin-top:4px;margin-bottom:0;padding:4px;border:0;"><script type="text/javascript"><!--
google_ad_client = "pub-1963733382421272";
google_ad_slot = "3802836967";
google_ad_width = 120;
google_ad_height = 240;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</div>
<p>The important css declarations and attributes are &#8220;display: inline-block&#8221;, &#8220;vertical-align: middle&#8221; and &#8220;line-height: XXpx&#8221;. The line-height tells every .button block the exact height of the inline elements underneath. The inline elements .icon and .text are handled and displayed as an &#8220;inline-block&#8221;. Firefox 3 and most of the other major browsers supporting it so it is safe to use it. <a href="http://www.quirksmode.org/css/display.html">Read more on this.</a><br />
<br />
The result should look like this:<img style="vertical-align:middle" class="alignnone size-full wp-image-419" title="screenshot13" src="http://fritzthomas.com/wp-content/uploads/2009/02/screenshot13.png" alt="screenshot13" width="112" height="25" /><br />
I think the example is simple enough to adapt it to your needs and other use cases. Please keep in mind that in the example i use -moz-border-radius. This declaration is mozilla specific. So if you want rounded corners in IE you have to wait until IE is implementing this. Take <a href="http://a.deveria.com/caniuse/#feat=roundedcorners">a look</a> when this is scheduled and <a href="http://fritzthomas.com/overall/407-charts-of-when-we-can-use-features-of-html-svg-and-css3/#refuse-internet-explorer">follow my suggestion.</a></p>

	Tags: <a href="http://fritzthomas.com/tags/css/" title="css" rel="tag">css</a>, <a href="http://fritzthomas.com/tags/css3/" title="CSS3" rel="tag">CSS3</a>, <a href="http://fritzthomas.com/tags/how-to/" title="how-to" rel="tag">how-to</a>, <a href="http://fritzthomas.com/tags/howto/" title="howto" rel="tag">howto</a>, <a href="http://fritzthomas.com/tags/html/" title="HTML" rel="tag">HTML</a>, <a href="http://fritzthomas.com/tags/inline-block/" title="inline-block" rel="tag">inline-block</a>, <a href="http://fritzthomas.com/tags/vertical-align/" title="vertical-align" rel="tag">vertical-align</a><br />

	<h4>&Auml;hnliche Beitr&auml;ge:</h4>
	<ul class="st-related-posts">
	<li><a href="http://fritzthomas.com/overall/415-css-browser-compatiblity/" title="CSS Browser Compatiblity (February 18, 2009)">CSS Browser Compatiblity</a> (0)</li>
	<li><a href="http://fritzthomas.com/php/zend-framework/33-how-to-teil-1-projektaufbau-konventionen-und-modulare-verzeichnisstruktur/" title="Zend Framework How-To Teil 1: Projektaufbau, Konventionen und modulare Verzeichnisstruktur (January 28, 2008)">Zend Framework How-To Teil 1: Projektaufbau, Konventionen und modulare Verzeichnisstruktur</a> (13)</li>
	<li><a href="http://fritzthomas.com/open-source/linux/12-aendern-oder-setzen-eines-statischen-netzwerk-device-namen-unter-gentoo-eth0-eth1ethn/" title="Setzen eines statischen Netzwerk Device Namen unter Gentoo. (eth0,eth1,&#8230;) (December 27, 2007)">Setzen eines statischen Netzwerk Device Namen unter Gentoo. (eth0,eth1,&#8230;)</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://fritzthomas.com/overall/418-how-to-vertically-align-text-and-block-elements/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
