<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: Image centering with CSS?</title>
	<link>http://ask.metafilter.com/12663/Image-centering-with-CSS/</link>
	<description>Comments on Ask MetaFilter post Image centering with CSS?</description>
	<pubDate>Wed, 08 Dec 2004 10:45:58 -0800</pubDate>
	<lastBuildDate>Wed, 08 Dec 2004 10:45:58 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: Image centering with CSS?</title>
		<link>http://ask.metafilter.com/12663/Image-centering-with-CSS</link>	
		<description>Following some googling, I&apos;ve found a few sites that claim you can&apos;t use CSS to centre an image vertically within a div. Does this mean that I can&apos;t get the images on &lt;a href=&quot;http://www.lawrence.gb.com/test/&quot;&gt;this page&lt;/a&gt; to float in the centre of their respective grey box? At the moment, they only seem to be postioned in the middle at the top of the box and even the middle bit is only because there is a text-align:center in there. (I don&apos;t mind If I have to lose the title of the image to get this to work)</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2004:site.12663</guid>
		<pubDate>Wed, 08 Dec 2004 10:24:10 -0800</pubDate>
		<dc:creator>ralawrence</dc:creator>
		
			<category>css</category>
		
			<category>div</category>
		
			<category>float</category>
		
			<category>howto</category>
		
	</item> <item>
		<title>By: Asparagirl</title>
		<link>http://ask.metafilter.com/12663/Image-centering-with-CSS#220407</link>	
		<description>Won&apos;t this work...?&lt;br&gt;
&lt;br&gt;
div.image img {&lt;br&gt;
vertical-align:middle;&lt;br&gt;
}</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2004:site.12663-220407</guid>
		<pubDate>Wed, 08 Dec 2004 10:45:58 -0800</pubDate>
		<dc:creator>Asparagirl</dc:creator>
	</item><item>
		<title>By: Hildago</title>
		<link>http://ask.metafilter.com/12663/Image-centering-with-CSS#220413</link>	
		<description>This ought to be a silly question, but CSS positioning, though crippled in numerous ways, does rule the world, so I can understand if it never even occured to you, but... have you tried using a table?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2004:site.12663-220413</guid>
		<pubDate>Wed, 08 Dec 2004 10:54:21 -0800</pubDate>
		<dc:creator>Hildago</dc:creator>
	</item><item>
		<title>By: hatbox</title>
		<link>http://ask.metafilter.com/12663/Image-centering-with-CSS#220427</link>	
		<description>It hasn&apos;t been tested on a Mac, but try &lt;a href=&quot;http://www.jakpsatweb.cz/css/css-vertical-center-solution.html&quot;&gt;Yuhu&apos;s Definitive Solution with Unknown Height&lt;/a&gt;.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2004:site.12663-220427</guid>
		<pubDate>Wed, 08 Dec 2004 11:08:18 -0800</pubDate>
		<dc:creator>hatbox</dc:creator>
	</item><item>
		<title>By: ralawrence</title>
		<link>http://ask.metafilter.com/12663/Image-centering-with-CSS#220431</link>	
		<description>I tried vertical-align on &quot;div.image&quot; and &quot;div.image img&quot; and neither worked.&lt;br&gt;
&lt;br&gt;
As for tables, my old album used them but had to assume a fixed width. I&apos;d ideally like to use CSS so it reflows correctly on different sized windows - but it isn&apos;t as easy as I thought it would be!</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2004:site.12663-220431</guid>
		<pubDate>Wed, 08 Dec 2004 11:14:20 -0800</pubDate>
		<dc:creator>ralawrence</dc:creator>
	</item><item>
		<title>By: Danelope</title>
		<link>http://ask.metafilter.com/12663/Image-centering-with-CSS#220437</link>	
		<description>&lt;a href=&quot;http://ask.metafilter.com/mefi/12422&quot;&gt;Six days ago&lt;/a&gt;.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2004:site.12663-220437</guid>
		<pubDate>Wed, 08 Dec 2004 11:21:51 -0800</pubDate>
		<dc:creator>Danelope</dc:creator>
	</item><item>
		<title>By: Monk</title>
		<link>http://ask.metafilter.com/12663/Image-centering-with-CSS#220601</link>	
		<description>&lt;code&gt;vertical-align&lt;/code&gt; is specifically for table cells, not arbitrary block elements. However, you can use &lt;code&gt;display: table-cell&lt;/code&gt; to make any element behave like a table cell; giving it the ability to align its contents vertically. Unfortunately, this doesn&apos;t work in IE6.&lt;br&gt;
