<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" version="2.0"><channel><title>Bolo的博客</title><link>http://blog.imbolo.com</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/bolo" /><description>一个设计爱好者杂七杂八的博客</description><language>en</language><lastBuildDate>Wed, 21 Jul 2010 23:03:02 PDT</lastBuildDate><generator>http://wordpress.org/?v=2.9.2</generator><sy:updatePeriod xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">hourly</sy:updatePeriod><sy:updateFrequency xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">1</sy:updateFrequency><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/bolo" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="bolo" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">bolo</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bloglines.com/sub/http://feeds.feedburner.com/bolo" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.newsalloy.com/?rss=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://www.newsalloy.com/subrss3.gif">Subscribe with NewsAlloy</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://download.attensa.com/app/get_attensa.html?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://www.attensa.com/blogs/attensa/WindowsLiveWriter/BadgeredintoBadges_10C02/attensa_feed_button5.gif">Subscribe with Attensa for Outlook</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.flurry.com/pushRssFeed.do?r=fb&amp;url=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://www.flurry.com/images/flurry_rss_logo2.gif">Subscribe with Flurry</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2Fbolo" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item><title>CSS 屏蔽 Webkit 浏览器 input 高亮和 textarea 缩放</title><link>http://blog.imbolo.com/css-turn-off-webkit-browsers-input-highlight-and-textarea-resize/</link><category>CSS</category><category>WEB</category><category>Webkit</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">bolo</dc:creator><pubDate>Wed, 21 Jul 2010 23:03:02 PDT</pubDate><guid isPermaLink="false">http://blog.imbolo.com/?p=1918</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/EaZbpJ9UQK3Deb6H_3Z_vB_cyig/0/da"><img src="http://feedads.g.doubleclick.net/~a/EaZbpJ9UQK3Deb6H_3Z_vB_cyig/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/EaZbpJ9UQK3Deb6H_3Z_vB_cyig/1/da"><img src="http://feedads.g.doubleclick.net/~a/EaZbpJ9UQK3Deb6H_3Z_vB_cyig/1/di" border="0" ismap="true"></img></a></p><p><strong>采用 Webkit 核心的浏览器主要有苹果的 Safari 和 Google 的 Chrome</strong>，Webkit 核心有着良好的性能，并且在某些细节对用户非常友好，页面输入框（input 标签）聚焦高亮和文本框（textarea 标签）缩放功能就是其中的两个对用户非常友好的设计。可是这两个设计在对用户友好的同时，却会对页面设计产生影响。</p>
<h3>CSS 屏蔽 Webkit 输入框高亮</h3>
<p>下面是默认情况下，Webkit 浏览器里输入框获取焦点时的情况。<br />
<img src="http://i1001.photobucket.com/albums/af131/bolo1988/1-4.png" alt="Webkit input 聚焦高亮" /><br />
我们可以发现 Webkit 对输入框的高亮已经使页面呈现出的样式和设计样式不同了。如果<strong>你的网站已经对输入框获取焦点时定义了特殊的样式</strong>，不妨把 Webkit 这个多此一举的功能屏蔽掉。加上下面的 CSS 就可以轻松地把高亮去掉。<span id="more-1918"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">input <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #808080; font-style: italic;">/* 屏蔽文本框高亮 */</span>
textarea <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3>CSS 屏蔽 Webkit 文本框缩放</h3>
<p>Webkit 的文本框缩放功能原本是方便用户进行大量文本输入而设计的，但有时果度的缩放会造成下图的效果，打乱了页面的布局。如果你的网站已经为用户提供了足够大的空间让用户进行输入，那么你可以屏蔽这个功能，用 CSS 有两种方法。<br />
<img src="http://i1001.photobucket.com/albums/af131/bolo1988/2-4.png" alt="CSS 屏蔽 Webkit 文本框缩放" /></p>
<h5>CSS 2.1 的方法：</h5>
<p>原理：限制文本框的最大宽度和最大高度，使其和设计的大小一样。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">textarea <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">400px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">max-width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">400px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">400px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">max-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">400px</span><span style="color: #00AA00;">;</span></pre></td></tr></table></div>

<h5>CSS3 的方法：</h5>
<p>通过 resize 属性禁止对元素进行缩放，因为 Chrome 对 CSS3 支持良好，因此推荐使用这个方法。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">texearea <span style="color: #00AA00;">&#123;</span>
	resize<span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/center-multiple-divs-with-css/" title="CSS 多个子框架居中">CSS 多个子框架居中</a></li><li><a href="http://blog.imbolo.com/the-css3-flexible-box-model/" title="CSS3 灵活的盒子模型(Flexible Box Module) &#8211; 1">CSS3 灵活的盒子模型(Flexible Box Module) &#8211; 1</a></li><li><a href="http://blog.imbolo.com/web-rounded-conner-choice/" title="网页圆角的取舍">网页圆角的取舍</a></li><li><a href="http://blog.imbolo.com/10-css-snippets-to-save-time/" title="10个节约开发时间的CSS技巧">10个节约开发时间的CSS技巧</a></li><li><a href="http://blog.imbolo.com/css-beveled-corners/" title="纯CSS打造斜角">纯CSS打造斜角</a></li></ul><img src="http://feeds.feedburner.com/~r/bolo/~4/a_WFSDrYmek" height="1" width="1"/>]]></content:encoded><description>采用 Webkit 核心的浏览器主要有苹果的 Safari 和 Google 的 Chrome，Webkit 核心有着良好的性能，并且在某些细节对用户非常友好，页面输入框（input 标签）聚焦高亮和文本框（textarea 标签）缩放功能就是其中的两个对用户非常友好的设计。可是这两个设计在对用户友好的同时，却会对页面设计产生影响。</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.imbolo.com/css-turn-off-webkit-browsers-input-highlight-and-textarea-resize/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">11</slash:comments></item><item><title>为 WordPress 3.0 自定义菜单添加描述</title><link>http://blog.imbolo.com/improve-wordpress-navigation-menu-output/</link><category>WordPress</category><category>Skill</category><category>Theme</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">bolo</dc:creator><pubDate>Mon, 19 Jul 2010 23:04:42 PDT</pubDate><guid isPermaLink="false">http://blog.imbolo.com/?p=1914</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/WuXTiE_ZxWSBtWiepcM64X_wqo8/0/da"><img src="http://feedads.g.doubleclick.net/~a/WuXTiE_ZxWSBtWiepcM64X_wqo8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/WuXTiE_ZxWSBtWiepcM64X_wqo8/1/da"><img src="http://feedads.g.doubleclick.net/~a/WuXTiE_ZxWSBtWiepcM64X_wqo8/1/di" border="0" ismap="true"></img></a></p><p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/1-3.png" alt="WordPress 带描述的菜单" /></p>
<p>WordPress 3.0 增加了一个强大的自定义菜单功能，但美中不足是要实现题图这样包含描述的菜单时，单靠目前 WordPress 的功能还无法实现。本文将教你改变 WordPress 默认的菜单输出，打造更加个性的菜单。</p>
<p>也许你已经知道，当后台出现 <strong>Appearance > Menus</strong> 这个菜单项的时候，就标明你使用的主题支持 WordPress 3.0 自定义菜单。只需要用 <a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu">wp_nav_menu()</a> 函数进行调用即可。但问题是 WordPress 输出的菜单 HTML 结构如下：<span id="more-1914"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="html4strick" style="font-family:monospace;">&lt;ul id=&quot;menu-main&quot;&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;About&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Contact&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Blog&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre></td></tr></table></div>

