<?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>Knappster&#039;s ramblings</title>
	<atom:link href="http://knappster.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://knappster.co.uk</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Thu, 09 Feb 2012 14:26:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>CSS: Re-size images keeping the aspect ratio in both portrait and landscape.</title>
		<link>http://knappster.co.uk/2011/12/24/css-re-size-images-and-keep-their-aspect-ratio/</link>
		<comments>http://knappster.co.uk/2011/12/24/css-re-size-images-and-keep-their-aspect-ratio/#comments</comments>
		<pubDate>Sat, 24 Dec 2011 23:23:22 +0000</pubDate>
		<dc:creator>knappster</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[aspect]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[ratio]]></category>
		<category><![CDATA[re-size]]></category>
		<category><![CDATA[resize]]></category>

		<guid isPermaLink="false">http://knappster.co.uk/?p=12</guid>
		<description><![CDATA[I recently encountered a problem with resizing images. They had to fit within a containing div but every image on the site I was working on had a mix of portrait and landscape images. The normal approach would have been &#8230; <a href="http://knappster.co.uk/2011/12/24/css-re-size-images-and-keep-their-aspect-ratio/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently encountered a problem with resizing images. They had to fit within a containing div but every image on the site I was working on had a mix of portrait and landscape images.</p>
<p>The normal approach would have been to do something like this:<br />
<code><br />
img.landscape {<br />
height: auto;<br />
width: 100%;<br />
}</p>
<p>img.portrait {<br />
height: 100%;<br />
width: auto;<br />
}<br />
</code></p>
<p>This works fine if all your images are one aspect ratio or you can differentiate them from one another by either using classes or some other means.</p>
<p>Now I&#8217;m not a CSS guru or a designer by any means so I tried to do what I normally do and googled the problem. I found all sorts of weird solutions people has come up with. Javascript and application based solutions (php) were out of the question and couldn&#8217;t find a CSS only solution. So I experimented.</p>
<p>Original example images:<br />
<img src="http://knappster.co.uk/wp-content/uploads/2011/12/landscapepic.jpg" alt="Landscape Image" /><br />
<img src="http://knappster.co.uk/wp-content/uploads/2011/12/portraitpic.jpg" alt="Portrait Image" /></p>
<p>This is what was happening:</p>
<div style="height: 310px;">
<div style="float: left; width: 200px; height: 200px; border: 1px solid #000;"><img style="height: auto; width: 100%; max-width: 100%;" src="http://knappster.co.uk/wp-content/uploads/2011/12/landscapepic.jpg" alt="Landscape Image" /></div>
<div style="float: left; width: 200px; height: 200px; border: 1px solid #000; margin-left: 15px;"><img style="height: auto; width: 100%; max-width: 100%;" src="http://knappster.co.uk/wp-content/uploads/2011/12/portraitpic.jpg" alt="Portrait Image" /></div>
</div>
<p>I&#8217;ve placed a black border around the containing div elements. As you can see the portrait image is breaking out of it&#8217;s containing div. I thought the browser might be smart enough to solve to issue if I just set the width and height to &#8216;auto&#8217;. It didn&#8217;t work. So I tried max-height and max-width to 100%. That didn&#8217;t work.</p>
<p>In a fit of frustration I tried combined both height, width, max-height and max-width. Lo and behold a miracle occurred.<br />
<code><br />
img {<br />
height: auto;<br />
width: auto;<br />
max-height: 100%;<br />
max-width: 100%;<br />
}<br />
</code></p>
<div style="height: 220px;">
<div style="float: left; width: 200px; height: 200px; border: 1px solid #000;"><img style="height: auto; width: auto; max-height: 100%; max-width: 100%;" src="http://knappster.co.uk/wp-content/uploads/2011/12/landscapepic.jpg" alt="Landscape Image" /></div>
<div style="float: left; width: 200px; height: 200px; border: 1px solid #000; margin-left: 15px; text-align: center;"><img style="height: auto; width: auto; max-height: 100%; max-width: 100%;" src="http://knappster.co.uk/wp-content/uploads/2011/12/portraitpic.jpg" alt="Portrait Image" /></div>
</div>
<p>This seems to work cross browser as well. I tested this in IE7/8/9, Firefox 8 and Chrome.</p>
<p>Please note I don&#8217;t condone the resizing of images using CSS, it&#8217;s horrible, I had no choice. Images should always be resized before they reach the browser. If you have to ask why then you shouldn&#8217;t be working on websites imo.</p>
]]></content:encoded>
			<wfw:commentRss>http://knappster.co.uk/2011/12/24/css-re-size-images-and-keep-their-aspect-ratio/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Welcome</title>
		<link>http://knappster.co.uk/2011/12/12/welcome/</link>
		<comments>http://knappster.co.uk/2011/12/12/welcome/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 13:46:46 +0000</pubDate>
		<dc:creator>knappster</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://knappster.co.uk/?p=5</guid>
		<description><![CDATA[Welcome to my new WordPress site ^_^. Please bare with me as I create a new theme and learn the inner workings of WordPress.]]></description>
			<content:encoded><![CDATA[<p>Welcome to my new WordPress site ^_^. Please bare with me as I create a new theme and learn the inner workings of WordPress.</p>
]]></content:encoded>
			<wfw:commentRss>http://knappster.co.uk/2011/12/12/welcome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

