编辑“WordPress:Styling Lists with CSS

跳转至: 导航、​ 搜索
警告:您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您登录创建一个账户,您的编辑将归属于您的用户名,且将享受其他好处。

该编辑可以被撤销。 请检查下面的对比以核实您想要撤销的内容,然后发布下面的更改以完成撤销。

最后版本 您的文本
第69行: 第69行:
#pagenav ul li {attributes}</pre>
#pagenav ul li {attributes}</pre>


;ul :The first style (<tt>#sidebar ul</tt>) sets the look for the overall list.  It usually contains the margins and padding styles and may contain the font-family, color, and other details for the overall list.
;li :The <tt>#sidebar li</tt> assigns a style to the actual list item.  Here you can set the format to include a bullet or not. You can also change the font, font-size, or color, and you can even add borders.
;ul li :The <tt>#sidebar ul li</tt> determines the style of the first nested list.  Each first level nested list will be customized here, but you can style each of these sub-lists differently if they are contained within a specific [[WordPress:Glossary#CSS|CSS]] ID.  In the above example, after the <tt>#search</tt> section, the first nested list is <tt>#pagenav</tt>.  If you use [[WordPress:Pages]] this is where the list of [[WordPress:Pages]] would be generated.  Since [[WordPress:Pages]] work outside of [[WordPress:The Loop|The WordPress Loop]], and often highlight specific information like "About Us", "Contact", and "Site Map", you may want to design the [[WordPress:Pages]] style differently than the rest of your lists by putting the specific information about the look of the [[WordPress:Pages]] in the <tt>#pagenav</tt>.
;ul ul li :The <tt>#sidebar ul ul li</tt> applies style to the links within the <tt>#sidebar ul ul</tt> to help customize the look of this list.  Again, if you have customized the <tt>#pagenav</tt> list, it will be different from the rest of your nested list items.
;ul ul ul li :The <tt>#sidebar ul ul ul li</tt> is the style for the sub-sub-list.  If you have a list of [[WordPress:Glossary#Category|categories]] with subcategories, the [[WordPress:Glossary#Category|category]] title will be the first level of the list, the categories would be the second level of the list, and any subcategories would be the third level, or sub-sub-list, such as the example below.  Some designers like having the third level list feature a smaller font, a different bullet, or even a different color to highlight them from the list items above them:
:*Category Title
:**Category One
:**Category Two
:***Sub-Category One
:***Sub-Category Two
:**Category Three


;ul :第一个样式(<tt>#sidebar ul</tt>)设置整体列表的外观. 通常包含整个列表的页边空白和填充样式,也可能包含字体库,颜色和别的内容。
;ul :第一个样式(<tt>#sidebar ul</tt>)设置整体列表的外观. 通常包含整个列表的页边空白和填充样式,也可能包含字体库,颜色和别的内容。
;li : <tt>#sidebar li</tt> 分配样式给现有的列表项目.  这里你可以设置是否包含bullet 符号,你也可以改变字体,字号,或者颜色,你还可以加入边线.
;li : <tt>#sidebar li</tt> 分配样式给现有的列表项目.  这里你可以设置是否包含bullet 符号,你也可以改变字体,自号,或者颜色,你还可以加入边线.
;ul li :<tt>#sidebar ul li</tt>确定第一个嵌套类表的样式. 每个第一级嵌套列表都在这里制定,但是如果它们有详细的[[WordPress:Glossary#CSS|CSS]]ID的话,你可以设计每个嵌套的子列表。上述例子中,<tt>#search</tt> 部分之后, 第一级嵌套列表是<tt>#pagenav</tt>. 如果你使用[[WordPress:Pages|页面]],这里是[[WordPress:Pages|页面]]的列表生成的地方。因为 [[WordPress:Pages|页面]]工作在[[WordPress:The Loop|WordPress循环]]之外, 并且通常高亮显示特殊的信息比如"About Us", "Contact", and "Site Map", 你可能想通过把关于[[WordPress:Pages|页面]]外观特殊信息输入<tt>#pagenav</tt>来设计[[WordPress:Pages|页面]],使它的样式与列表的其他部分不同.
;ul li :<tt>#sidebar ul li</tt>确定第一个嵌套类表的样式. 每个第一级嵌套列表都在这里制定,但是如果它们有详细的[[WordPress:Glossary#CSS|CSS]]ID的话,你可以设计每个嵌套的子列表。上述例子中,<tt>#search</tt> 部分之后, 第一级嵌套列表是<tt>#pagenav</tt>. 如果你使用[[WordPress:Pages|页面]],这里是[[WordPress:Pages|页面]]的列表生成的地方。因为 [[WordPress:Pages|页面]]工作在[[WordPress:The Loop|WordPress循环]]之外, 并且通常高亮显示特殊的信息比如"About Us", "Contact", and "Site Map", 你可能想通过把关于[[WordPress:Pages]]外观特殊信息输入<tt>#pagenav</tt>来设计[[WordPress:Pages|页面]],使它的样式与列表的其他部分不同.
;ul ul li : <tt>#sidebar ul ul li</tt>在<tt>#sidebar ul ul</tt>中提供了连接的样式 以帮助定义列表的外观。另外,如果你已经定义了<tt>#pagenav</tt>列表,将会和你剩下的的嵌套列表不同。
;ul ul li : <tt>#sidebar ul ul li</tt>在<tt>#sidebar ul ul</tt>中提供了连接的样式 以帮助定义列表的外观。另外,如果你已经定义了<tt>#pagenav</tt>列表,将会和你剩下的的嵌套列表不同。
;ul ul ul li : <tt>#sidebar ul ul ul li</tt>是二级子表的样式。如果你有一个带有子类的[[WordPress:Glossary#Category|分类]]列表,[[WordPress:Glossary#Category|分类]] 标题将是列表的第一级,分类是第二级,而任何子类将是第三级,或者是子表,如下面的例子。一些设计者喜欢在第三级使用一些较小的字体,不同的符号,或者不同的颜色,高亮显示,以区别它们上一层的项目:
;ul ul ul li : <tt>#sidebar ul ul ul li</tt>是二级子表的样式。如果你有一个带有子类的[[WordPress:Glossary#Category|分类]]列表,[[WordPress:Glossary#Category|分类]] 标题将是列表的第一级,分类是第二级,而任何子类将是第三级,或者是子表,如下面的例子。一些设计者喜欢在第三级使用一些较小的字体,不同的符号,或者不同的颜色,高亮显示,以区别它们上一层的项目:
第84行: 第96行:




== Styling Specific List Items ==


Do you want your [[WordPress:Glossary#Category|Categories List]] to look different from your Archives List?  Then open up the <tt>index.php</tt> or <tt>sidebar.php</tt> and carefully add the following style references to the appropriate list item:
<div style="border:1px dashed blue; width:50%; margin: 20px; padding:20px"><tt>&lt;li '''id="categories"'''>&lt;h2>Categories&lt;/h2>.....</tt><br /><br />
<tt>&lt;li '''id="archives"'''>&lt;h2>Archives&lt;/h2>....</tt></div>


== 设计特定列表项目 ==
== 设计特定列表项目 ==
第93行: 第110行:
<tt>&lt;li '''id="archives"'''>&lt;h2>Archives&lt;/h2>....</tt></div>
<tt>&lt;li '''id="archives"'''>&lt;h2>Archives&lt;/h2>....</tt></div>


To customize the Categories and Archives list, add the following to your stylesheet to customize these individually:
<pre>#categories {attributes}
#categories ul {attributes}
#categories ul li {attributes}
#archives {attributes}
#archives ul {attributes}
#archives ul li {attributes}</pre>
Go through any other sections of your list and give them a style reference name and add them to your style sheet.  When you've identified which part of the list controls which aspect of the list, it's time to start changing the look of the list.


要想自定义分类和文档列表,把下列代码加入样式表来单独定义:
要想自定义分类和文档列表,把下列代码加入样式表来单独定义:
第105行: 第132行:
检查列表的其它部分,给它们一个样式参数名,把它们加入到你的样式表。当你能识别出列表的哪一部分控制列表的哪一方面时,就是改变列表外观的时候了。
检查列表的其它部分,给它们一个样式参数名,把它们加入到你的样式表。当你能识别出列表的哪一部分控制列表的哪一方面时,就是改变列表外观的时候了。


=== 设计个人条目===
=== Styling individual items ===
 
If you want to use image replacement techniques to style your list, each <tt>LI</tt> tag will need its own class or ID.  Try the [http://wordpress.org/extend/plugins/classy-wp-list-pages/ Classy wp_list_pages] plugin.
 
=== 设计个别项目 ===


如果你想使用图片替换技巧设计你的列表,那么每个<tt>LI</tt>标签需要它自己的类别或者ID,你可以试试[http://wordpress.org/extend/plugins/classy-wp-list-pages/ Classy wp_list_pages]插件。
如果你想使用图片替换技巧设计你的列表,那么每个<tt>LI</tt>标签需要它自己的类别或者ID,你可以试试[http://wordpress.org/extend/plugins/classy-wp-list-pages/ Classy wp_list_pages]插件。


== Styling Your Lists ==
An important part of a list is the bullet - an eye catching dot, spot, or graphic that tells viewers "this is a list". The style of bullet or numbering for a list is determined by a '''list-style-type property''' in the style sheet. The default value is <tt>disc</tt>. Other basic values are <tt>circle</tt>, <tt>square</tt>, <tt>decimal</tt>, <tt>decimal-leading-zero</tt>, <tt>lower-roman</tt>, <tt>upper-roman</tt>, and <tt>none</tt>.  Let's change the default value to something else, like a square.
<pre>#sidebar li {
  list-style: square;
}</pre>


== 设计列表 ==
== 设计列表 ==
第117行: 第155行:
   list-style: square;
   list-style: square;
}</pre>
}</pre>
Instead of typing <tt>list-style-type</tt>, you see a shorthand form of <tt>list-style</tt>, and instead of using the default <tt>disc</tt>, the list now features small squares.


不用输入<tt>list-style-type</tt>,你可以使用速记形式<tt>list-style</tt>,而且代替了默认的<tt>disc</tt>,列表现在使用的是小方块了。
不用输入<tt>list-style-type</tt>,你可以使用速记形式<tt>list-style</tt>,而且代替了默认的<tt>disc</tt>,列表现在使用的是小方块了。


But not all lists need bullets.  By their overall layout, you just ''know'' a list is a list.  To eliminate the bullet, change the stylesheet to this:
<pre>#sidebar li {
  list-style: none;
}</pre>
Now, anything tagged with <nowiki><li></nowiki>, within the DIV of the ID of <tt>#sidebar</tt>, would have no bullet.  Experiment with different values to see the results you can achieve.
'''HINT:''' In terms of accessibility, an ordered list is easier to navigate than an unordered list.


但是不是所有的列表都需要这种着重号,通过他们的整体规划,你只需要''知道''列表是一个列表就够了。要消除着重号,只需要把样式表修改成这样:
但是不是所有的列表都需要这种着重号,通过他们的整体规划,你只需要''知道''列表是一个列表就够了。要消除着重号,只需要把样式表修改成这样:
第127行: 第176行:
}</pre>
}</pre>


现在,任何带有<nowiki><li></nowiki>的标签,<tt>#sidebar</tt>内的ID的DIV标签内,都不会在有着重号了。你可以尝试其他不同的值来看看你可能得到什么样的结果。
现在,任何带有<nowiki><li></nowiki>的标签,<tt>#sidebar</tt>内的ID的DIV标签内,都不会在有bullet符号了。你可以尝试其他不同的值来看看你可能得到什么样的结果。


'''提示:'''根据易用性,整齐的列表要比不整齐的列表更容易浏览。
'''提示:'''根据易用性,整齐的列表要比不整齐的列表更容易浏览。
=== Using a Custom Image Instead of a Bullet ===
Tired of boring bullets? Let's get rid of the boring with a few [[WordPress:Glossary#CSS|CSS]] techniques. In this case, use '''list-style-image''' to instruct the browser to use your bullet image instead of the old boring default bullets.


=== 使用图片代替着重号===
=== 使用图片代替着重号===
第135行: 第188行:
厌倦了乏味的着重号吗?让我们用几个[[WordPress:Glossary#CSS|CSS]]技巧来处理这乏味的东西。在这里,使用'''list-style-image'''来指示浏览器使用你的图片代替乏味的默认着重号。
厌倦了乏味的着重号吗?让我们用几个[[WordPress:Glossary#CSS|CSS]]技巧来处理这乏味的东西。在这里,使用'''list-style-image'''来指示浏览器使用你的图片代替乏味的默认着重号。


找一些有趣的着重图片然后把下面的代码加入你的样式表,来加入一些好看的着重号到你的列表中:
Find some interesting bullet graphics and add the following code in your style sheet to add some jazzy bullets to your lists:
 
<pre>#sidebar ul {
list-style-image: url(/wp-images/image.gif);
}</pre>
 
Note that you could also use an absolute link rather than a relative link. Simply change the <tt>url(/wp-images/image.gif )</tt> to <tt><nowiki>url(http://example.com/wp-images/image.gif)</nowiki></tt>.
 
找一些有趣的着重图片然后把下面的代码加入你的样式表,来加入一写好看的着重号到你的列表中:


<pre>#sidebar ul {
<pre>#sidebar ul {
第149行: 第210行:
<pre>#sidebar ul ul {...; border-top: solid 1px blue; ....}</pre>
<pre>#sidebar ul ul {...; border-top: solid 1px blue; ....}</pre>


===给你的列表添加边框===
===跟你的列表添加边框===


想添加边框,如标题之后的下划线,你可以简单的加入一个边框样式到<tt>ul</tt>的顶部,标题下边,而不是在标题本身上添加。
想添加边框,如标题之后的下划线,你可以简单的加入一个边框样式到<tt>ul</tt>的顶部,标题下边,而不是在标题本身上添加。
第174行: 第235行:
     background:#CCFFFF; ....}</pre>
     background:#CCFFFF; ....}</pre>


And your end result would look like this:
<div style="padding: 10px"><span style="font-size:115%; font-style: italic; font-weight:bold; color: navy">Category Title</span>
<div style="width:30%; border: solid 1px blue; background:#CCFFFF; color: blue; padding: 5px">Category One
Category Two
Category Three</div></div>


你的最终结果可能显示如下:
你的最终结果可能显示如下:
第179行: 第246行:
<div style="padding: 10px"><span style="font-size:115%; font-style: italic; font-weight:bold; color: navy">Category Title</span>
<div style="padding: 10px"><span style="font-size:115%; font-style: italic; font-weight:bold; color: navy">Category Title</span>
<div style="width:30%; border: solid 1px blue; background:#CCFFFF; color: blue; padding: 5px">Category One
<div style="width:30%; border: solid 1px blue; background:#CCFFFF; color: blue; padding: 5px">Category One
Category Two
Category Three</div></div>
Or really expand the possiblities to something like this:
<div style="width: 30%; border-top: 20px solid #CC6600; border-left: 30px solid #CC6600"><span style="font-size:130%; font-style: italic; font-weight:bold; color: #660000">Category Title</span>
<div style="border-top: solid 5px black; border-left: solid 10px black; background:#FFFF00; color: navy; padding: 5px; font-size: 105%; font-weight: bold">Category One
Category Two
Category Two
Category Three</div></div>
Category Three</div></div>
第188行: 第262行:
Category Two
Category Two
Category Three</div></div>
Category Three</div></div>
You can have a lot of fun with your list bullets and list layouts.  If you are having trouble with your bullets and lists, check out the resources listed below and then visit the [http://wordpress.org/support/ WordPress support forums] to get more help.


你可以从列表设计和着重号上找到很多乐趣。如果你有困难,查看下面列出的资源然后访问[http://wordpress.org/support/ WordPress 支持论坛]获得帮助。
你可以从列表设计和着重号上找到很多乐趣。如果你有困难,查看下面列出的资源然后访问[http://wordpress.org/support/ WordPress 支持论坛]获得帮助。
==Troubleshooting Nested Lists==
If you are having trouble with your nested lists, the following might provide the solution. Also check [[WordPress:CSS Troubleshooting]] for more styling help issues.


==发现并解决嵌套列表问题==
==发现并解决嵌套列表问题==
第195行: 第275行:
如果你对你的嵌套列表有疑问,下面的内容可能提供了一些解决方法。同样查看[[WordPress:CSS Troubleshooting|CSS问题解决]]以获得更多有关样式的帮助。
如果你对你的嵌套列表有疑问,下面的内容可能提供了一些解决方法。同样查看[[WordPress:CSS Troubleshooting|CSS问题解决]]以获得更多有关样式的帮助。


===Improper Tag Structure===
The number one cause for errors or non-validation within a nested list is the lack of proper list structure. Here is a very simplified and correct nested list layout.  Note that when a new list begins (nested), the <tt>&lt;/li></tt> at the end of the last list item '''is not closed'''.  It is left open until the new nested list is completed, and then closed.


===不合适的标签结构===
===不合适的标签结构===
第214行: 第297行:
     <li>Category Three</li>
     <li>Category Three</li>
</ul>      &lt;----Note: End of entire list</pre>
</ul>      &lt;----Note: End of entire list</pre>
===Template Tag Lists===
Different [[WordPress:Template Tags]] used within lists have different ways of using and relying upon list tags.  Some tags automatically include the <tt>UL</tt> and <tt>LI</tt> so all you have to do is include the tag in the list by itself and it will do all the work.  Other tags require the <tt>UL</tt> to be in place followed by the template tag and it generates its own <tt>LI</tt> tags.  Other template tags require designating which type of list tags are needed or use none at all if not listed in the tag's parameters.


===模板标签列表===
===模板标签列表===


列表中使用的不同的[[WordPress:Template Tags|模板标签]]有不同的使用方法并且依赖于列表标签。一些标签自动包含<tt>UL</tt> 和 <tt>LI</tt>,这样你所需要做的就是把标签放进列表,它就会做好一切工作。一些标签需要通过模板标签把<tt>UL</tt>放在合适的,然后它会生成它自己的标签。一些标签要求指明,如果没有在标签参数中列出的话,哪种列表标签形式是需要的或者完全不需要的,
列表中使用的不同的[[WordPress:Template Tags|模板标签]]有不同的使用方法并且依赖于列表标签。一些标签自动包含<tt>UL</tt> 和 <tt>LI</tt>,这样你所需要做的就是把标签放进列表,它就会做好一切工作。一些标签需要通过模板标签把<tt>UL</tt>放在合适的,然后它会生成它自己的标签。一些标签要求指明,如果没有在标签参数中列出的话,哪种列表标签形式是需要的或者完全不需要的,
If you are having trouble with your nested lists when using template tags like [[WordPress:Template Tags/wp_list_cats|wp_list_cats]] or [[WordPress:Template Tags/wp_list_pages|wp_list_pages]], check their paramaters to see how they use the list tags and compare it with your usage.


如果你在使用模板标签时,如[[WordPress:Template Tags/wp_list_cats|wp_list_cats]] or [[WordPress:Template Tags/wp_list_pages|wp_list_pages]],对你的嵌套列表产生了什么问题,查阅它们的参数,看看它们如何使用列表标签,与你的使用方法做做比较。
如果你在使用模板标签时,如[[WordPress:Template Tags/wp_list_cats|wp_list_cats]] or [[WordPress:Template Tags/wp_list_pages|wp_list_pages]],对你的嵌套列表产生了什么问题,查阅它们的参数,看看它们如何使用列表标签,与你的使用方法做做比较。
第228行: 第317行:


在 [[WordPress:CSS_Troubleshooting#The_CSS_Parent_and_Child_Relationship| CSS 父和子的关系]]中讨论过的,列表是很多故障出现的原因之一。子列表项的样式受它的"父"列表的影响。如果父级的列表样式使用了"红色",而你想让子列表使用"兰色",那么你需要在子列表样式中进行设置,这样它们才会不受父列表的影响。
在 [[WordPress:CSS_Troubleshooting#The_CSS_Parent_and_Child_Relationship| CSS 父和子的关系]]中讨论过的,列表是很多故障出现的原因之一。子列表项的样式受它的"父"列表的影响。如果父级的列表样式使用了"红色",而你想让子列表使用"兰色",那么你需要在子列表样式中进行设置,这样它们才会不受父列表的影响。
Nested lists within the WordPress Sidebar typically contain links.  Therefore, while you can style the list as much as you want, the style for links will override the list style.  You can control the way the links in the list work by giving them a specific style class of their own, including their hover attributes:
<pre>#sidebar a {attributes}
#sidebar a:hover {attributes}
#categories a {attributes}
#categories a:hover {attributes}
#archives a {attributes}
#archives a:hover {attributes}</pre>


WordPress边栏中的嵌套列表通常包括连接。这样,当你设计你想要的列表时,连接的样式将不受列表样式影响。你可以通过给出一个特定的样式,来控制列表中的连接的样式,包括它们的属性:
WordPress边栏中的嵌套列表通常包括连接。这样,当你设计你想要的列表时,连接的样式将不受列表样式影响。你可以通过给出一个特定的样式,来控制列表中的连接的样式,包括它们的属性:
第237行: 第335行:
#archives a {attributes}
#archives a {attributes}
#archives a:hover {attributes}</pre>
#archives a:hover {attributes}</pre>
== Resources ==
* [[WordPress:Creating Horizontal Menus]]
* [[WordPress:Dynamic Menu Highlighting]]
* [[WordPress:Customizing Your Sidebar]]
* [[WordPress:Site Architecture 1.5]]
* [[WordPress:Stepping Into Template Tags]]
* [http://www.alistapart.com/articles/taminglists/ Taming Lists]
* [http://css.maxdesign.com.au/listamatic/ Listamatic]
* [http://www.yourhtmlsource.com/stylesheets/csstext.html CSS Text Formatting]
* [http://www.w3.org/TR/REC-CSS2/generate.html W3.org's CSS-2 - Generated Content, Automatic Numbering, and Lists]
* [http://www.davesite.com/webstation/css/chap07.shtml Cascading Style Sheets Interactive Tutorial for Beginners: Lists]
* [http://www.maxdesign.com.au/presentation/definition/index.cfm Max Design's Definition lists - Misused or Misunderstood?]
* [http://www.cameraontheroad.com/?p=160 CSS Unleashed - Experiments with Lists, Menus, Tables of Content, and More]
* [http://www.simplebits.com/notebook/2003/10/19/styling_nested_lists.html Simplebits' Style Nested Lists]


== 资源 ==
== 资源 ==
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅Wordpress-mediawiki:版权的细节)。 未经许可,请勿提交受版权保护的作品!
取消 编辑帮助(在新窗口中打开)