[CSS] DOM Hierarchy Pseudo Classes :first-child :last-child :nth-child (demystified)
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)的更多相关文章
- 【CSS】Intermediate2:Pseudo Classes
1.specify a state or relation to the selector selector:pseudo_class { property: value; } 2.Link 3.Dy ...
- CSS pseudo classes All In One
CSS pseudo classes All In One CSS 伪类 https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes ...
- dom core,html dom,css dom,jquery 中的dom操作
前端开发中为达到某种目的,往往有很多方法:dom core,html dom,jquery; dom core/jquery主要通过函数调用的方式(getAttribute("属性名&quo ...
- [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 ...
- [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 ...
- [CSS] The :empty Pseudo Selector Gotchas
The :empty pseudo selector selects empty elements. We can use this to display useful messages instea ...
- Html,Css,Dom,javascript细节总结
最近愈发觉得基础的重要性,细节决定成败,所以希望能够将自己注意到的搜集到的一些关于前端的小细节小知识整理出来,更好的方便自己记忆回顾. 1.在构建网页Html框架时,尽量只给外层标记(即是父标记)定义 ...
- 【CSS】Intermediate7:Pseudo Elements
1.selector:pseudo element{property:value;} 2.first-letter first-line CSS3:: 与pseudo class 区别 old br ...
- html+css+dom补充
补充1:页面布局 一般像京东主页左侧右侧都留有空白,用margin:0 auto居中,一般.w. <!DOCTYPE html> <html lang="en"& ...
随机推荐
- bzoj 3858: Number Transformation 暴力
3858: Number Transformation Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 82 Solved: 41[Submit][Sta ...
- 【技术贴】解决 myeclipse打不开报错an error has occurred, see .
方法1.右键选中快捷方式属性选项,在快捷方式页,目标一项最后加上-clean选项,如C:\MyEclipse6\eclipse.exe -clean. 然后重新启动一下MyEclipse. 方法2. ...
- nginx日志配置
nginx日志配置 http://www.ttlsa.com/linux/the-nginx-log-configuration/ 日志对于统计排错来说非常有利的.本文总结了nginx日志相关的配置如 ...
- GIT在LINUX下的基本操作
没办法,看来,VIM技能也要同步练起来了. 离开了WIN的日常应用安乐窝,外面的世界有多精彩? GIT的错了我再改..呵呵 git clone http://username@1.2.3.4/repo ...
- Android 小知识点(持续更新)
①文件保存默认是private权限. ②在layout的xml文件中onClick的方法中包含一个View类型的参数 ③获取项目下files路径:Context.getFilesDir(); ④获取项 ...
- SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-005-Bean的作用域@Scope、ProxyMode
一. Spring的bean默认是单例的 But sometimes you may find yourself working with a mutable class that does main ...
- jQuery zTree v3.5 实例3 异步树
最终效果: 点击非叶子节点时,向后台发送请求,获取下级菜单 前台代码如下: <%@ page language="java" contentType="text/h ...
- C#的装箱和拆箱
1:装箱 其实就是将一个值类型的转换成一个引用类型,或者把值类型转换成一个被该值类型那个应用的接口类型,这个过程会使用堆栈.被装箱的值是作为一个复制赋给对象的. int intValue = 100 ...
- 生成AWK快照的方法
1.首先在用oracle用户登陆执行sqlplus命令用dba用户执行: exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT (flush_level=> ...
- 经典算法面试题目-翻转一个C风格的字符串(1.2)
题目: Write code to reverse a C-Style String. (C-String means that "abcd" is represented as ...