2012-09-04 34 views
2

我需要创建类似的列表:http://jsfiddle.net/BkBZJ/HTML:列表,子列表和伪构件

只,而无需在HTML(名单内的类或嵌套列表span标签)的额外的标记。
有谁知道的一种方式,我可以做到这一点,说有一个伪元素,如前/后,最后一个孩子,第n个孩子等等

,或者这是不可能没有的附加标记HTML。

+0

':: before'和':: after'是伪元素,而':最后child'和':第n个孩子()'是伪类。他们是两个不同的东西;不要混淆。 – BoltClock

回答

1

嗯,你总是可以使用:第n个孩子(x),其中x是一个你想要修改,然后对其应用余量以及颜色:对其进行更改。

例如:http://jsfiddle.net/PcA4u/

+0

这不会为我在挪亚后的工作,但无论如何谢谢你。 – user1752759

+0

我误解了如何正确使用此建议...使用提供这个答案并改变它一点点是对HTML更最小的,我可以做到这一点: http://jsfiddle.net/JZF5v/ 谢谢诺亚 – user1752759

1

根本就the following (JSFiddle)

CSS

body { 
    background: #202024; 
    color: #FFF; 
    font: .75em Arial, san-serif; 
} 

h1 { 
    font: 1.25em Arial, san-serif; 
    text-transform: uppercase; 
} 

#education dt { margin-top: 15px;} 
#education dd { 
    text-indent: 25px; 
    color:#C5B7A6; 
} 
/* Add the dashes where appropriate */ 
#education dd:before { 
    content: "- "; 
    display: inline-block; 
} 
/* Override the styles for specific dds */ 
#education .co {color:#FFF; margin-left:50px;} 

/* Or, alternately if all except the first dd should be white */ 
#education dd:first-child { color: #C5B7A6; margin-left: 0; } 
#education dd { color: #FFF; margin-left: 50px; } 

HTML

<div id="education"> 
<h1>Education</h1> 
<dl> 
    <dt>Holmsglen Institute of TAFE</dt> 
     <dd>Certificate II &amp; Certificate III of Multimedia</dd> 
    <dt>RMIT University</dt> 
     <dd>Advanced Diploma Of Interactive Media</dd> 
    <dd>2D Animation Major</dd> 
    <dt>Swinburne University</dt> 
     <dd>Bachelors Degree of Digital Media</dd> 
     <dd class="co">Branding &amp; Advertising Co-Minor</dd> 
     <dd class="co">Motion Graphics Co-Minor</dd> 
</dl> 
</div>​ 
+0

感谢您的快速反应sean,我希望避免添加更多的类并寻找围绕此的伪方法。这可能不得不作为最后的手段。 – user1752759

+1

@Rob - 看看我编辑的方法,不需要在后面的'dd'元素上使用类。 (只需使用':first-child'来改变第一个'dd'的显示方式)。 –

+0

迄今为止我能得到的最好的是http://jsfiddle.net/BkBZJ/5/。即时通讯不能确切地确定如何使用您的方法来针对第二个dd:第一个孩子。 – user1752759