<p>但我们需要的是像下面这种结构的菜单：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="html4strick" style="font-family:monospace;">&lt;ul id=&quot;menu-main&quot;&gt;
     &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;strong&gt;Home&lt;/strong&gt;&lt;span&gt;Description&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
     &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;strong&gt;About&lt;/strong&gt;&lt;span&gt;Description&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
     &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;strong&gt;Contact&lt;/strong&gt;&lt;span&gt;Description&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
     &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;strong&gt;Blog&lt;/strong&gt;&lt;span&gt;Description&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre></td></tr></table></div>

<p>通过对比，很明显 WordPress 默认输出的菜单结构并不能满足我们的要求。我们需要做的是先为每个菜单项写上 description，然后添加一个 filter 对 WordPress 输出的菜单进行整理。</p>
<p>在 <strong>Appearance > Menus</strong> 页面，菜单项的 description 输入框默认是隐藏的，我们可以在页顶的 <strong>Screen Options</strong> 里把 <strong>Description</strong> 勾上。<br />
<img src="http://i1001.photobucket.com/albums/af131/bolo1988/2-3.png" alt="显示菜单项描述输入框" /><br />
然后我们就开始为菜单项加上描述吧！<br />
<img src="http://i1001.photobucket.com/albums/af131/bolo1988/3-3.png" alt="填写菜单项描述" /><br />
在默认情况下，WordPress 已经自动为 Page 菜单项写上了长长的描述，在这里我们可以把这些描述改为自己喜欢的内容。</p>
<p>接下来我们要写一个 filter 用来整理 WordPress 输出的菜单代码。<a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu">wp_nav_menu()</a> 函数有一个 <strong>walker</strong> 参数，我们通过这个参数来调用 filter。下面是 filter 的代码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> description_walker <span style="color: #000000; font-weight: bold;">extends</span> Walker_Nav_Menu
<span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">function</span> start_el<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$output</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span><span style="color: #339933;">,</span> <span style="color: #000088;">$depth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
           <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$indent</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$depth</span> <span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">str_repeat</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$depth</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #000088;">$class_names</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #000088;">$classes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">classes</span> <span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">classes</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #000088;">$class_names</span> <span style="color: #339933;">=</span> <span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> apply_filters<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'nav_menu_css_class'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array_filter</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$classes</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$class_names</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">' class=&quot;'</span><span style="color: #339933;">.</span> esc_attr<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$class_names</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$indent</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;li id=&quot;menu-item-'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$class_names</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #000088;">$attributes</span>  <span style="color: #339933;">=</span> <span style="color: #339933;">!</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attr_title</span> <span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">' title=&quot;'</span>  <span style="color: #339933;">.</span> esc_attr<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attr_title</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$attributes</span> <span style="color: #339933;">.=</span> <span style="color: #339933;">!</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">target</span> <span style="color: #009900;">&#41;</span>     ? <span style="color: #0000ff;">' target=&quot;'</span> <span style="color: #339933;">.</span> esc_attr<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">target</span>     <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$attributes</span> <span style="color: #339933;">.=</span> <span style="color: #339933;">!</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xfn</span> <span style="color: #009900;">&#41;</span>        ? <span style="color: #0000ff;">' rel=&quot;'</span>    <span style="color: #339933;">.</span> esc_attr<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xfn</span>        <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$attributes</span> <span style="color: #339933;">.=</span> <span style="color: #339933;">!</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span> <span style="color: #009900;">&#41;</span>        ? <span style="color: #0000ff;">' href=&quot;'</span>   <span style="color: #339933;">.</span> esc_attr<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span>        <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #000088;">$prepend</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;strong&gt;'</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$append</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;/strong&gt;'</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$description</span>  <span style="color: #339933;">=</span> <span style="color: #339933;">!</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span> <span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'&lt;span&gt;'</span><span style="color: #339933;">.</span>esc_attr<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/span&gt;'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$depth</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
           <span style="color: #009900;">&#123;</span>
                     <span style="color: #000088;">$description</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$append</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$prepend</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
           <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000088;">$item_output</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">before</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$item_output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;a '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$attributes</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$item_output</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link_before</span> <span style="color: #339933;">.</span><span style="color: #000088;">$prepend</span><span style="color: #339933;">.</span>apply_filters<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'the_title'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$append</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$item_output</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$description</span><span style="color: #339933;">.</span><span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link_after</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$item_output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$item_output</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">after</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> apply_filters<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'walker_nav_menu_start_el'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item_output</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span><span style="color: #339933;">,</span> <span style="color: #000088;">$depth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>这个 filter 只是在 WordPress 默认的 walker 脚本的基础上修改了一些内容（原代码在 wp-includes/nav-menu-template.php），并且只为顶级菜单项添加描述。</p>
