<?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>bweaver.net &#187; web design</title>
	<atom:link href="http://bweaver.net/taxonomy/tags/web-design/feed" rel="self" type="application/rss+xml" />
	<link>http://bweaver.net</link>
	<description>web design, technology, photography, and other mayhem</description>
	<lastBuildDate>Sat, 22 Aug 2009 17:06:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Left-Align Lists With Margin Bullets</title>
		<link>http://bweaver.net/left-align-lists-with-margin-bullets</link>
		<comments>http://bweaver.net/left-align-lists-with-margin-bullets#comments</comments>
		<pubDate>Sun, 26 Oct 2008 02:40:33 +0000</pubDate>
		<dc:creator>bill weaver</dc:creator>
				<category><![CDATA[web design]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://bweaver.net/?p=124</guid>
		<description><![CDATA[Left-align lists with bullets in the margin Though Firefox allows you to move bullets out of the list&#8217;s div, Internet Explorer does not. In IE, bullets are clipped if they are moved out of the box. However, by including an image at the beginning of the list items, then using CSS to align the remainder [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Left-align lists with bullets in the margin</strong></p>
<p>Though Firefox allows you to move bullets out of the list&#8217;s div, Internet Explorer does not. In IE, bullets are clipped if they are moved out of the box.</p>
<p>However, by including an image at the beginning of the list items, then using CSS to align the remainder of the list item to the left margin works just fine.</p>
<p>Of course, that&#8217;s kind of ugly.</p>
<p><strong>Enter jQuery</strong></p>
<p>However, javascript can be used to do this automatically, and jQuery can further simplify this work.</p>
<p><strong>HTML</strong></p>
<p>For the HTML, simply tag the unordered list with a unique classname, in this case, &#8220;test&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;ul class=&quot;test&quot;&gt;
&lt;li&gt;item 1&lt;/li&gt;
&lt;li&gt;item 2&lt;/li&gt;
&lt;/ul&gt;</pre></div></div>

<p><strong>Javascript</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> styleList<span style="color: #009900;">&#40;</span> cls<span style="color: #339933;">,</span> imgwidth<span style="color: #339933;">,</span> imgsrc <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul.&quot;</span> <span style="color: #339933;">+</span> cls <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; li&quot;</span><span style="color: #009900;">&#41;</span>
		.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;list-style-type&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;none&quot;</span><span style="color: #009900;">&#41;</span>
		.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;text-indent&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;-&quot;</span> <span style="color: #339933;">+</span> imgwidth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul.&quot;</span> <span style="color: #339933;">+</span> cls <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; li&quot;</span><span style="color: #009900;">&#41;</span>
		.<span style="color: #660066;">prepend</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;img class=<span style="color: #000099; font-weight: bold;">\&quot;</span>listitemimage<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">+</span>
			<span style="color: #3366CC;">&quot;src=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">+</span> imgsrc <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul.&quot;</span> <span style="color: #339933;">+</span> cls<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;padding&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;margin&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.listitemimage&quot;</span><span style="color: #009900;">&#41;</span>
		.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;position&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;relative&quot;</span><span style="color: #009900;">&#41;</span>
		.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;-&quot;</span> <span style="color: #339933;">+</span> imgwidth<span style="color: #009900;">&#41;</span>
		.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;top&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;-2px&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	styleList<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;test&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;9px&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;/code/bullet01.gif&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Basically, styleList takes a CSS class name that identifies the unordered lists to style. It sets list padding and margins to 0. Then, for list items, it sets list-style-type to none to remove the default bullet and sets a negative text-indent to compensate for the space taken by the bullet image. To each list item it prepends the bullet image. The .listitemimage class is styled to relative positioning, given a negative left shift equal to the width of the bullet, and bumped up a bit.</p>
<p><strong>Demo</strong></p>
<p>Check out the <a href="http://bweaver.net/code/marginbulletsdemo.html">demo of left-aligned lists and margin bullets</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bweaver.net/left-align-lists-with-margin-bullets/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wrangling Drop Caps</title>
		<link>http://bweaver.net/wrangling-drop-caps</link>
		<comments>http://bweaver.net/wrangling-drop-caps#comments</comments>
		<pubDate>Mon, 17 Mar 2008 23:50:33 +0000</pubDate>
		<dc:creator>bill weaver</dc:creator>
				<category><![CDATA[web design]]></category>
		<category><![CDATA[art]]></category>
		<category><![CDATA[Bible]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://bweaver.net/wrangling-with-drop-caps</guid>
		<description><![CDATA[.firstp{ font-size:1.5em; line-height:1.25; text-decoration: none; text-align: justify; color: #555; } .firstp:first-line { font-variant:small-caps; } .firstp:first-letter { font-size:4.5em; line-height:1; float:left; padding:0 .05em 0 0; margin:-.15em 0 -.2em -.05em; color:#aaa; } Setting the initial letter of a page&#8212;or chapter, or section&#8212;in larger type and dropping it down a bit into the text is similar to decorated initials [...]]]></description>
			<content:encoded><![CDATA[<style>
.firstp{
font-size:1.5em;
line-height:1.25;
text-decoration: none;
text-align: justify;
color: #555;
}
.firstp:first-line {
font-variant:small-caps;
}
.firstp:first-letter {
font-size:4.5em;
line-height:1;
float:left;
padding:0 .05em 0 0;
margin:-.15em 0 -.2em -.05em;
color:#aaa;
}
</style>
<p class="firstp">Setting the initial letter of a page&mdash;or chapter, or section&mdash;in larger type and dropping it down a bit into the text is similar to <em>decorated initials</em> common in illuminated manuscripts, such as the breathtaking <a href="http://www.sjbible.org/Custom.aspx?VID=1">Saint John&#8217;s Bible</a>, and of course, in the world of print. Initial <em>drop caps</em> are fairly simple to accomplish on the web with CSS and the <em>:first-letter</em> pseudo-selector. But, as you might guess, the differences amongst various browsers can make this a frustrating exercise.</p>
<p>Often combined with initial drop caps, another common typesetting flourish is to set the remainder of the first word, first several words, or the entire first line in <em>small caps</em>. Here you use the CSS <em>:first-line</em> pseudo-selector, though it too suffers from a few browser peculiarities.</p>
<h3>Pseudo-selector Basics</h3>
<p>Pseudo-selectors, or pseudo-elements, give a designer the flexibility to style portions of the document that are not distinct elements within the DOM. The <a href="http://www.w3.org/TR/REC-CSS2/selector.html#pseudo-elements">W3 definition</a> is as follows.</p>
<blockquote><p>Pseudo-elements create abstractions about the document tree beyond those specified by the document language. For instance, document languages do not offer mechanisms to access the first letter or first line of an element&#8217;s content. CSS pseudo-elements allow style sheet designers to refer to this otherwise inaccessible information.</p></blockquote>
<p><strong>:first-letter</strong> controls everything up to the first letter or number of an element, including punctuation, while <strong>:first-line</strong>, controls everything in the first line of an element. We will be building CSS rules with these selectors to create initial drop caps in a first line of small caps.</p>
<p><strong>The Challenge</strong></p>
<p>The eventual goal for the examples below is to style only the first paragraph of a content page from a CMS (such as WordPress), and assumes that the paragraph follows an h2 element.</p>
<p><strong>The Solution(s)</strong></p>
<p>There are a few approaches to using first-letter and first-line pseudo-selectors. One is to assign an explicit class to the element you wish to style. Another is to use preceding selector notation to target the CSS rule. A third method uses Javascript (jQuery in this article) to make things happen. All three approaches are covered in this article.</p>
<h3>Explicit Class Solution</h3>
<p>The first option is to assign an explicit class to the target element, and apply the pseudo-selector to that class, as shown in the next several examples. Setting the element class will look something like the following example, where the paragraph is given the class <code>someclass</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;someclass&quot;</span>&gt;</span>Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Donec ullamcorper mauris sit amet
ante. Donec convallis nisl malesuada eros. Nullam volutpat
quam non elit.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span></pre></div></div>

<p>(For the examples in this article, all sample output elements also use a class of _examples&mdash;shown below&mdash;that sets the font size to 16 pixels and the line height to twice that. So the code above would use <code>class="someclass _examples"</code> to combine the two.)</p>
<style>
._examples{
font-size:16px;
line-height:32px;
border:1px solid #ccc;
background-color:#fffff0;
padding:1em;
margin-bottom:2em;
}
</style>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">._examples<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">32px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><strong>Initial Capital</strong></p>
<p>The following CSS rule sets the font size for the first letter of the example1 class to 32px (two em).</p>
<style>
.example1:first-letter{
font-size:32px;
}
</style>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.example1</span><span style="color: #3333ff;">:first-letter</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">32px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p class="example1 _examples">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec ullamcorper mauris sit amet ante. Donec convallis nisl malesuada eros. Nullam volutpat quam non elit.</p>
<p><strong>Small Caps</strong></p>
<p>To set the first line in small caps, we will use the font-variant property, as shown below.</p>
<style>
.example2:first-line{
font-variant:small-caps;
}
</style>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.example2</span><span style="color: #3333ff;">:first-line</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">font-variant</span><span style="color: #3333ff;">:small-</span>caps<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p class="example2 _examples">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec ullamcorper mauris sit amet ante. Donec convallis nisl malesuada eros. Nullam volutpat quam non elit.</p>
<p>Put example1 and example2 together and we get the two combined styles, shown below.</p>
<p class="example1 example2 _examples">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec ullamcorper mauris sit amet ante. Donec convallis nisl malesuada eros. Nullam volutpat quam non elit.</p>
<p><strong>Dropping The First Letter</strong></p>
<p>That looks nice, but tweaking things will make things look even better. The key is to float the letter to the left and move it down, then adjust to taste.</p>
<style>
.example4:first-line{
font-variant:small-caps;
}
.example4:first-letter{
font-variant:none;
font-size:64px;
float:left;
margin:-.06em .1em -.3em -.1em;
line-height:1;
}
</style>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.example4</span><span style="color: #3333ff;">:first-line</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">font-variant</span><span style="color: #3333ff;">:small-</span>caps<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.example4</span><span style="color: #3333ff;">:first-letter</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">font-variant</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">64px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">-.06em</span> <span style="color: #933;">.1em</span> <span style="color: #933;">-.3em</span> <span style="color: #933;">-.1em</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>For this example, there are several adjustments to the first letter rule to produce something like the text below.</p>
<p class="example4 _examples">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec ullamcorper mauris sit amet ante. Donec convallis nisl malesuada eros. Nullam volutpat quam non elit.</p>
<p>The first letter adjustments include applying a left float, bumping the font size up to 64px, then tweaking the margins and line height.</p>
<p>Setting the first letter size to 64 pixels is a matter of taste, but essentially makes the first letter approximately the size of two lines. The margin adjustments accomplish a few things. The top margin moves the baseline of the letter up to the bottom of the second line; the right margin adds a bit of space after the large initial letter; the bottom margin chops the invisible space below the letter so the following line will flow under it; and the left margin cheats the big serifs a bit into the left margin to the meat of the letter aligns with the smaller text below it.</p>
<p>And this is where browser discrepancies bite us. In Internet Explorer, the top margin used above do not work to lower the &#8220;L&#8221; into the text as they do in Firefox. In IE we need to adjust the line height to make it work.</p>
<h3>h2 + p Solution</h3>
<p>In this approach, we set up <code>h2 + p:first-letter</code> and <code>h2 + p:first-line</code> rules (or h3, etc.). The advantage here is that additional tagging is unnecessary, and nicely separates content from display.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">h2 <span style="color: #00AA00;">+</span> p<span style="color: #3333ff;">:first-letter </span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">3em</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
h2 <span style="color: #00AA00;">+</span> p<span style="color: #3333ff;">:first-line </span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">font-variant</span><span style="color: #3333ff;">:small-</span>caps<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Unfortunately, IE 6 fails to handle the element-preceding notation (+) when combined with a pseudo-element such as :first-line or :first-letter. It does not hurt anything; your styling will simply not be applied in IE 6.</p>
<p>Another potential ill-effect is the need to avoid multiple h2 tags per page, unless we want multiple first-letter / first-line styling.</p>
<p>Also, this can work if we do not care about IE 6 (or can accept the graceful downgrade) and can control the content tagging such that a single element such as h2 is followed by the paragraph in need of special styling.</p>
<h3>The jQuery Solution</h3>
<p>Here we use jQuery to tear apart then rebuild the target paragraph to explicitly invoke the correct CSS rules.</p>
<p>This solution works in IE 6 (but not IE 5.5 and below).</p>
<p>Include jQuery and the following script:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;h2 + p:eq(0)&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> t <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> f <span style="color: #339933;">=</span> t.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> l <span style="color: #339933;">=</span> t.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">browser</span>.<span style="color: #660066;">opera</span><span style="color: #009900;">&#41;</span>
			t <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;div class='operap'&gt;&quot;</span> <span style="color: #339933;">+</span> t <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">else</span> t <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;div class='firstp'&gt;&quot;</span> <span style="color: #339933;">+</span> t <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replaceWith</span><span style="color: #009900;">&#40;</span> t <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The code uses jQuery&#8217;s selector logic to target <code>h2 + p:eq(0)</code>, and simply replaces the paragraph with a <code>div</code> of class <code>firstp</code>. An advantage of this approach is that you do not have to explicitly tag the first paragraph by hand. Also <code>h2 + p:eq(0)</code> is specific enough to target the first paragraph after the first h2 element <em>and</em> it because jQuery is doing the heavy lifting, it works in IE 6. Which brings us to Opera.</p>
<p><strong>More Browser Disagreements</strong></p>
<p>All this works fine in Opera, except the top margin and a little rendering issue.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">browser</span>.<span style="color: #660066;">opera</span><span style="color: #009900;">&#41;</span>
		t <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;div class='operap'&gt;&quot;</span> <span style="color: #339933;">+</span> t <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">else</span> t <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;div class='firstp'&gt;&quot;</span> <span style="color: #339933;">+</span> t <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replaceWith</span><span style="color: #009900;">&#40;</span> t <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The code above uses a special class with a top margin for :first-letter of 0 if it&#8217;s running in Opera, otherwise it uses the normal class that works for IE and Firefox. Then, it hides the target element, sets the HTML, then makes the element visible again. This is because Opera does not correctly re-render the element after the HTML has been changed. This forces the re-render to happen in Opera. (The curious syntax in this last line is an example of chaining jQuery calls.)</p>
<h3>Demo</h3>
<p>Check out the <a href="http://bweaver.net/code/dropcapdemo.html">demo of first-letter and first-line pseudo-selectors</a> used in conjunction with jQuery.</p>
]]></content:encoded>
			<wfw:commentRss>http://bweaver.net/wrangling-drop-caps/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
