<?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>Extensible Development &#187; css sprites</title>
	<atom:link href="http://blog.itwarlocks.com/tag/css-sprites/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.itwarlocks.com</link>
	<description>Profession blog about Software Engineering, Web, *nix, Processes, Tools and more.</description>
	<lastBuildDate>Mon, 29 Mar 2010 12:20:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Float overflow can be useful too</title>
		<link>http://blog.itwarlocks.com/2009/05/08/float-overflow-can-be-useful-too/</link>
		<comments>http://blog.itwarlocks.com/2009/05/08/float-overflow-can-be-useful-too/#comments</comments>
		<pubDate>Fri, 08 May 2009 21:13:03 +0000</pubDate>
		<dc:creator><span property="dc:creator" resource="http://blog.itwarlocks.com/2009/05/08/float-overflow-can-be-useful-too/">Jeffrey Ridout</span></dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css sprites]]></category>
		<category><![CDATA[icons]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[style]]></category>

		<guid isPermaLink="false">http://blog.itwarlocks.com/?p=140</guid>
		<description><![CDATA[Introduction
Looking at the list of tags at the bottom of my posts, I noticed that when the amount of tags gets bigger, strange things happen to the style. When the text width gets too big to fit next to the category tags, it&#8217;s naetly moved down. But when it gets even bigger the text gets [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<div id="attachment_143" class="wp-caption alignright" style="width: 426px"><a title="Image 1, Common tag line without any style problems." rel="lightbox-140" href="http://blog.itwarlocks.com/wp-content/uploads/2009/05/single-line-short.png"><img class="size-full wp-image-143" title="single-line-short" src="http://blog.itwarlocks.com/wp-content/uploads/2009/05/single-line-short.png" alt="Common tag line without any style problems." width="416" height="23" /></a><p class="wp-caption-text">Image 1, Common tag line without any style problems.</p></div>
<p>Looking at the list of tags at the bottom of my posts, I noticed that when the amount of tags gets bigger, strange things happen to the style. When the text width gets too big to fit next to the category tags, it&#8217;s naetly moved down. But when it gets even bigger the text gets clipped. Changing the style so the text fits easily solved that problem.</p>
<div id="attachment_142" class="wp-caption alignnone" style="width: 621px"><a title="Image 2, Wide tag line without any style problems." rel="lightbox-140" href="http://blog.itwarlocks.com/wp-content/uploads/2009/05/multi-line-short.png"><img class="size-full wp-image-142" title="multi-line-short" src="http://blog.itwarlocks.com/wp-content/uploads/2009/05/multi-line-short.png" alt="Image 2, Wide tag line without any style problems." width="611" height="51" /></a><p class="wp-caption-text">Image 2, Wide tag line without any style problems.</p></div>
<pre class="brush: css">.post .content .under span {
float:    left;
/* Make the span change height to prevent the text from being clipped. */
height:    auto;
margin-right:    15px;
/* Add padding to the left for the image. */
padding-left:    22px;
}</pre>
<div id="attachment_141" class="wp-caption alignnone" style="width: 612px"><a title="Image 3, Long tag line with wrong background." rel="lightbox-140" href="http://blog.itwarlocks.com/wp-content/uploads/2009/05/multi-line-long-wrong.png"><img class="size-full wp-image-141" title="multi-line-long-wrong" src="http://blog.itwarlocks.com/wp-content/uploads/2009/05/multi-line-long-wrong.png" alt="Image 3, Long tag line with wrong background." width="602" height="55" /></a><p class="wp-caption-text">Image 3, Long tag line with wrong background.</p></div>
<p>But whoops, what&#8217;s with the background image? Using CSS Sprites and fluid/elastic layout doesn&#8217;t quite seem to work together&#8230;<br />
Im my efforts to make this website&#8217;s themes more &#8220;elastic&#8221; I had to find a solution.<br />
<span id="more-140"></span></p>
<h3>Experiments</h3>
<p>I first tried to find CSS properties that could be applied directly to the containing SPAN.<br />
Setting float to &#8216;none&#8217; and display to &#8216;inline&#8217; will make the text &#8220;hanging&#8221;. This actually means that each line will receive it&#8217;s own &#8220;box&#8221; with only the first box having a padding and background.</p>
<pre class="brush: css">.post .content .under span {
display:    inline;
float:    none;
height:    auto;
margin-right:    15px;
padding-left:    22px;
}</pre>
<div id="attachment_152" class="wp-caption alignnone" style="width: 418px"><a title="Image 4, Tag line with hanging text." rel="lightbox-140" href="http://blog.itwarlocks.com/wp-content/uploads/2009/05/multi-line-inline.png"><img class="size-full wp-image-152" title="multi-line-inline" src="http://blog.itwarlocks.com/wp-content/uploads/2009/05/multi-line-inline.png" alt="Image 4, Tag line with hanging text." width="408" height="167" /></a><p class="wp-caption-text">Image 4, Tag line with hanging text.</p></div>
<p>Unfortunately not floating is not optional and hanging text is not what we want either.<br />
So&#8230; how can I get a floating box with a background that ignores the content and stays 16px high?<br />
What property do floats have that can be used and that&#8217;s been a thorn in many eyes?</p>
<h3>Solution</h3>
<p>Overflow! Floats tend to reach outside the containing box making their parent unaware of their size. (The containing box is actually secretly aware of the float&#8217;s size, check this by turning on &#8216;outline&#8217;.)</p>
<div id="attachment_157" class="wp-caption alignnone" style="width: 415px"><a title="Image 5, Float overflow." rel="lightbox-140" href="http://blog.itwarlocks.com/wp-content/uploads/2009/05/float-left-outside.png"><img class="size-full wp-image-157" title="float-left-outside" src="http://blog.itwarlocks.com/wp-content/uploads/2009/05/float-left-outside.png" alt="Image 5, Float overflow." width="405" height="211" /></a><p class="wp-caption-text">Image 5, Float overflow.</p></div>
<p>If we create a containing span and make the content a floating block, then the container can contain the background image and won&#8217;t be affected by the content&#8217;s size.<br />
The content block used to have a background and padding to show an &#8220;icon&#8221;, so we start by adding a container.</p>
<div id="attachment_156" class="wp-caption alignnone" style="width: 412px"><a href="http://blog.itwarlocks.com/wp-content/uploads/2009/05/multi-line-float-img-wrong.png"><img class="size-full wp-image-156" title="multi-line-float-img-wrong" src="http://blog.itwarlocks.com/wp-content/uploads/2009/05/multi-line-float-img-wrong.png" alt="Image 6, Content block with background." width="402" height="221" /></a><p class="wp-caption-text">Image 6, Content block with background.</p></div>
<p>We can then move the background to the container and lock it&#8217;s height.</p>
<div id="attachment_154" class="wp-caption alignnone" style="width: 415px"><a href="http://blog.itwarlocks.com/wp-content/uploads/2009/05/multi-line-float-img-container.png"><img class="size-full wp-image-154" title="multi-line-float-img-container" src="http://blog.itwarlocks.com/wp-content/uploads/2009/05/multi-line-float-img-container.png" alt="Image 7, Container with background." width="405" height="264" /></a><p class="wp-caption-text">Image 7, Container with background.</p></div>
<p>Great, this is what we wanted all along! But there&#8217;s one final step left.<br />
Since the container doesn&#8217;t &#8220;contain&#8221; the actual content, but the content flows out, we need one more container around the whole. This outer container can be &#8220;floating-content-aware&#8221;.</p>
<div id="attachment_155" class="wp-caption alignnone" style="width: 411px"><a href="http://blog.itwarlocks.com/wp-content/uploads/2009/05/multi-line-float-img-right.png"><img class="size-full wp-image-155" title="multi-line-float-img-right" src="http://blog.itwarlocks.com/wp-content/uploads/2009/05/multi-line-float-img-right.png" alt="Image 8, Final result." width="401" height="217" /></a><p class="wp-caption-text">Image 8, Final result.</p></div>
<div class="wp-caption">Listing 1: Final HTML</div>
<pre class="brush: html">&lt;span class=&quot;outer-container&quot;&gt;
    &lt;span class=&quot;icon-container&quot;&gt;
        &lt;div class=&quot;content&quot;&gt;Lorem impsum, dolor&lt;/div&gt;
    &lt;/span&gt;
&lt;/span&gt;</pre>
<div class="wp-caption">Listing 2: Final CSS</div>
<pre class="brush: css">
.outer-container {
    float:    left;
    height:    auto;
    margin:    0;
    overflow:    auto;
    padding:    0;
}
.icon-container {
    background-image:    url(css-sprite.png);
    background-position:    0 16px;
    background-repeat:    no-repeat;
    float:    none;
    height:    16px;
    margin-right:    15px;
    overflow:    visible;
    padding-left:    22px;
}
.content {
    display:    block;
    float:    left;
    padding:    0;
    margin:    0;
}
</pre>
<div id="attachment_162" class="wp-caption alignnone" style="width: 609px"><a title="Image 9, Tag line with correct style." rel="lightbox-140" href="http://blog.itwarlocks.com/wp-content/uploads/2009/05/multi-line-long-right.png"><img class="size-full wp-image-162" title="multi-line-long-right" src="http://blog.itwarlocks.com/wp-content/uploads/2009/05/multi-line-long-right.png" alt="Image 9, Tag line with correct style." width="599" height="54" /></a><p class="wp-caption-text">Image 9, Tag line with correct style.</p></div>
<h3>Conclusion</h3>
<p>A better solution would have been to use clipping on the background image, but that&#8217;s not present in CSS 2.1, CSS 3 or Mozilla&#8217;s specifications. Mozilla has an isue on this (<a title="Bugzilla: -moz-background-image-region" href="https://bugzilla.mozilla.org/show_bug.cgi?id=113577" target="_blank">113577</a>, please vote!), so I&#8217;m hoping this will make it to Firefox 3.5. W3C has nothing on it, so I contacted the &#8220;CSS 3, Background and Border&#8221; WorkGroup. Let&#8217;s hope for the best.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.itwarlocks.com/2009/05/08/float-overflow-can-be-useful-too/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)

Served from: blog.itwarlocks.com @ 2010-09-05 05:53:03 -->