<p>最后一步，我们只需在调用菜单的时候告诉 WordPress：“调用这个菜单的时候使用我自己的 walker 脚本”，WordPress 就会自动生成你所需要的结构的菜单了。在调用菜单是，我们这样写：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">wp_nav_menu<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'container'</span> <span style="color: #339933;">=&gt;</span>false<span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'menu_class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'nav'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'echo'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'before'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'after'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'link_before'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'link_after'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'depth'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'walker'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> description_walker<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>要令菜单更好看的话，我们只需要编写自己喜欢的 CSS 样式即可。</p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/customizing-the-new-wordpress-3-0-custom-menus-adding-different-icons-to-each-link/" title="为 WordPress 3.0 的自定义菜单链接添加栏目图标">为 WordPress 3.0 的自定义菜单链接添加栏目图标</a></li><li><a href="http://blog.imbolo.com/inpad/" title="主题发布：Inpad">主题发布：Inpad</a></li><li><a href="http://blog.imbolo.com/custom-gravatar/" title="自定义默认Gravatar头像">自定义默认Gravatar头像</a></li><li><a href="http://blog.imbolo.com/show-the-date-of-each-post/" title="显示每篇文章的日期">显示每篇文章的日期</a></li><li><a href="http://blog.imbolo.com/ajax-posting-comments/" title="为主题添加AJAX提交评论功能">为主题添加AJAX提交评论功能</a></li></ul><img src="http://feeds.feedburner.com/~r/bolo/~4/Db919EFhYro" height="1" width="1"/>]]></content:encoded><description>WordPress 3.0 增加了一个强大的自定义菜单功能，但美中不足是要实现题图这样包含描述的菜单时，单靠目前 WordPress 的功能还无法实现。本文将教你改变 WordPress 默认的菜单输出，打造更加个性的菜单。</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.imbolo.com/improve-wordpress-navigation-menu-output/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">9</slash:comments></item><item><title>jQuery选择器详解（一）</title><link>http://blog.imbolo.com/jquery-selectors/</link><category>JavaScript</category><category>CSS</category><category>jQuery</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">bolo</dc:creator><pubDate>Sat, 17 Jul 2010 18:57:18 PDT</pubDate><guid isPermaLink="false">http://blog.imbolo.com/?p=1890</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/TyqXkRimNWVWcmCd1zzKosd7onc/0/da"><img src="http://feedads.g.doubleclick.net/~a/TyqXkRimNWVWcmCd1zzKosd7onc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/TyqXkRimNWVWcmCd1zzKosd7onc/1/da"><img src="http://feedads.g.doubleclick.net/~a/TyqXkRimNWVWcmCd1zzKosd7onc/1/di" border="0" ismap="true"></img></a></p><p>jQuery 的选择器借鉴了大量 CSS1 ~ CSS3 标准的特点，并且整理成一个强大的对象选择工具集。但要注意的是如果你的对象名里包含 “<em>#;&#038;,.+*~&#8217;:&#8221;!^$[]()=>|/</em>” 这些元字符时，你必须用 “<em>\\</em>” 进行转义。例如你要选择文档里包含 “<em>name=&#8221;names[]&#8220;</em>” 的 input 元素时，在编写过滤规则时你必须先对 “<em>[]</em>” 进行转义，所以我们应该这样定义选择器：“<em>$(&#8220;input[name=names\\[\\]]&#8221;)</em>”。<span id="more-1890"></span></p>
<h3>泛选择器（*）</h3>
<p>在 jQuery 选择器里，“*” 号是一个通配符，表示所有。例如：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;*&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;border&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;3px solid red&quot;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>上面的一句表示遍历页面里的所有容器，并且全部赋予一个线宽为 3px 的红色实线边框。还有一种情况是我们只需要对某些容器里的内容进行操作，我们可以这样写：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#test&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;*&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;border&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;3px solid red&quot;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>上一句只对 ID 为 test 的容器里的子容器产生效果，为它们加上线宽为 3px 的红色实现边框。</p>
<h3>:animated 选择器</h3>
<p>:animated 选择器是用来选择当前执行 jQuery 动画的元素的，严格来说是一个特征过滤器。例如：在空 HTML 文档里建一些 Div ，其中一个 ID 为 mover ，然后编写以下的 jQuery 语句</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mover&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideToggle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #339933;">,</span> animateIt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div:animated&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggleClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;colored&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>上面的代码执行后将先找到 ID 为 mover 的元素，并不断地进行展开和收缩的动画。然后浏览器遍历页面里所有的 Div 标签，如果该 Div （在这个例子里也就是 ID 为 mover 的 Div 了）正在执行动画的话，jQuery 将为这个 Div 加上 class=&#8221;colored&#8221;。具体的 Demo 可以看<a href="http://api.jquery.com/animated-selector/">这个页面</a>。</p>
<h3>属性选择器</h3>
<p>jQuery 的属性选择器是其所有选择器最强大的一个，也是最灵活复杂的，具体情况还可以继续进行细分。</p>
<h4>属性字头选择器（Attribute Contains Prefix Selector）</h4>
<p>jQuery 属性字头选择器的使用格式是 <strong>jQuery(&#8216;[attribute|=value]&#8216;)</strong> ，例如 <strong>jQuery(&#8216;[herflang|=en]&#8216;)</strong> 这句代码执行时将会选择文档中所有含有 herflang 属性，并且 herflang 的值以 “en” 开头的元素，即使 “en” 后面紧跟着连字符 “-” 也能进行选择。</p>
<h4>属性开头选择器（Attribute Starts With Selector）</h4>
<p><strong>jQuery(&#8216;[attribute^=value]&#8216;)</strong> ，用于选择属性的值以某个字符串开头的元素，但和 <strong>jQuery(&#8216;[attribute|=value]&#8216;)</strong> 的区别是，如果 value 的后面是一个连字符的话，这个元素不会被选择。例如 <strong>jQuery(&#8216;[rel^=no]&#8216;)</strong> 将会选择所有 rel 的值以 “no” 开头的元素，但类似于 rel=&#8221;no-****&#8221; 的元素不会被选择。</p>
<h4>属性包含选择器（Attribute Contains Selector）</h4>
<p>基本使用方法为 <strong>jQuery(&#8216;[attribute*=value]&#8216;)</strong>，例如 <strong>jQuery(&#8216;[rel*=no]&#8216;)</strong>，表示所有带有 rel 属性，并且 rel 的值里包含子字符串 “no” 的元素（如 rel=&#8221;nofollow&#8221;，rel=&#8221;yesorno&#8221; 等等）都将会被选择。</p>
<h4>属性单词选择器（Attribute Contains Word Selector）</h4>
<p><strong>jQuery(&#8216;[attribute~=value]&#8216;)</strong>，这个选择器的特别之处在于 value 的值只能必须是一个独立的单词（或者是字符串），例如 <strong>jQuery(&#8216;[rel~=no]&#8216;)</strong> ，此句在执行的时候会选择带有 rel=&#8221;yes or no&#8221; 的元素，但不会选择带有 rel=&#8221;yesorno&#8221; 的元素。这个选择器可以看做属性包含选择器的补充品，用于需要进行严格匹配的时候。</p>
<h4>属性结尾选择器（Attribute Ends With Selector）</h4>
<p><strong>jQuery(&#8216;[attribute$=value]&#8216;)</strong> ，用于选择特定属性的值以某个字符串结尾的元素，例如 <strong>jQuery(&#8216;[rel$=no]&#8216;)</strong> 将会选择 rel 属性的值以 “no” 结尾的元素。</p>
<h4>属性均等选择器（Attribute Equals Selector）</h4>
<p><strong>jQuery(&#8216;[attribute=value]&#8216;)</strong> ，只选择属性的值完全相等的元素，如：<strong>jQuery(&#8216;[rel=nofollow]&#8216;)</strong>，则只选择 rel=&#8221;nofollow&#8221; 的元素，差一点都不行！</p>
<h4>属性非等选择器（Attribute Not Equal Selector）</h4>
<p><strong>jQuery(&#8216;[attribute!=value]&#8216;)</strong> ，和 <strong>:not([attr=value])</strong> 的效果一样，用于选择属性不等于某个值的元素，例如 <strong>jQuery(&#8216;[rel!=nofollow]&#8216;)</strong>，所有 rel=&#8221;nofollow&#8221; 的元素都不会被选择。</p>
<h3>按钮选择器（:button Selector）</h3>
<p><strong>jQuery(&#8216;:button&#8217;)</strong> ，所有的 &#60;input type=&#8221;button&#8221;&#62; 和 &#60;button&#62; 元素都会被选择。</p>
<h3>Checkbox 选择器（:checkbox Selector）</h3>
<p><strong>jQuery(&#8216;:checkbox&#8217;)</strong> ，所有的 &#60;input type=&#8221;checkbox&#8221;&#62; 元素都会被选择。</p>
<h3>Checked 选择器（:checked Selector）</h3>
<p><strong>jQuery(&#8216;:checked&#8217;)</strong> ，可以看做是 Checkbox 选择器的补充，用于选择所有已经被勾选的 Checkbox 对象。</p>
<h3>子元素选择器（Child Selector）</h3>
<p><strong>jQuery(&#8216;parent > child&#8217;)</strong>，只选择 parent 的子元素（下一级元素），不对子元素以下的元素进行选择。</p>
<hr />
<p>近期忙，少更新。</p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/css-turn-off-webkit-browsers-input-highlight-and-textarea-resize/" title="CSS 屏蔽 Webkit 浏览器 input 高亮和 textarea 缩放">CSS 屏蔽 Webkit 浏览器 input 高亮和 textarea 缩放</a></li><li><a href="http://blog.imbolo.com/create-a-simple-ajax-rss-widget-with-jquery-and-yahoo-pipes/" title="利用 Yahoo Pipes 和 jQuery 做一个 RSS 挂件">利用 Yahoo Pipes 和 jQuery 做一个 RSS 挂件</a></li><li><a href="http://blog.imbolo.com/customizing-the-new-wordpress-3-0-custom-menus-adding-different-icons-to-each-link/" title="为 WordPress 3.0 的自定义菜单链接添加栏目图标">为 WordPress 3.0 的自定义菜单链接添加栏目图标</a></li><li><a href="http://blog.imbolo.com/center-multiple-divs-with-css/" title="CSS 多个子框架居中">CSS 多个子框架居中</a></li><li><a href="http://blog.imbolo.com/the-css3-flexible-box-model-2/" title="CSS3 灵活的盒子模型(Flexible Box Module) – 2">CSS3 灵活的盒子模型(Flexible Box Module) – 2</a></li></ul><img src="http://feeds.feedburner.com/~r/bolo/~4/OlZpa-cHhDk" height="1" width="1"/>]]></content:encoded><description>jQuery 的选择器借鉴了大量 CSS1 ~ CSS3 标准的特点，并且整理成一个强大的对象选择工具集。</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.imbolo.com/jquery-selectors/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">7</slash:comments></item><item><title>Android 神器级系统管理软件：Toggle Settings 汉化版</title><link>http://blog.imbolo.com/android-software-toggle-settings/</link><category>Android</category><category>Mobile</category><category>Software</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">bolo</dc:creator><pubDate>Sat, 05 Jun 2010 07:46:42 PDT</pubDate><guid isPermaLink="false">http://blog.imbolo.com/?p=1881</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/ANga1jub4SHIR35dbSZSAwZspF8/0/da"><img src="http://feedads.g.doubleclick.net/~a/ANga1jub4SHIR35dbSZSAwZspF8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ANga1jub4SHIR35dbSZSAwZspF8/1/da"><img src="http://feedads.g.doubleclick.net/~a/ANga1jub4SHIR35dbSZSAwZspF8/1/di" border="0" ismap="true"></img></a></p><p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/ToggleSettings1.png" alt="Android 系统管理软件 Toggle Settings 主界面" class="alignright" /></p>
<p>Android 作为一个优秀的手机操作系统，有着大量的软件开发者为其开发各种软件。由于目前 Android 手机用户多数为 Geek ，他们追求极致的性能，因此优秀的系统管理软件成为了必需品。今天介绍的是一款强大的 Android 系统管理软件：Toggle Settings。</p>
<h3>一个顶好几个</h3>
<p>Toggle Settings 通过同时修改多项系统设置，并保存为一个配置，使用户能迅速把手机调整到一个最适合你所处场合的状态，例如 Android 系统缺少的情景模式，通过 Toggle Settings 的环境配置可以一键切换到会议模式、户外模式等等。除了系统本来预设的集中情景外，用户还可以自己添加情景。</p>
<p>另外 Toggle Settings 还带有一个进程管理器，并且支持自动结束任务功能，进程杀手等等可以靠边站了！</p>
<p>Toggle Settings 有一个类似 Google Calendar 的实用功能，可以实现日程提醒，不习惯 Google Calendar 的人可以试试。</p>
<p>很多人习惯在 Android 安装一些桌面开关，用来随时打开或关闭蓝牙、Wifi等等，但这种桌面开关却是本来已经不大的桌面更加拥挤了。Toggle Settings 完全可以实现这些一键开关的功能，而且他能隐藏到通知栏里，要使用的时候只需要拉下通知栏并且点击 Toggle Settings 进程就能启动了。可以说是功能强大，使用方便，但一点都不会弄脏我们的桌面。<span id="more-1881"></span></p>
<h3>汉化版下载</h3>
<p><a href="http://cantonbolo.googlecode.com/files/Toggle-Settings-CN-sign.apk">http://cantonbolo.googlecode.com/files/Toggle-Settings-CN-sign.apk</a></p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/samsung-i7500-galaxy/" title="入手三星 i7500 Galaxy">入手三星 i7500 Galaxy</a></li></ul><img src="http://feeds.feedburner.com/~r/bolo/~4/AJoOvycloEI" height="1" width="1"/>]]></content:encoded><description>Android 作为一个优秀的手机操作系统，有着大量的软件开发者为其开发各种软件。由于目前 Android 手机用户多数为 Geek ，他们追求极致的性能，因此优秀的系统管理软件成为了必需品。今天介绍的是一款强大的 Android 系统管理软件：Toggle Settings。</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.imbolo.com/android-software-toggle-settings/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">23</slash:comments></item><item><title>在 WordPress 后台查看 FeedBurner 数据</title><link>http://blog.imbolo.com/access-your-feedburner-stats-from-wordpress-dashboard/</link><category>WordPress</category><category>Feed</category><category>Plugins</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">bolo</dc:creator><pubDate>Thu, 03 Jun 2010 09:53:15 PDT</pubDate><guid isPermaLink="false">http://blog.imbolo.com/?p=1876</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/OO9WbkCahmTFdthv1dfpBjUJtkU/0/da"><img src="http://feedads.g.doubleclick.net/~a/OO9WbkCahmTFdthv1dfpBjUJtkU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/OO9WbkCahmTFdthv1dfpBjUJtkU/1/da"><img src="http://feedads.g.doubleclick.net/~a/OO9WbkCahmTFdthv1dfpBjUJtkU/1/di" border="0" ismap="true"></img></a></p><p>为了管理和统计的方便，很多人会使用 FeedBurner 来烧录博客的 Feed ，今天介绍一款插件，可以在 WordPress 的后台查看自己的 FeedBurner 统计数据。</p>
<h3>打开“Awareness API”</h3>
<p>首先要做的是在 FeedBurner 里打开 Feed 的 Awareness API，否则任何人都无法通过其他途径获取你的 Feed 统计数据。在 FeedBurener 的 My Feeds 页面选择博客的 Feed ，在 Publicize 选项卡里打开 Awareness API 选项，点击 Activate 即可打开 Awareness API 功能，非常简单。<span id="more-1876"></span></p>
<p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/1-2.png" alt="开启 FeedBurner Awareness API" /></p>
<h2>安装和配置 <a href="http://www.speedbreeze.com/feed-stats/" rel="nofollow">Feed Stats for WordPress</a> 插件</h2>
<p>这个插件可以在官方插件目录找到，安装并激活以后在后台的 Setting（设置） -> Feed Stats 页面里进行设置。只需在 FeedBurner Feed URL 里填写 FeedBurner 提供的 Feed 地址，点解 Test 提示 <strong>This feed is valid.</strong> 即为成功。</p>
<p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/2-2.png" alt="配置 Feed Stats for WordPress 插件" /></p>
<p>完成配置后你马上就可以在 Dashbroad -> Feed Stats 里查看 Feed 的统计数据了，非常详细。</p>
<p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/3-2.png" alt="在 WordPress 后台查看 FeedBurner 数据" /></p>
<h3>几个重要的细节</h3>
<ul>
<li>统计数据仅在你打开 Feed Stats 页面是才会从 FeedBurner 获取，插件不会一直进行连接</li>
<li>插件默认只获取最近十天的数据</li>
</ul>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/wordpress-plugin-ibegin-share-mod/" title="WordPress 分享插件：iBegin Share (mod)">WordPress 分享插件：iBegin Share (mod)</a></li><li><a href="http://blog.imbolo.com/wordpress-microblog-plugin-wp-admin-microblog/" title="WordPress 微博插件： WP Admin Microblog">WordPress 微博插件： WP Admin Microblog</a></li><li><a href="http://blog.imbolo.com/diy-a-plugin/" title="做一个自己的插件">做一个自己的插件</a></li><li><a href="http://blog.imbolo.com/improve-the-experience-of-plugin-in-a-theme/" title="提高主题的插件体验">提高主题的插件体验</a></li><li><a href="http://blog.imbolo.com/how-to-combine-plugin-with-theme-1/" title="如何把插件集成到主题里(1)">如何把插件集成到主题里(1)</a></li></ul><img src="http://feeds.feedburner.com/~r/bolo/~4/P66QVLftH28" height="1" width="1"/>]]></content:encoded><description>为了管理和统计的方便，很多人会使用 FeedBurner 来烧录博客的 Feed ，今天介绍一款插件，可以在 WordPress 的后台查看自己的 FeedBurner 统计数据。</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.imbolo.com/access-your-feedburner-stats-from-wordpress-dashboard/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">16</slash:comments></item><item><title>利用 Yahoo Pipes 和 jQuery 做一个 RSS 挂件</title><link>http://blog.imbolo.com/create-a-simple-ajax-rss-widget-with-jquery-and-yahoo-pipes/</link><category>Develop</category><category>jQuery</category><category>JSON</category><category>RSS</category><category>WEB</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">bolo</dc:creator><pubDate>Tue, 01 Jun 2010 09:54:00 PDT</pubDate><guid isPermaLink="false">http://blog.imbolo.com/?p=1870</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/sAGYw86CARmNZPfENQA5sIsuYfM/0/da"><img src="http://feedads.g.doubleclick.net/~a/sAGYw86CARmNZPfENQA5sIsuYfM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/sAGYw86CARmNZPfENQA5sIsuYfM/1/da"><img src="http://feedads.g.doubleclick.net/~a/sAGYw86CARmNZPfENQA5sIsuYfM/1/di" border="0" ismap="true"></img></a></p><p>如果我们希望把一个网站的更新实时发布到令一个网站上，最好的方法是通过 RSS 进行转载。如果只是需要简单的对更新的条目做个提示的话，使用 JavaScript 是最可行的方法。但是通过 JavaScript 解析一个 XML 文档十分麻烦。幸好 Yahoo Pipes 为我们提供了非常好的 RSS to JSON 功能，我们可以先把 RSS 转换成 JSON 再用 JavaScript 进行解析，这样比直接解析 XML 简单得多！</p>
<h3>把 RSS 转换成 JSON</h3>
<p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/yahoopipes.png" alt="雅虎 Pipes" class="alignright" /></p>
<p>首先登录 <a href="http://pipes.yahoo.com">http://pipes.yahoo.com</a> ，新建一个 Pipe ( Creat a Pipe ) 。然后在左边的工具里选择 <strong>Sources > Fetch Feed</strong> ，在输入框里输入一个 RSS 地址。再用线把 Fetch Feed 和 Pipe Output 两个框框连起来（如右图），保存这个 Pipe，然后点击顶部的 <strong>Run Pipe&#8230;</strong> 。点击 <strong>Publish</strong> 发布这个 Pipe ，然后记下 <strong>Get as JSON 的 URL</strong>。简单几步就已经把一个 RSS 转换成 JSON 了，而且这个 JSON 会根据 RSS 的更新自动更新。<span id="more-1870"></span></p>
<h3>通过 jQuery 解析 JSON</h3>
<p>jQuery 本身为我们提供了一个 <strong>getJSON()</strong> 函数，为我们解析 JSON 提供简单快捷的方法。</p>
<p>由于我希望做一个 AJAX 载入项目的效果，我先做一个 HTML 框架，然后通过 jQuery 的 append 方法把解析出来的内容添加到指定的容器里。HTML框架如下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html4strick" style="font-family:monospace;">&lt;div id=&quot;rssdata&quot;&gt;
	&lt;ul class=&quot;rss-items&quot;&gt;&lt;/ul&gt;
	&lt;div class=&quot;loading&quot;&gt;Loading RSS items...&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;然后编写 jQuery 调用：&lt;/p&gt;</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;&gt;&lt;/script&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#rssdata'</span><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: #006600; font-style: italic;">// JSON 地址 = 刚才记下的 URL + &amp;_callback=?</span>
	<span style="color: #003366; font-weight: bold;">var</span> pipe_url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://pipes.yahoo.com/pipes/pipe.run?_id=90caf3b6ba8f36459a3137248b47620e&amp;_render=json&amp;_callback=?'</span><span style="color: #339933;">;</span>
&nbsp;
	$.<span style="color: #660066;">getJSON</span><span style="color: #009900;">&#40;</span>pipe_url<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// 遍历 JSON 项目，并且确定输出哪些信息</span>
		$<span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">value</span>.<span style="color: #660066;">items</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>index<span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> item_html <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;li&gt;&lt;a href=&quot;'</span><span style="color: #339933;">+</span><span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">link</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;'</span><span style="color: #339933;">+</span><span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">title</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/a&gt;&lt;/li&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #006600; font-style: italic;">// 把输出的内容插入页面里</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#rssdata ul.rss-items'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>item_html<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: #006600; font-style: italic;">// 添加条目载入效果</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#rssdata div.loading'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#rssdata ul.rss-items'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</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></td></tr></table></div>

<p>当然要页面美观的话，写一些 CSS 是必要的，这个可以随自己的喜好而定。最终的效果可以看这个 <a href='http://blog.imbolo.com/wp-content/uploads/2010/06/rss_widget.html'>DEMO</a>。</p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/jquery-jwtabs/" title="jQuery插件：jwTabs">jQuery插件：jwTabs</a></li><li><a href="http://blog.imbolo.com/make-a-jquery-style-switch/" title="用jQuery制作页面风格切换开关">用jQuery制作页面风格切换开关</a></li><li><a href="http://blog.imbolo.com/make-ajax-with-jquery/" title="使用 jQuery 简化 Ajax 开发">使用 jQuery 简化 Ajax 开发</a></li><li><a href="http://blog.imbolo.com/make-a-door-effect-in-jquery-and-css/" title="jQuery+CSS制作滑动门效果">jQuery+CSS制作滑动门效果</a></li><li><a href="http://blog.imbolo.com/jquery-make-the-link-background-fadein-effect/" title="jQuery实现链接背景淡出淡入效果">jQuery实现链接背景淡出淡入效果</a></li></ul><img src="http://feeds.feedburner.com/~r/bolo/~4/pl0YSYQloJo" height="1" width="1"/>]]></content:encoded><description>如果我们希望把一个网站的更新事实发布到令一个网站上，最好的方法是通过 RSS 进行转载。如果只是需要简单的对更新的条目做个提示的话，使用 JavaScript 是最可行的方法。</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.imbolo.com/create-a-simple-ajax-rss-widget-with-jquery-and-yahoo-pipes/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">24</slash:comments></item><item><title>为 WordPress 3.0 的自定义菜单链接添加栏目图标</title><link>http://blog.imbolo.com/customizing-the-new-wordpress-3-0-custom-menus-adding-different-icons-to-each-link/</link><category>WordPress</category><category>CSS</category><category>Theme</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">bolo</dc:creator><pubDate>Tue, 25 May 2010 08:18:57 PDT</pubDate><guid isPermaLink="false">http://blog.imbolo.com/?p=1854</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/vFFrZKV2BQSIxdRQkwpsijMPFEI/0/da"><img src="http://feedads.g.doubleclick.net/~a/vFFrZKV2BQSIxdRQkwpsijMPFEI/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/vFFrZKV2BQSIxdRQkwpsijMPFEI/1/da"><img src="http://feedads.g.doubleclick.net/~a/vFFrZKV2BQSIxdRQkwpsijMPFEI/1/di" border="0" ismap="true"></img></a></p><p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/custompagemenuitemicon.png" alt="WordPress 3.0 自定义菜单栏目图标" /></p>
<p>WordPress 3.0 为了增强 CMS 功能，加入了自定义菜单的功能，除了定义菜单项目外，还可以菜单定义各个项目的 CSS Class。我们可以利用这个功能来为菜单项目添加一个个性图标。</p>
<p>在 WordPress 3.0 的 Appearance（外观）-> Menus（菜单）面板里我们可以看到自定义菜单的设置，首先点击“Creat Menu”，再在左栏勾选需要的菜单项目后点击“Add to Menu”可以把勾选的项目添加到刚才建立的自定义菜单里。这是展开菜单项可以看到相关项目的参数。<span id="more-1854"></span></p>
<p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/Captura-de-pantalla-2010-05-24-a-la.png" alt="默认自定义菜单项目参数" /></p>
<p>默认情况下能修改的参数很少，这时点击屏幕左上角的“Screen Options（屏幕参数）”，把“Show advanced menu properties（显示高级菜单属性）”里的项目全部勾选，我们就可以看到更多的参数。以本文题图为例，为各个项目分别加上 Home、Advertise、Contact、Archives 和 About 的 CSS Class，这样在前台调用菜单时，这些项目将拥有一个自定义的 CSS Class，接下来我们可以通过 CSS 为这些项目加上图标。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#header</span> ul<span style="color: #6666ff;">.navigation</span> li a<span style="color: #6666ff;">.home</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;images/home.png&quot;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">1px</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#header</span> ul<span style="color: #6666ff;">.navigation</span> li a<span style="color: #6666ff;">.about</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;images/about.png&quot;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">0px</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#header</span> ul<span style="color: #6666ff;">.navigation</span> li a<span style="color: #6666ff;">.advertise</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;images/advertise.png&quot;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">0px</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#header</span> ul<span style="color: #6666ff;">.navigation</span> li a<span style="color: #6666ff;">.archive</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;images/archive.png&quot;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #933;">1px</span> <span style="color: #933;">2px</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#header</span> ul<span style="color: #6666ff;">.navigation</span> li a<span style="color: #6666ff;">.contact</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;images/contact.png&quot;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">3px</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>在 WordPress 3.0 之前的版本里，我们可以通过 JavaScript 等方法为菜单项目加上图标。原理是获取菜单项的 title 值，再为它加上一个和 title 值相同的 Class，在 jQuery 里可以这样写：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<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;">'ul.navigation li a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</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: #000066; font-weight: bold;">return</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;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</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></pre></td></tr></table></div>

<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/improve-wordpress-navigation-menu-output/" title="为 WordPress 3.0 自定义菜单添加描述">为 WordPress 3.0 自定义菜单添加描述</a></li><li><a href="http://blog.imbolo.com/inpad/" title="主题发布：Inpad">主题发布：Inpad</a></li><li><a href="http://blog.imbolo.com/custom-gravatar/" title="自定义默认Gravatar头像">自定义默认Gravatar头像</a></li><li><a href="http://blog.imbolo.com/show-the-date-of-each-post/" title="显示每篇文章的日期">显示每篇文章的日期</a></li><li><a href="http://blog.imbolo.com/ajax-posting-comments/" title="为主题添加AJAX提交评论功能">为主题添加AJAX提交评论功能</a></li></ul><img src="http://feeds.feedburner.com/~r/bolo/~4/65ZnqwHCtIY" height="1" width="1"/>]]></content:encoded><description>WordPress 3.0 为了增强 CMS 功能，加入了自定义菜单的功能，除了定义菜单项目外，还可以菜单定义各个项目的 CSS Class。我们可以利用这个功能来为菜单项目添加一个个性图标。</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.imbolo.com/customizing-the-new-wordpress-3-0-custom-menus-adding-different-icons-to-each-link/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">15</slash:comments></item><item><title>WordPress 在 more 截断处插入广告</title><link>http://blog.imbolo.com/wordpress-insert-a-advertisement-at-the-more-tag/</link><category>WordPress</category><category>Advertisment</category><category>PHP</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">bolo</dc:creator><pubDate>Wed, 19 May 2010 22:01:48 PDT</pubDate><guid isPermaLink="false">http://blog.imbolo.com/?p=1847</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/0iRT-fxIB3nXW_0O6Tk3wGvR8zU/0/da"><img src="http://feedads.g.doubleclick.net/~a/0iRT-fxIB3nXW_0O6Tk3wGvR8zU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/0iRT-fxIB3nXW_0O6Tk3wGvR8zU/1/da"><img src="http://feedads.g.doubleclick.net/~a/0iRT-fxIB3nXW_0O6Tk3wGvR8zU/1/di" border="0" ismap="true"></img></a></p><p>在文章内插入的广告具有相当高的点击率。在 WordPress 里，我发现很多人利用 JavaScript 把广告插入到 more 截断标签处，作为内文广告。昨晚我也在内文里放了 Google Adsense，但我是用 WordPress 自带的 add_filter 函数实现的。</p>
<p>打开主题的 function.php ，插入下面的代码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * The filter to insert the ads
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> bl_insert_ad_code_filter<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$content</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// 只在文章页面显示</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// 首先插入广告代码</span>
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;div class=&quot;single_ads&quot;&gt;你的广告代码&lt;/div&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// more 标签在 WordPress 2.3 前是一个 a 标签，2.3 后是一个 span 标签</span>
		<span style="color: #666666; font-style: italic;">// 保证兼容性</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#\《(a|span) id＼=<span style="color: #000099; font-weight: bold;">\&quot;</span>more-<span style="color: #006699; font-weight: bold;">$id</span><span style="color: #000099; font-weight: bold;">\&quot;</span>\》\《/<span style="color: #000099; font-weight: bold;">\\</span>1\》#&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$html</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$0</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//因为 wp-syntax 插件的问题，请把上一句代码中的书名号替换成“&lt; ”和“&gt;”，“＼”换成“\”</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bl_insert_ad_code_filter'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>利用这个 filter 我们还可以在文章任意的地方插入广告，或者添加其他的应用，大家可以尽情发挥创意。<span id="more-1847"></span></p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/improve-wordpress-navigation-menu-output/" title="为 WordPress 3.0 自定义菜单添加描述">为 WordPress 3.0 自定义菜单添加描述</a></li><li><a href="http://blog.imbolo.com/customizing-the-new-wordpress-3-0-custom-menus-adding-different-icons-to-each-link/" title="为 WordPress 3.0 的自定义菜单链接添加栏目图标">为 WordPress 3.0 的自定义菜单链接添加栏目图标</a></li><li><a href="http://blog.imbolo.com/wordpress-advance-setting-tips/" title="WordPress 高级设置技巧">WordPress 高级设置技巧</a></li><li><a href="http://blog.imbolo.com/wordpress-plugin-ibegin-share-mod/" title="WordPress 分享插件：iBegin Share (mod)">WordPress 分享插件：iBegin Share (mod)</a></li><li><a href="http://blog.imbolo.com/php-get-image-from-remote-host/" title="PHP 获取远程图片">PHP 获取远程图片</a></li></ul><img src="http://feeds.feedburner.com/~r/bolo/~4/xjmP41gVyIU" height="1" width="1"/>]]></content:encoded><description>在文章内插入的广告具有相当高的点击率。在 WordPress 里，我发现很多人利用 JavaScript 把广告插入到 more 截断标签处，作为内文广告。昨晚我也在内文里放了 Google Adsense，但我是用 WordPress 自带的 add_filter 函数实现的。</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.imbolo.com/wordpress-insert-a-advertisement-at-the-more-tag/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">29</slash:comments></item><item><title>CSS 多个子框架居中</title><link>http://blog.imbolo.com/center-multiple-divs-with-css/</link><category>CSS</category><category>WEB</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">bolo</dc:creator><pubDate>Sat, 15 May 2010 06:29:44 PDT</pubDate><guid isPermaLink="false">http://blog.imbolo.com/?p=1844</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/ShhL3qOxf9Ax5011Co9uRtBXe1I/0/da"><img src="http://feedads.g.doubleclick.net/~a/ShhL3qOxf9Ax5011Co9uRtBXe1I/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ShhL3qOxf9Ax5011Co9uRtBXe1I/1/da"><img src="http://feedads.g.doubleclick.net/~a/ShhL3qOxf9Ax5011Co9uRtBXe1I/1/di" border="0" ismap="true"></img></a></p><p>有时我们需要令一个宽度固定的容器里的子框架居中（例如一个 Div ，或者其他 block 级元素），如果子框架只有一个的话，我们只需要为子框架加上 CSS 属性 margin: auto 就可以了。</p>
<p>但如果我们要让多个子框架居中，并且等分父框架剩余的空间的话，我们对所有子框架使用 CSS <strong>box-align: center</strong> 来实现这种效果。</p>
<p>可是目前还有相当一部分主流浏览器不支持 <strong>box-align 属性</strong>，那么我们应该如何编写 CSS，使这种效果能兼容大部分的浏览器呢？</p>
<h3>通常的方法</h3>
<p>为了使多个 block 级元素排列在同一行里，我们习惯使用 float 属性使子框架浮动，然后利用 margin 属性让每一个子框架之间都留出一些空白的间距。可是这样做会触发经典的 IE6 双倍 margin BUG，这样反而要投入额外的时间去调试 IE6 的 Hack。</p>
<p>虽然我们还可以通过 display: inline 来避开 IE6 的 BUG，但我们仍然需要调整这些子框架间的间距，防止最后一个自框架被挤到下一行。<span id="more-1844"></span></p>
<h3>改变子框架级别并且控制剩余的空白</h3>
<p>使用 float 和 margin 来让多个子框架居中并且等分父框架剩余空间的做法缺点很多。为了避开这些缺点，我们还可以使用另一种方法：把子框架的级别改为 inline-block ，并且通过 <strong>letter-spacing 属性</strong> 控制自框架之间的间距。</p>
<p>假设在一个父框架里有四个 block 级的子容器，每个子容器的大小均为 100px x 100px。为了让这些子框架能排列在同一行内，我们可以把它们改为 inline-block 级，由于子框架和父框架之间并没有其它的内容，应此要控制子框架的空间分配将易如反掌。姑且假设父框架 id=parent，子框架 class=child，那么 CSS 可以这样写：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#parent</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">615px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">solid</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#aaa</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</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;">20px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">letter-spacing</span><span style="color: #00AA00;">:</span> <span style="color: #933;">35px</span><span style="color: #00AA00;">;</span>
	whitewhite-space<span style="color: #00AA00;">:</span> <span style="color: #993333;">nowrap</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;">12px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.child</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">solid</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> inline-<span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">middle</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>在这段样式里，#parent 的 text-align、letter-spacing、white-space、overflow 和 .child 的 vertical-align、display 这些属性是实现预想效果的关键，下面解释一下这些属性起了什么作用。</p>
<ul>
<li><strong>text-align</strong>：使 #parent 里的所有内容都居中</li>
<li><strong>letter-spacing</strong>：控制每个子框架之间的空白大小</li>
<li><strong>white-space: nowrap</strong>：防止最后一个子框架被挤到下一行</li>
<li><strong>overflow: hidden</strong>：隐藏超出 #parent 范围的内容</li>
<li><strong>vertical-align: middle</strong>：使所有子框架都垂直居中</li>
<li><strong>display: inline-block</strong>：是所有子框架都排列在同一行，并且保持 block 级元素的特性</li>
</ul>
<h3>兼容 IE</h3>
<p>在今时今日，老版本的 IE 浏览器已经成为网页设计师的心头大恨，虽然上面的 CSS 能兼容 IE8，但由于 IE6 和 IE7 并不完全支持 inline-block 级元素，因此我们还需要写下面的一段 Hack，确保在 IE6 和 IE7 里能保持和现代浏览器一致的效果。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.child</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #00AA00;">*</span><span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">*</span><span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">20px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>本文所举例子的最终效果可以看这个 <a href="http://blog.imbolo.com/wp-content/uploads/2010/05/center-multiple-divs.html">DEMO</a>。</p>
<h3>后记</h3>
<p>本文所举的例子虽然只有短短的两句 IE Hack，但在实际开发中大家要写的 Hack 肯定要多很多，因此淘汰老版本 IE 的任务已经刻不容缓。我听过很多人说：“我不用 IE 浏览器的，我用傲游和世界之窗”，在这里我提醒一下大家，对这些无法解释清楚的人，我们可以简单地和他们说：“凡是能用支付宝的浏览器都是落后的，请放弃使用。”。</p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/css-turn-off-webkit-browsers-input-highlight-and-textarea-resize/" title="CSS 屏蔽 Webkit 浏览器 input 高亮和 textarea 缩放">CSS 屏蔽 Webkit 浏览器 input 高亮和 textarea 缩放</a></li><li><a href="http://blog.imbolo.com/the-css3-flexible-box-model/" title="CSS3 灵活的盒子模型(Flexible Box Module) &#8211; 1">CSS3 灵活的盒子模型(Flexible Box Module) &#8211; 1</a></li><li><a href="http://blog.imbolo.com/web-rounded-conner-choice/" title="网页圆角的取舍">网页圆角的取舍</a></li><li><a href="http://blog.imbolo.com/10-css-snippets-to-save-time/" title="10个节约开发时间的CSS技巧">10个节约开发时间的CSS技巧</a></li><li><a href="http://blog.imbolo.com/css-beveled-corners/" title="纯CSS打造斜角">纯CSS打造斜角</a></li></ul><img src="http://feeds.feedburner.com/~r/bolo/~4/nxyMikw3YQs" height="1" width="1"/>]]></content:encoded><description>有时我们需要令一个宽度固定的容器里的子框架居中（例如一个 Div ，或者其他 block 级元素），如果子框架只有一个的话，我们只需要为子框架加上 CSS 属性 margin: auto 就可以了。</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.imbolo.com/center-multiple-divs-with-css/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">9</slash:comments></item><item><title>CSS3 灵活的盒子模型(Flexible Box Module) – 2</title><link>http://blog.imbolo.com/the-css3-flexible-box-model-2/</link><category>CSS</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">bolo</dc:creator><pubDate>Sun, 09 May 2010 01:55:06 PDT</pubDate><guid isPermaLink="false">http://blog.imbolo.com/?p=1838</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/7Fl7TFRBvRe0sB1NpZuIhDEsY_8/0/da"><img src="http://feedads.g.doubleclick.net/~a/7Fl7TFRBvRe0sB1NpZuIhDEsY_8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/7Fl7TFRBvRe0sB1NpZuIhDEsY_8/1/da"><img src="http://feedads.g.doubleclick.net/~a/7Fl7TFRBvRe0sB1NpZuIhDEsY_8/1/di" border="0" ismap="true"></img></a></p><p>继上一篇《<a href="http://blog.imbolo.com/the-css3-flexible-box-model/">CSS3 灵活的盒子模型(Flexible Box Module) – 1</a>》后继续深入，说说 CSS3 里盒子模型的尺寸。本文的 HTML 框架继续沿用《<a href="http://blog.imbolo.com/the-css3-flexible-box-model/">CSS3 灵活的盒子模型(Flexible Box Module) – 1</a>》。</p>
<p>在 CSS2 里，要把一个容器分成三栏的话比较简便的方法是把三个字容器的 width 都设为 33.3%，这种方法无法把父容器的宽度完全填充，在父容器的宽度足够大的时候留下的空白会是页面变得很不美观。令一种方法是通过计算把子容器的 width 都设为一个固定值，这种方法比较繁琐，而且在一些情况下无法使子容器的宽度完全相等（例如父容器的宽度为 100px）。当我们迈入 CSS3 时代后，这种问题将迎刃而解。</p>
<h3>box-flex 属性</h3>
<p>box-flex 应用在需要分栏的子容器上，它的值必须是一个自然数或小数。当父容器里有多个带有 box-flex 属性的子容器时，浏览器将会把这些子容器的 box-flex 的值相加，然后根据它们各自的值占总值的比例，再在父容器剩余的空间里分配它们的尺寸（说的啰嗦，其实一看 DEMO 就懂）。也就是说，我们需要注意 <strong>box-flex 属性必须在父框架具有具体的 width 或者 height 的时候才能正常渲染</strong>。<span id="more-1838"></span></p>
<h4>灵活的尺寸</h4>
<p>在这个例子里，我将使子容器2和3的宽度相等，并且子容器1的宽度为它们的两倍。由于使用了 box-flex 属性，如果再插入一个子容器的话，已有的容器宽度将会自动调整。CSS 如下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#exemple4</span> .<span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">&#123;</span>
	-moz-box-orient <span style="color: #00AA00;">:</span> horizontal<span style="color: #00AA00;">;</span>
	-webkit-box-orient <span style="color: #00AA00;">:</span> horizontal<span style="color: #00AA00;">;</span>
	box-orient <span style="color: #00AA00;">:</span> horizontal<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#exemple4</span> .v1<span style="color: #00AA00;">&#123;</span>
	-moz-box-flex<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span>
	-webkit-box-flex<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span>
	box-flex<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#exemple4</span> .v2<span style="color: #00AA00;">&#123;</span>
	-moz-box-flex<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
	-webkit-box-flex<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
	box-flex<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#exemple4</span> .v3<span style="color: #00AA00;">&#123;</span>
	-moz-box-flex<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
	-webkit-box-flex<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
	box-flex<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>效果可以看这个 <a href='http://blog.imbolo.com/wp-content/uploads/2010/05/exemple-css3-box-2.html#exemple4'>DEMO</a>。大家也可以下载这个 DEMO，尝试添加一个新的子容器，它是不是自动适应了。</p>
<h4>自适应子容器和固定尺寸子容器的混合使用</h4>
<p>box-flex 的另一个强大之处是可以和具有固定尺寸的容器混合使用。我把上面的例子改一改，子容器3改成固定宽度160px，其它的保持不变，看看有什么效果。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#exemple5</span> .<span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">&#123;</span>
	-moz-box-orient<span style="color: #00AA00;">:</span> horizontal<span style="color: #00AA00;">;</span>
	-webkit-box-orient<span style="color: #00AA00;">:</span> horizontal<span style="color: #00AA00;">;</span>
	box-orient<span style="color: #00AA00;">:</span> horizontal<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#exemple5</span> .v1<span style="color: #00AA00;">&#123;</span>
	-moz-box-flex<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span>
	-webkit-box-flex<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span>
	box-flex<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#exemple5</span> .v2<span style="color: #00AA00;">&#123;</span>
	-moz-box-flex<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
	-webkit-box-flex<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
	box-flex<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#exemple5</span> .v3<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">160px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>大家可以看这个 <a href='http://blog.imbolo.com/wp-content/uploads/2010/05/exemple-css3-box-2.html#exemple5'>DEMO</a> 的效果。我们可以发现，子容器1和子容器2的宽度是在父容器宽度减去子容器3的宽度以后剩下的空间里分配的，这点和使用百分比作为 width 时直接根据父容器的宽度进行计算有很大的不同，<strong>使用 box-flex 能使子容器自动适应尺寸的变化</strong>，节省了很多调试时间。</p>
<h3>空间的分配</h3>
<p>因为我们可以把具有固定尺寸和灵活尺寸的子容器混合使用，并且也可以给父容器赋予灵活的尺寸。因此在最终的成品里我们可能会遇到父容器空间过余或者不足的情况。为了更合理地利用父容器提供的空间，box-align 和 box-pack 属性可以帮助我们。</p>
<h4>box-pack 属性</h4>
<p>box-pack 属性可以用于设置子容器在水平轴上的空间分配方式，它共有四种可能值：start，end，justify 和 center。这些值的含义如下：</p>
<ul>
<li>start ：所有子容器都分布在父容器的左侧，右侧留空</li>
<li>end ：所有子容器都分布在父容器的右侧，左侧留空</li>
<li>justify ：所有子容器平均分布（默认值）</li>
<li>center ：平均分配父容器剩余的空间（能压缩子容器的大小，并且有全局居中的效果）</li>
</ul>
<h4>box-align 属性</h4>
<p>box-align 属性用于管理子容器在竖轴上的空间分配方式，共有五个值：start，end，center，baseline 和 stretch。</p>
<ul>
<li>start ：子容器从父容器顶部开始排列</li>
<li>end ：子容器从父容器底部开始排列</li>
<li>center ：子容器横向居中（有点奇怪）</li>
<li>baseline ：所有子容器沿同一基线排列（很难理解）</li>
<li>stretch ：所有子容器和父容器保持同一高度（默认值）</li>
</ul>
<p>box-align 和 box-pack 属性通常混合使用，我们可以用下面的 CSS 测试一下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#exemple6</span> .<span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">&#123;</span>
	-moz-box-orient<span style="color: #00AA00;">:</span> horizontal<span style="color: #00AA00;">;</span>
	-moz-box-pack<span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	-moz-box-align<span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
&nbsp;
	-webkit-box-orient<span style="color: #00AA00;">:</span> horizontal<span style="color: #00AA00;">;</span>
	-webkit-box-pack<span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	-webkit-box-align<span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
&nbsp;
	box-orient<span style="color: #00AA00;">:</span> horizontal<span style="color: #00AA00;">;</span>
	box-pack<span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	box-align<span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>在线的 <a href='http://blog.imbolo.com/wp-content/uploads/2010/05/exemple-css3-box-2.html#exemple6'>DEMO</a>，大家可以 Firebug 禁用 box-align 和 box-pack 属性看看它们的区别和效果。</p>
<h4>防止子容器溢出</h4>
<p>CSS3 并没有更好地解决内容溢出的问题，反而在加入和新的盒子模型参数后，溢出的情况变得更加频繁。因此最好的方法还是多做试验，更好地管理你的内容。overflow: hidden 正能临时起点作用而已。</p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/css-turn-off-webkit-browsers-input-highlight-and-textarea-resize/" title="CSS 屏蔽 Webkit 浏览器 input 高亮和 textarea 缩放">CSS 屏蔽 Webkit 浏览器 input 高亮和 textarea 缩放</a></li><li><a href="http://blog.imbolo.com/jquery-selectors/" title="jQuery选择器详解（一）">jQuery选择器详解（一）</a></li><li><a href="http://blog.imbolo.com/customizing-the-new-wordpress-3-0-custom-menus-adding-different-icons-to-each-link/" title="为 WordPress 3.0 的自定义菜单链接添加栏目图标">为 WordPress 3.0 的自定义菜单链接添加栏目图标</a></li><li><a href="http://blog.imbolo.com/center-multiple-divs-with-css/" title="CSS 多个子框架居中">CSS 多个子框架居中</a></li><li><a href="http://blog.imbolo.com/the-css3-flexible-box-model/" title="CSS3 灵活的盒子模型(Flexible Box Module) &#8211; 1">CSS3 灵活的盒子模型(Flexible Box Module) &#8211; 1</a></li></ul><img src="http://feeds.feedburner.com/~r/bolo/~4/5W9nQgSH7ew" height="1" width="1"/>]]></content:encoded><description>继上一篇《CSS3 灵活的盒子模型(Flexible Box Module) – 1》后继续深入，说说 CSS3 里盒子模型的尺寸。</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.imbolo.com/the-css3-flexible-box-model-2/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">7</slash:comments></item></channel></rss>
