<?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>A Tasty Pixel » Blog &#187; CSS</title>
	<atom:link href="http://atastypixel.com/blog/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://atastypixel.com/blog</link>
	<description></description>
	<lastBuildDate>Tue, 24 Jan 2012 10:40:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Links for March 17th through April 24th</title>
		<link>http://atastypixel.com/blog/links-march-17th-april-24th/</link>
		<comments>http://atastypixel.com/blog/links-march-17th-april-24th/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 00:00:41 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/?p=1514</guid>
		<description><![CDATA[Links for March 17th through April 24th: XSD Schema XML Validator A XSD Schema validator in Java, provides lots of useful information; use it with a schema and an xml instance Three20 Three20 is a collection of iPhone UI classes, like a photo viewer, and general utilities, like an HTTP disk cache. Three20 is derived [...]]]></description>
			<content:encoded><![CDATA[<p>Links for March 17th through April 24th:</p>

<ul class="delicious-bookmarks">
<li><a href="http://www.herongyang.com/XML-Schema/JAXP-XSD-Schema-XML-Validator-Final-Version.html">XSD Schema XML Validator</a> A XSD Schema validator in Java, provides lots of useful information; use it with a schema and an xml instance</li>
<li><a href="http://github.com/joehewitt/three20/tree/master">Three20</a> Three20 is a collection of iPhone UI classes, like a photo viewer, and general utilities, like an HTTP disk cache. Three20 is derived from the Facebook iPhone app, which is one of the most downloaded iPhone apps ever.</li>
<li><a href="http://www.webdesignerwall.com/tutorials/css-decorative-gallery/">CSS Decorative Gallery</a> &#8230;How to decorate your images and photo galleries without editing the source images. The trick is very simple. All you need is an extra &lt;span&gt; tag and apply a background image to create the overlaying effect.</li>
<li><a href="http://en.wikipedia.org/wiki/Comet_(programming)">Comet (programming) &#8211; Wikipedia, the free encyclopedia</a> Comet is a neologism to describe a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it</li>
<li><a href="http://www.cimgf.com/2008/03/26/cocoa-tutorial-awakefromnib-vs-applicationdidfinishlaunching/">Cocoa Is My Girlfriend &raquo; Cocoa Tutorial: awakeFromNib vs applicationDidFinishLaunching</a> A very good overview of the &#39;startup&#39; procedure for objects stored in IB nib/xibs.</li>

</ul>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1514" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/links-march-17th-april-24th/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Links for February 28th through March 3rd</title>
		<link>http://atastypixel.com/blog/links-february-28th-march-3rd/</link>
		<comments>http://atastypixel.com/blog/links-february-28th-march-3rd/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 03:00:23 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/?p=1455</guid>
		<description><![CDATA[Links for February 28th through March 3rd: Lifehacker readers: Most Popular Reliable and Affordable Web Hosts Top seven hosts as voted by readers (DreamHost, Blue Host, NearlyFreeSpeech.NET, 1&#38;1, GoDaddy, HostGator and A Small Orange) Domainr, the domain name search engine Given a name, suggests a variety of different domain name possibilities, and reports on availability [...]]]></description>
			<content:encoded><![CDATA[<p>Links for February 28th through March 3rd:</p>

<ul class="delicious-bookmarks">
<li><a href="http://lifehacker.com/5124856/most-popular-reliable-and-affordable-web-hosts">Lifehacker readers: Most Popular Reliable and Affordable Web Hosts</a> Top seven hosts as voted by readers (DreamHost, Blue Host, NearlyFreeSpeech.NET, 1&amp;1, GoDaddy, HostGator and A Small Orange)</li>
<li><a href="http://domai.nr/">Domainr, the domain name search engine</a> Given a name, suggests a variety of different domain name possibilities, and reports on availability</li>
<li><a href="http://www.schillmania.com/content/projects/even-more-rounded-corners/">Even More Rounded Corners With CSS &#8211; Schillmania.com</a> Single-image, PNG-based, fluid rounded corner dialogs with support for borders, alpha transparency throughout, gradients, patterns and whatever else you (or your designer) could want</li>
<li><a href="http://www.smashingmagazine.com/2009/02/04/50-beautiful-and-user-friendly-navigation-menus/">50 Beautiful And User-Friendly Navigation Menus</a> Navigation inspiration</li>
<li><a href="http://ocrterminal.com/">OCR Terminal</a> OCR Terminal is a free online Optical Character Recognition service that allows you to convert scanned images and PDF&#39;s into editable and text searchable documents. It accurately preserves formatting and layout of documents.</li>

</ul>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1455" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/links-february-28th-march-3rd/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Advanced web templating with PHP and regular expressions</title>
		<link>http://atastypixel.com/blog/advanced-web-templating-with-php-and-regular-expressions/</link>
		<comments>http://atastypixel.com/blog/advanced-web-templating-with-php-and-regular-expressions/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 02:53:03 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/2008/10/12/advanced-web-templating-with-php-and-regular-expressions/</guid>
		<description><![CDATA[A method to gain more control over the styling of images for web templates/blog themes, using a bit of Regular Expression magic. This is the technique used for my recent theme, Elegant Grunge.]]></description>
			<content:encoded><![CDATA[<p><em>This post describes a method to gain more control over the styling of images for web templates/blog themes, using a bit of Regular Expression magic. This is the technique used for my recent theme, <a href="http://atastypixel.com/blog/2008/10/10/elegant-grunge-wordpress-theme/">Elegant Grunge</a>.</em></p>

<p>You&#8217;ve just designed the most beautiful template ever &#8211; pleasing composition, clean lines, smooth colours and gradients and an awesome typeface. You apply it as the theme for your blog, or release it to the community, and there is much rejoicing.<a href="http://atastypixel.com/blog/wp-content/uploads/2008/10/200810121259.jpg" rel="lightbox[921]"><img src="http://atastypixel.com/blog/wp-content/uploads/2008/10/200810121259-tm.jpg" width="100" height="67" alt="Example of the 'SH Trocadero' WordPress theme with image" title="Example of the 'SH Trocadero' WordPress theme with image" style="float:right;" /></a></p>

<p>Then you or someone else inconsiderately puts a photograph into a post &#8211; disaster! That nasty square of graphic just destroyed your composition, and the page is unbalanced and suddenly looks terrible.</p>

<p>Images are particularly tricky to make work with a theme, mostly because they&#8217;re so unpredictable. With text, it&#8217;s easy to control the way it looks. With images, they can be any colour or shape, many of which will break the composition of a theme, especially if the design elements of the theme contains irregular lines.</p>

<p>A big impediment to making images work is the limitations introduced by the current versions of CSS: All you can really do is provide a square border, possibly with some padding. That&#8217;s it, unless you&#8217;re willing to manually add tons of markup around images every time – and willing to make your users do it, if you&#8217;ve released a theme.<a href="http://atastypixel.com/blog/wp-content/uploads/2008/10/200810121308.jpg" rel="lightbox[921]"><img src="http://atastypixel.com/blog/wp-content/uploads/2008/10/200810121308-tm.jpg" width="100" height="71" alt="Example of images in the &quot;Green Light&quot; WordPress theme" title="Example of images in the &quot;Green Light&quot; WordPress theme" style="float:right;" /></a></p>

<p>Some people will carefully Photoshop-up their images to make them fit &#8211; <a href="http://webdemar.com/">Webdemar</a> (who made the theme I first used on my blog) does this, for example, and it looks great. That&#8217;s a lot of work, though, especially if you make frequent posts with images!</p>

<p>If you&#8217;re a theme designer, there&#8217;s an easier way to make images work.</p>

<p><span id="more-921"></span></p>

<h3>CSS Borders</h3>

<p>There are a <a href="http://www.google.com/search?q=css+rounded+borders+OR+corners">thousand and one</a> different ways to create styled borders in CSS. The basic principle is that one adds a certain amount of HTML markup around the content to be framed, and CSS rules apply background images in a variety of ways. The best of these techniques are very flexible, and allow designers to apply any kind of frame they can imagine.</p>

<p>The Joomla documentation describes <a href="http://docs.joomla.org/Creating_rounded_corners">one of these techniques</a> quite well, and it’s worth a read.</p>

<p>So, providing a frame around images allows designers to break up those straight lines, among other things. Thus, this:</p>

<div style="text-align: center;">
  <a href="http://atastypixel.com/blog/wp-content/uploads/2008/10/200810121311.jpg" rel="lightbox[921]"><img src="http://atastypixel.com/blog/wp-content/uploads/2008/10/200810121311-tm.jpg" width="300" height="216" alt="Example of &quot;Elegant Grunge&quot; WordPress theme without framed images" title="Example of &quot;Elegant Grunge&quot; WordPress theme without framed images" /></a><br />
</div>

<div style="text-align: center;">
  <small><em>Note how the straight image border breaks the ‘broken-up’ edge theme</em></small><br />
</div>

<p>Becomes this:</p>

<div style="text-align: center;">
  <a href="http://atastypixel.com/blog/wp-content/uploads/2008/10/200810121312.jpg" rel="lightbox[921]"><img src="http://atastypixel.com/blog/wp-content/uploads/2008/10/200810121312-tm.jpg" width="300" height="205" alt="200810121312.jpg" title="200810121312.jpg" class="Example of "Elegant Grunge" WordPress theme with framed images" /></a><br />
</div>

<div style="text-align: center;">
  <small><em>Frame with drop shadow provides illusion of depth, distancing image from theme</em></small><br />
</div>

<p>This is, of course, just one example, but there are many possibilities.</p>

<p>So, the question becomes: How do we provide the necessary HTML markup in the content, without doing it ourselves or making our users do it? Enter regular expressions…</p>

<h3>Regex magic</h3>

<p>The concept is very simple – whenever we encounter an image in the content, we surround it by the markup necessary to render a frame around it. There are, however, a few extra things that’d be nice:</p>

<ul>
  <li>Provide the ability to frame any content, not just images, by supplying a class</li>

  <li>Provide the ability to avoid framing some images, to provide some control, by supplying a class</li>

  <li>Manage image sizing, in case a too-large image is provided</li>

  <li>Avoid showing frames if the surrounded image is too small (and would thus look wrong)</li>

  <li>Some styles/classes applied to the inner content should be also applied to the frame (such as float settings)</li>
</ul>

<p>This PHP script gives an example of how it can be done as part of a WordPress theme: <a href="http://atastypixel.com/blog/wp-content/uploads/2008/10/framing-samplephp.zip">framing-sample.php.zip</a></p>

<p>The script provides a filter function, used by WordPress during the render pipeline to modify content. The function looks for blocks with a class of ‘frame’, or images. It avoids any block with a class of ‘noframe’ (and also ‘wp-smiley’, which is the class used for those small emoticons in WordPress). It then uses a ‘callback’ helper function to perform the actual replacement, capturing styles/classes for the inner object, and managing image sizes in the process.</p>

<p>A caveat here: The regular expression that supports wrapping any kind of content block (as opposed to just images) uses a relatively modern feature of regular expressions called recursive sub-patterns, which will not work with PHP installations with an older PCRE regular expression library. Hence, the ‘@’ sign preceding the preg_replace_callback, which will cause it to fail silently, without throwing error messages everywhere.</p>

<p>So, this code wraps the content in four ‘span’ objects, which can then be styled using CSS. For small images, it also applies the ‘small’ class, which can be used to provide a smaller frame to avoid visual glitching.</p>

<h3>CSS time</h3>

<p>So, we now have markup in place, and it’s time to provide some styles. Here’s some sample CSS:</p>

<blockquote>
  <br /><span style="color: #8C868F; font-size: 11px;"><span style="color: #8c868f">/* Frame */</span><span style="color: #000000"><br />  <br /></span>.frame-outer <span style="color: #000000">{<br /></span> background<span style="color: #000000">:</span> url<span style="color: #000000">(images/frame-top-left.jpg)</span> no-repeat left top<span style="color: #000000">;<br /></span> padding<span style="color: #000000">:</span> 0<span style="color: #000000">;<br /></span> margin<span style="color: #000000">:</span> 0<span style="color: #000000">;<br /></span> display<span style="color: #000000">:</span> inline-block<span style="color: #000000">;<br />}<br />  <br /></span>.frame-outer span <span style="color: #000000">{<br /></span> background<span style="color: #000000">:</span> url<span style="color: #000000">(images/frame-bottom-left.jpg)</span> no-repeat left bottom<span style="color: #000000">;<br /></span> margin<span style="color: #000000">:</span> 0<span style="color: #000000">;<br /></span> padding<span style="color: #000000">:</span> 0<span style="color: #000000">;<br /></span> display<span style="color: #000000">:</span> block<span style="color: #000000">;<br />}<br />  <br /></span>.frame-outer span span <span style="color: #000000">{<br /></span> background<span style="color: #000000">:</span> url<span style="color: #000000">(images/frame-top-right.jpg)</span> no-repeat right top<span style="color: #000000">;<br /></span> display<span style="color: #000000">:</span> block<span style="color: #000000">;<br />}<br />  <br /></span>.frame-outer span span span <span style="color: #000000">{<br /></span> background<span style="color: #000000">:</span> url<span style="color: #000000">(images/frame-bottom-right.jpg)</span> no-repeat right bottom<span style="color: #000000">;<br /></span> padding<span style="color: #000000">:</span> 32<span style="color: #ff7800">px</span><span style="color: #000000">;<br /></span> min-width<span style="color: #000000">:</span> 150<span style="color: #ff7800">px</span><span style="color: #000000">;<br /></span> min-height<span style="color: #000000">:</span> 150<span style="color: #ff7800">px</span><span style="color: #000000">;<br /></span> text-align<span style="color: #000000">:</span> center<span style="color: #000000">;<br /></span> overflow<span style="color: #000000">:</span> hidden<span style="color: #000000">;<br /></span> display<span style="color: #000000">:</span> block<span style="color: #000000">;<br />}<br />  <br /></span>.frame-outer span span span * <span style="color: #000000">{<br /></span> max-width<span style="color: #000000">:</span> 425<span style="color: #ff7800">px</span><span style="color: #000000">;<br />}<br />  <br /></span>.frame-outer.small <span style="color: #000000">{<br /></span> background<span style="color: #000000">:</span> url<span style="color: #000000">(images/frame-top-left-small.jpg)</span> no-repeat left top<span style="color: #000000">;<br />}<br />  <br /></span>.frame-outer.small span <span style="color: #000000">{<br /></span> background<span style="color: #000000">:</span> url<span style="color: #000000">(images/frame-bottom-left-small.jpg)</span> no-repeat left bottom<span style="color: #000000">;<br />}<br />  <br /></span>.frame-outer.small span span <span style="color: #000000">{<br /></span> background<span style="color: #000000">:</span> url<span style="color: #000000">(images/frame-top-right-small.jpg)</span> no-repeat right top<span style="color: #000000">;<br />}<br />  <br /></span>.frame-outer.small span span span <span style="color: #000000">{<br /></span> background<span style="color: #000000">:</span> url<span style="color: #000000">(images/frame-bottom-right-small.jpg)</span> no-repeat right bottom<span style="color: #000000">;<br /></span> padding<span style="color: #000000">:</span> 10<span style="color: #ff7800">px</span><span style="color: #000000">;<br /></span> min-height<span style="color: #000000">:</span> 38<span style="color: #ff7800">px</span><span style="color: #000000">;<br /></span> min-width<span style="color: #000000">:</span> 38<span style="color: #ff7800">px</span><span style="color: #000000">;<br />}<br />  <br /></span>.frame-outer span span span span <span style="color: #000000">{<br /></span> background<span style="color: #000000">:</span> none<span style="color: #000000">;<br />}</span></span>
</blockquote>

<p>Here’s a sample of the images that are used here:</p>

<div style="text-align: center;">
  <img src="http://atastypixel.com/blog/wp-content/uploads/2008/10/framing-images.jpg" width="400" height="400" alt="framing-images.jpg" title="framing-images.jpg" class="noframe" /><br />
</div>

<h3>Further possibilities</h3>

<p>Providing frames around image is all very well, but what if that’s not enough? Perhaps you have a particular style set up that requires, say, rounded corners, or Aqua-style bubbles, or sepia tones? Maybe something more complicated, as with Webdemar’s page: Rounded corners, a dark border with a light inner-border, a gradient background, then the image itself rotated a bit then cropped.</p>

<p>It just so happens, there’s a whole lot one can do with the PHP ‘GD’ image processing library, if you’re willing to get your hands dirty. Imagemagick’s ‘convert’ utility is fairly capable too. This is outside the scope of this article, but I may return to the topic another time.</p>

<p>So, one possibility is to add an additional function that is called, which extracts the URL of any image, opens and processes the image, saves it to a local cache, and replaces the URL with a URL to the newly created, cached image. This function could do all kinds of nifty operations on the image, with zero work required on the part of the user.</p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=921" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/advanced-web-templating-with-php-and-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