&lt;br&gt;
The following works on FireFox and IE6 in both strict and quirks modes. I don&apos;t have any other browsers here to test on. (The second block of CSS isn&apos;t necessary, it just styles the page to look like the example.)&lt;br&gt;
&lt;br&gt;
&lt;code&gt;&lt;br&gt;
#PhotoAlbum a {&lt;br&gt;
&amp;nbsp;  display: block;&lt;br&gt;
&amp;nbsp;  float: left;&lt;br&gt;
&amp;nbsp;  background-color: #eef;&lt;br&gt;
&amp;nbsp;  background-position: 50% 50%;&lt;br&gt;
&amp;nbsp;  background-repeat: no-repeat;&lt;br&gt;
&amp;nbsp;  width: 110px;&lt;br&gt;
&amp;nbsp;  padding: 95px 0 3px 0;&lt;br&gt;
&amp;nbsp;  text-align: center;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;  border: #ccc 1px dashed;&lt;br&gt;
&amp;nbsp;  margin: 0 10px 10px 0;&lt;br&gt;
&amp;nbsp;  font-family: Trebuchet MS;&lt;br&gt;
&amp;nbsp;  color: #000;&lt;br&gt;
&amp;nbsp;  font-size: 10px;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&amp;lt;div id=&quot;PhotoAlbum&quot;&amp;gt;&lt;br&gt;
&amp;nbsp;  &amp;lt;a href=&quot;IMG_1736.JPG&quot; title=&quot;IMG_1736.JPG&quot; style=&quot;background-image: url(IMG_1736.JPG)&quot;&amp;gt;IMG_1736&amp;lt;/a&amp;gt;&lt;br&gt;
&amp;lt;/div&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
While it&apos;s easier to center background images than inline images, there are some downsides. There is no &lt;code&gt;alt&lt;/code&gt; attribute for screen readers and background images do not print using default settings, making it more difficult to print a contact sheet should you need a hard copy.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2004:site.12663-220601</guid>
		<pubDate>Wed, 08 Dec 2004 13:43:38 -0800</pubDate>
		<dc:creator>Monk</dc:creator>
	</item><item>
		<title>By: tenseone</title>
		<link>http://ask.metafilter.com/12663/Image-centering-with-CSS#220964</link>	
		<description>Would &lt;a href=&quot;http://www.wpdfd.com/editorial/thebox/deadcentre4.html&quot;&gt;Dead Centre&lt;/a&gt; help?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2004:site.12663-220964</guid>
		<pubDate>Thu, 09 Dec 2004 04:35:31 -0800</pubDate>
		<dc:creator>tenseone</dc:creator>
	</item><item>
		<title>By: ruthsarian</title>
		<link>http://ask.metafilter.com/12663/Image-centering-with-CSS#220995</link>	
		<description>vertical-align isn&apos;t just for tables, it&apos;s actually applicable to any inline element such as text or an image. It determines how inline elements of varying heights will line-up next to each other.&lt;br&gt;
