{"authorId":"1","title":"The Ultimate PNG Guide","slug":"the-ultimate-png-guide","postDate":1198690564,"expiryDate":null,"enabled":"1","fields":{"2":"<p>I would say one of the coolest things in web development\/design is the creative use of PNGs. Although, it&rsquo;s a little hard because of the way that IE6 handles them.<\/p>\n\n<p>I have already written about <a href=\"http:\/\/trevordavis.net\/blog\/tutorial\/using-dean-edwards-ie7-script\/\">Using Dean Edwards&rsquo; IE7 Script<\/a>, but I wanted to take it a step further and talk more about PNGs.<\/p>\n\n<!--more-->\n\n<h2 class=\"replaceHeadline\">To Review<\/h2>\n<blockquote>\n<p>First, <a href=\"http:\/\/dean.edwards.name\/download\/\">download the Dean Edwards script<\/a>. Next, extract the files to the root of your webserver in a folder called <strong>ie7<\/strong>. It needs to be in this folder, because some of the scripts have a dependency on the folder.<\/p>\n<p>Finally, just include the script in the head of your document using conditional comments:<\/p>\n<\/blockquote>\n\n<div class=\"codeblock\"><code>\n&lt;!--&#91;if&nbsp;lt&nbsp;IE&nbsp;7&#93;&gt;<br \/>&lt;script&nbsp;src=\"\/ie7\/ie7-standard-p.js\"&nbsp;type=\"text\/javascript\"&gt;&lt;\/script&gt;<br \/>&lt;!&#91;endif&#93;--&gt;&nbsp;\n\n<\/code><\/div>\n<p>Ok, so now when you want to have the script &ldquo;fix&rdquo; the PNG in IE6, you just have to have <strong>-trans.png<\/strong> as the suffix of the filename of the image.<\/p>\n\n<h2 class=\"replaceHeadline\">An Example<\/h2>\n\n<p>Now, I am no designer, but I have <a href=\"http:\/\/trevordavis.net\/images\/content\/2008\/01\/png-screenshot.png\">mocked-up a simple page to show some usage of PNGs<\/a>.<\/p>\n\n<p>Since the background on the body is the repeated diagonal lines, we cannot use a GIF for the rounded corners, because we aren&rsquo;t sure where the corners will intersect with the lines on the bottom.<\/p>\n\n<p>In an ideal world, <a href=\"http:\/\/trevordavis.net\/play\/pngs\/\">this is how I would want to mark the page up.<\/a><\/p>\n\n<p>But, in IE6, the PNGs have a blue glow around them. So if we <a href=\"http:\/\/trevordavis.net\/play\/pngs\/example-2\/\">apply the Dean Edwards scripts to the page<\/a>, we see the bottom image disappears (keep in mind you have to be looking in IE6 to see this problem). This is because the script is applying the IE proprietary filter property, and once this applied, we cannot position or repeat a PNG.<\/p>\n\n<p><a href=\"http:\/\/trevordavis.net\/play\/pngs\/example-3\/\">So let&rsquo;s change the way we are marking it up so that the bottom shows up in IE6<\/a>. Basically, we have just added an empty <code>div<\/code> that contains the bottom background PNG.<\/p>\n\n<p>Now we just have to worry about the repeated background of our main content area. In order to get rid of the blue glow, we have to apply IE&rsquo;s filter property, which means that we can't repeat it.<\/p>\n\n<p>But, if we apply the filter property manually and change the sizingMethod to scale, <a href=\"http:\/\/trevordavis.net\/play\/pngs\/example-4\/\">we can give the effect of repeating the background<\/a>.<\/p>\n\n<div class=\"codeblock\"><code>\ndiv#container&nbsp;div.inner&nbsp;&#123;<br \/>&nbsp;background-image:&nbsp;url(blank.gif);<br \/>&nbsp;filter:&nbsp;progid:DXImageTransform.Microsoft.AlphaImageLoader&nbsp;(src='\/images\/content\/2008\/01\/container-bg.png',&nbsp;sizingMethod='scale');<br \/>&#125;&nbsp;\n\n<\/code><\/div>\n\n<p>Basically, it&rsquo;s just stretching the image to fit the area, but since it&rsquo;s a simple image that we were going to repeat anyways, it looks fine stretched.<\/p>\n\n<h3 class=\"replaceHeadline\">In Conclusion<\/h3>\n<p>Hopefully using a combination of these two PNG fixes can provide you with enough to get things looking good in all browsers.<\/p>\n\n<p>Anyone have any other solutions?<\/p>","14":{"old_id":{}}}}