DOM hierarchy pseudo-classes allow you to style specific elements based on where they fall in the hierarchy and what type of elements they are. You can also use :nth-child to target custom element patterns, like every other element.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
<link rel="stylesheet" href="styles.css">
<style>
ul {
list-style: none;
margin: 0;
padding: 0;
} li {
padding: 5px;
} /* li:first-child {
background-color: rgb(225, 231, 252);
}
li:last-child {
background-color: rgb(225, 231, 252);
}
li:nth-child(2) {
background-color: rgb(225, 0, 252);
}*/
/* The even child*/
/*li:nth-child(2n) {
background-color: gold ;
}*/ /* The odd child*/
/*li:nth-child(2n+1) {
background-color: darkred;
}*/ /* First 4 children */
li:nth-child(-n+4) {
background-color: cadetblue;
} /* Expect first three children*/
li:nth-child(n+4) {
background-color: lightgoldenrodyellow;
} /* Other psuedo classes:
* :nth-last-child
* :only-child
* :only-of-type
* :last-of-type
* :nth-of-type(an+b)
* :nth-last-of-type(an+b)
*/</style>
</head>
<body>
<ul>
<li><a href="#" target="_blank">target=_blank</a></li>
<li><a href="#" target="someFrame">target=someFrame</a></li>
<li><a href="#" rel="link-blog">rel=link-blog</a></li>
<li><a href="#" rel="linkproducts">rel=linkproducts</a></li>
<li><a href="#" rel="link about">rel=link about</a></li>
<li><a href="#" rel="link-about" title="special">rel=link-about title=special </a></li>
<li><a href="#" rel="link-other" title="special">rel=link-other title=special </a></li>
<li><a href="#" rel="this item available now">rel=this item available now</a></li>
<li><a href="#" rel="product-200-available-now">rel=product-200-available-now</a></li>
<li><a href="#" rel="linkproductavailable300">rel=linkproductavailable300</a>
<li><a href="#" rel="sale-product-400">rel=sale-product-400</a></li>
<li><a href="#" rel="sale">rel=sale</a></li>
<li><a href="#" rel="product-500-discontinued">rel=product-500-discontinued</a></li>
<li><a href="#" rel="product600discontinued">rel=product600discontinued</a></li>
<li><a href="#" rel="discontinued">rel=discontinued</a></li>
</ul>
<script src="script.js"></script>
</body>
</html>

[CSS] DOM Hierarchy Pseudo Classes :first-child :last-child :nth-child (demystified)的更多相关文章

  1. 【CSS】Intermediate2:Pseudo Classes

    1.specify a state or relation to the selector selector:pseudo_class { property: value; } 2.Link 3.Dy ...

  2. CSS pseudo classes All In One

    CSS pseudo classes All In One CSS 伪类 https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes ...

  3. dom core,html dom,css dom,jquery 中的dom操作

    前端开发中为达到某种目的,往往有很多方法:dom core,html dom,jquery; dom core/jquery主要通过函数调用的方式(getAttribute("属性名&quo ...

  4. [CSS3] Define Form Element States with CSS Form Pseudo Classes

    Using just semantic CSS Pseudo-Classes you can help define important states for form elements that e ...

  5. [CSS3] Identify Interactive HTML Elements with CSS Link Pseudo Classes

    The interactive pseudo-classes for links (and buttons) allow us to make sure the user knows what ele ...

  6. [CSS] The :empty Pseudo Selector Gotchas

    The :empty pseudo selector selects empty elements. We can use this to display useful messages instea ...

  7. Html,Css,Dom,javascript细节总结

    最近愈发觉得基础的重要性,细节决定成败,所以希望能够将自己注意到的搜集到的一些关于前端的小细节小知识整理出来,更好的方便自己记忆回顾. 1.在构建网页Html框架时,尽量只给外层标记(即是父标记)定义 ...

  8. 【CSS】Intermediate7:Pseudo Elements

    1.selector:pseudo element{property:value;} 2.first-letter  first-line CSS3:: 与pseudo class 区别 old br ...

  9. html+css+dom补充

    补充1:页面布局 一般像京东主页左侧右侧都留有空白,用margin:0 auto居中,一般.w. <!DOCTYPE html> <html lang="en"& ...

随机推荐

  1. contos vsftp 530错误

    只需要把/etc/pam.d/vsftpd文件中的 auth       required    pam_listfile.so item=user sense=deny file=/etc/vsft ...

  2. combo下拉列表选择

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. websql

    http://blog.darkcrimson.com/2010/05/local-databases/ http://www.oschina.net/question/12_26204 webkit ...

  4. Android 使用XmlSerializer生成xml文件

    在Android开发中,我们时常要用到xml文件. xml作为一种数据载体,在数据传输中发挥着重要的作用,而且它可读性比较强. 下面给出在Android开发中使用XmlSerializer类生成一个简 ...

  5. Github上更新自己Fork的代码

    一.前提本文的前提是你已经在github上fork了别人的分支,并且弄好了跟github的ssh连接.相关配置详情参考:https://help.github.com二.详细操作 检出自己在githu ...

  6. C++解析JSON之JsonCPP

    一.JSON简介 JSON全称为JavaScript ObjectNotation,它是一种轻量级的数据交换格式,易于阅读.编写.解析. JSON由两种基本结构构成: )"名称/值" ...

  7. bzoj1093

    首先缩点然后半连通其实就是缩点后节点数最多的链注意这里一定是一条链才一定是半连通然后重建图拓扑排序上做dp即可 type node=record po,next:longint; end; ..] o ...

  8. bzoj1231

    看到n<=16不难想到状压dp 我们用二进制表示前x个位置,哪些牛被已经被选过了 这里我们可以通过穷举二进制数的顺序来转移 所以二维就够了 ..] of longint;     f:.. sh ...

  9. HDU 1162 Eddy's picture

    坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32 ...

  10. 获取客户端IP地址 via C#

    获取客户端IP地址 via C# 说明:本文中的内容是我综合博客园上的博文和MSDN讨论区的资料,再通过自己的实际测试而得来,属于自己原创的内容说实话很少,写这一篇是为了记录自己在项目中做过的事情,同 ...