&lt;br&gt;
In the case of ralawrence&apos;s contact sheet, the easiest way to do vertical-alignment is to remove the titles of the images so it&apos;s just a single image inside each box. Then define the font-width for the boxes as the pixel height you want the box, rather than explicitly setting the height attribute on the parent div element. Something like this:&lt;br&gt;
&lt;br&gt;
div.image {&lt;br&gt;
	font-size: 100px;&lt;br&gt;
	line-height: 120px;&lt;br&gt;
	padding: 0;&lt;br&gt;
	height: 0;&lt;br&gt;
}&lt;br&gt;
div.image img {&lt;br&gt;
	vertical-align: middle;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
Background images might work as well but you run into the problem of either figuring out how to push the image name to the bottom of that window block (so it doesn&apos;t appear over the image) or making the div clickable (via some javascript). &lt;br&gt;
&lt;br&gt;
The &lt;a href=&quot;http://www.wpdfd.com/editorial/thebox/deadcentre4.html&quot;&gt;Dead Centre&lt;/a&gt; approach works well too, but you have to be working with known pixel height, and you&apos;d need a different selector defined for each height you have (60 and 80 it appears).</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2004:site.12663-220995</guid>
		<pubDate>Thu, 09 Dec 2004 06:28:16 -0800</pubDate>
		<dc:creator>ruthsarian</dc:creator>
	</item><item>
		<title>By: ruthsarian</title>
		<link>http://ask.metafilter.com/12663/Image-centering-with-CSS#220996</link>	
		<description>Actually, that should be height: auto, not height: 0. Sorry.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2004:site.12663-220996</guid>
		<pubDate>Thu, 09 Dec 2004 06:29:26 -0800</pubDate>
		<dc:creator>ruthsarian</dc:creator>
	</item><item>
		<title>By: tenseone</title>
		<link>http://ask.metafilter.com/12663/Image-centering-with-CSS#221018</link>	
		<description>Would something like this work ( I didn&apos;t actually test it ):&lt;br&gt;
&lt;br&gt;
&amp;lt;?php&lt;br&gt;
&lt;br&gt;
for($i = 1000,$i &amp;lt;= 4000,$i++) {&lt;br&gt;
&lt;br&gt;
&#160;if(is_array(getimagesize($_SERVER[&apos;DOCUMENT_ROOT&apos;] . &apos;/test/Vienna/thumb/IMG_&apos; . $i . &apos;.JPG&apos;))) {&lt;br&gt;
	&lt;br&gt;
&#160;&#160;$image = getimagesize($_SERVER[&apos;DOCUMENT_ROOT&apos;] . &apos;/test/Vienna/thumb/IMG_&apos; . $i . &apos;.JPG&apos;);&lt;br&gt;
		&lt;br&gt;
&#160;&#160;$width 	= $image[0];&lt;br&gt;
&#160;&#160;$height	= $image[1];&lt;br&gt;
&#160;&#160;$w_pos	= $image[0] / 2;&lt;br&gt;
&#160;&#160;$h_pos	= $image[1] / 2;&lt;br&gt;
	&lt;br&gt;
&#160;&#160;echo		&apos;&amp;lt;div class=&quot;box&quot;&amp;gt;&apos;;&lt;br&gt;
&#160;&#160;echo		&apos;&amp;lt;img style=&quot;width:&apos; . $width . &apos;;height:&apos; . $height . &apos;;position:absolute;left:50%;top:-&apos; . $h_pos . &apos;;margin-left:-&apos; . $w_pos . &apos;;visibility:visible;&quot; src=&quot;/test/Vienna/thumb/IMG_&apos; . $i . &apos;.JPG&quot; alt=&quot;&quot; width=&quot;&apos; . $width . &apos;&quot; height=&quot;&apos; . $height . &apos;&quot; /&amp;gt;&apos;;&lt;br&gt;
&#160;&#160;echo		&apos;&amp;lt;/div&amp;gt;&apos;;&lt;br&gt;
		&lt;br&gt;
&#160;}&lt;br&gt;
	&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
?&amp;gt;&lt;br&gt;
&lt;br&gt;
Again, I didn&apos;t actually test it.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2004:site.12663-221018</guid>
		<pubDate>Thu, 09 Dec 2004 07:33:10 -0800</pubDate>
		<dc:creator>tenseone</dc:creator>
	</item><item>
		<title>By: tenseone</title>
		<link>http://ask.metafilter.com/12663/Image-centering-with-CSS#221021</link>	
		<description>Whoops!&lt;br&gt;
&lt;br&gt;
&lt;cite&gt;for($i = 1000&lt;strong&gt;;&lt;/strong&gt;$i &amp;lt;= 4000&lt;strong&gt;;&lt;/strong&gt;$i++) {&lt;/cite&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2004:site.12663-221021</guid>
		<pubDate>Thu, 09 Dec 2004 07:36:30 -0800</pubDate>
		<dc:creator>tenseone</dc:creator>
	</item><item>
		<title>By: ruthsarian</title>
		<link>http://ask.metafilter.com/12663/Image-centering-with-CSS#221366</link>	
		<description>&lt;em&gt;Would something like this work&lt;/em&gt;&lt;br&gt;
&lt;br&gt;
tenseone: that looks good to me. As long as your contact sheets aren&apos;t too big. If you&apos;ve got, say, 1000 images per page, then that&apos;s 2000 (because you&apos;re calling getimagesize twice)  open,read,close operations per page visit.&lt;br&gt;
&lt;br&gt;
If it&apos;s 25 or so, then that should work fine.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2004:site.12663-221366</guid>
		<pubDate>Thu, 09 Dec 2004 13:39:00 -0800</pubDate>
		<dc:creator>ruthsarian</dc:creator>
	</item><item>
		<title>By: tenseone</title>
		<link>http://ask.metafilter.com/12663/Image-centering-with-CSS#221473</link>	
		<description>&lt;cite&gt;If you&apos;ve got, say, 1000 images per page, then that&apos;s 2000 (because you&apos;re calling getimagesize twice) open,read,close operations per page visit.&lt;/cite&gt;&lt;br&gt;
&lt;br&gt;
Absolutely, I made a glaring error in logic. It would seem to be more intelligent to simply sort through the contents of the &apos;thumb&apos; directory, and only call getimagesize on existing &apos;.JPG&apos; files. At least we would be cutting the executions in half.&lt;br&gt;
&lt;br&gt;
Though even still, if we were discussing thousands of images, how would the processing time of the script compare to the taxing event of loading thousands of jpegs? Or am I completely off base in my thinking ( most likely )?&lt;br&gt;
&lt;br&gt;
Of course, I may very well be guilty of flogging a dead horse.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2004:site.12663-221473</guid>
		<pubDate>Thu, 09 Dec 2004 15:16:44 -0800</pubDate>
		<dc:creator>tenseone</dc:creator>
	</item>
	</channel>
</rss>
