1.css3属性选择器

<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<title>css3属性选择器</title>
<style type="text/css">
/* id包含div字符串*/ [id*=div] {
color: lime;
}
/*开始字符串为div*/ [id^=div] {
color: red;
}
/*结束字符串为div*/ [id$=div] {
color: blue;
}
</style>
</head> <body>
<div>
<div id="div1">11</div>
<div id="2div2">22</div>
<div id="3div3">33</div>
<div id="44div">44</div>
<div id="wowo">55</div>
</div>
</body> </html>

2.css3结构伪类选择器

<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<title>css3结构伪类选择器</title>
<style type="text/css">
/* 第一行*/ body>p:first-line {
color: aqua;
}
/* 首字母*/ body>p:first-letter {
color: red;
}
/*元素前插入内容*/ li:before {
content: "--";
color: yellow;
}
/*元素后插入内容*/ li:after {
content: "++";
color: green;
}
/*根元素*/ :root {
background: darkgrey;
}
/*排除*/ div *:not(h1) {
background: green;
}
/*为空*/ .bb li:empty {
background: green;
}
/*业内跳转目标*/ :target {
background: orange;
}
</style>
</head> <body>
<p>
我是第一行
<br> 我是第二行
</p>
<ul>
<li class="aa">1</li>
<li>2</li>
<li class="aa">3</li>
<li class="aa">4</li>
</ul>
<ul class="bb">
<li>1</li>
<li></li>
<li>3</li>
<li></li>
<li>5</li>
<li></li>
</ul>
<div>
<h1>111</h1>
<h2>222</h2>
<h3>333</h3>
</div>
<a href="#a1">111</a>
<a href="#a2">222</a>
<a href="#a3">333</a>
<div id="a1">a1</div>
<div id="a2">a2</div>
<div id="a3">a3</div>
</body> </html>

3.css3选择器

<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<title>css3选择器</title>
<style type="text/css">
/*第一个元素*/ li:first-child {
background-color: yellow;
}
/*最后一个元素*/ li:last-child {
background-color: blue;
}
/*上到下第几个*/ li:nth-child(2) {
background-color: #666;
}
/*下到上第几个*/ li:nth-last-child(2) {
background-color: #888;
}
/*基数*/ li:nth-child(odd) {
color: red;
}
/*偶数*/ li:nth-child(even) {
color: #999;
}
/*只算同类元素*/ .aa h3:nth-of-type(2),
.aa h4:nth-of-type(2) {
color: red;
}
/*样式循环*/ .bb li:nth-child(4n+1) {
background-color: #111;
} .bb li:nth-child(4n+2) {
background-color: #222;
} .bb li:nth-child(4n+3) {
background-color: #333;
} .bb li:nth-child(4n) {
background-color: #444;
}
/*只有一个元素*/ li:only-child {
background-color: green;
}
</style>
</head> <body>
<ul>
<li>11</li>
<li>22</li>
<li>33</li>
<li>44</li>
<li>55</li>
<li>66</li>
<li>77</li>
<li>88</li>
</ul>
<div class="aa">
<h3>111</h3>
<h4>222</h4>
<h3>111</h3>
<h4>222</h4>
<h3>111</h3>
<h4>222</h4>
<h3>111</h3>
<h4>222</h4>
<h3>111</h3>
<h4>222</h4>
</div>
<div class="bb">
<ul>
<li>11</li>
<li>22</li>
<li>33</li>
<li>44</li>
<li>11</li>
<li>22</li>
<li>33</li>
<li>44</li>
<li>11</li>
<li>22</li>
<li>33</li>
<li>44</li>
<li>11</li>
<li>22</li>
<li>33</li>
<li>44</li>
</ul>
</div>
<ul>
<li>11</li>
</ul>
</body> </html>

4.UI元素状态伪类选择器

<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<title>UI元素状态伪类选择器</title>
<style type="text/css">
/*hover鼠标在控件上*/ input[type="text"]:hover {
background-color: darkviolet;
}
/*focus获取焦点*/ input[type="text"]:focus {
background-color: aqua;
}
/*active鼠标按住*/ input[type="text"]:active {
background-color: #666;
}
/*checked已选择状态*/ input[type="checkbox"]:checked {
outline: 2px solid gold;
}
/*enabled可用*/ .aa input[type="text"]:enabled {
background: yellow;
}
/*disabled不可用*/ .aa input[type="text"]:disabled {
background: red;
cursor: pointer;
}
</style>
</head> <body>
<input type="text" name="name">
<input type="text" name="age">
<input type="checkbox">111
<input type="checkbox">222
<input type="checkbox">333
<div class="aa">
<input type="text" name="name" id="t1">
<input type="text" name="age" id="t2" disabled>
</div>
</body> </html>

5.通用兄弟选择器

<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<title>通用兄弟选择器</title>
<style type="text/css">
/*跟在div后面的p元素*/
div~p {
background: gold;
} </style>
</head> <body>
<div>
<div>
<p>div的子元素p</p>
<p>div的子元素p</p>
</div>
<p>div相邻元素p</p>
<p>div相邻元素p</p>
<h4>----------</h4>
<div>
<p>div的子元素p</p>
</div>
<p>div相邻元素p</p>
<p>div相邻元素p</p>
</div>
<p>div相邻元素p</p>
<p>div相邻元素p</p>
</body> </html>

CSS3选择器介绍的更多相关文章

  1. CSS3 选择器 基本选择器介绍

    CSS是一种用于屏幕上渲染html,xml等一种语言,CSS主要是在相应的元素中应用样式,来渲染相对应用的元素,那么这样我们选择相应的元素就很重要了,如何选择对应的元素,此时就需要我们所说的选择器.选 ...

  2. 总结30个CSS3选择器

    或许大家平时总是在用的选择器都是:#id  .class  以及标签选择器.可是这些还远远不够,为了在开发中更加得心应手,本文总结了30个CSS3选择器,希望对大家有所帮助. 1 *:通用选择器 ;; ...

  3. 总结30个CSS3选择器(转载)

    或许大家平时总是在用的选择器都是:#id  .class  以及标签选择器.可是这些还远远不够,为了在开发中更加得心应手,本文总结了30个CSS3选择器,希望对大家有所帮助. 1 *:通用选择器 * ...

  4. CSS3 选择器——属性选择器

    上一节在<CSS3选择器——基本选择器>中主要介绍了CSS3选择器的第一部分,这节主要和大家一起来学习CSS3选择器的第二部分——属性选择器.属性选择器早在CSS2中就被引入了,其主要作用 ...

  5. CSS3 选择器——基本选择器

    CSS的选择器,我想大家并不会陌生吧,因为天天在使用,但对于CSS3的选择器,要运用的灵活到位,我想对很多朋友还是一定的难度,特别是CSS3中的:nth选择器.那么从现在开始我们先丢开他们版本的区别, ...

  6. [css3]CSS3选择器:nth-child和:nth-of-type之间的差异

    by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=1709 一.深呼吸,直 ...

  7. CSS3 选择器——伪类选择器

    前面花了两节内容分别在<CSS3选择器——基本选择器>和<CSS3选择器——属性选择器>介绍了CSS3选择器中的基本选择器和属性选择器使用方法,今天要和大家一起学习CSS3选择 ...

  8. CSS3选择器(三)之伪类选择器

    伪类选择器对于大家来说最熟悉的莫过于:link,:focus,:hover之类的了,因为这些在平时中是常用到的伪类选择器,那么先和大家一起简单总 结一下CSS中常用的伪类选择器的使用方法,最后把重心放 ...

  9. CSS3选择器:nth-child和:nth-of-type之间的差异

    CSS3选择器:nth-child和:nth-of-type之间的差异 这篇文章发布于 2011年06月21日,星期二,23:04,归类于 css相关. 阅读 57546 次, 今日 143 次 by ...

随机推荐

  1. 无法加载父级样式或设置IIS的asp站点启用父路径

    打开IIS 1.单击站点,在"IIS"区域中找到ASP图标,双击. 2.找到"启用父路径"项目,将对应的值设置为"TRUE"即可.   顶

  2. RabbitMQ Topic exchange

    Topic exchange topic与之前的每个类型都不同(ps:废话每个都是不同的).Topic解决了我们另一个需求.举个例子,有一个做资讯的公司,他们会收集各种科技公司的动态并且第一时间转发出 ...

  3. Python中的file和open简述

    help(file) help(open) 老规矩先看一下内置的帮助文档怎么描述file和open,毕竟官方文档是最直接最准确的描述. Help on class file in module __b ...

  4. <<< Oracle表空间创建、修改、删除基本操作

    ORACLE 中,表空间是数据管理的基本方法,所有用户的对象要存放在表空间中,也就是用户有空间的使用权,才能创建用户对象 create tablespace myts  //建立表空间,名为mytsd ...

  5. JSVirtualMachine与JSContext

    JSVirtualMachine相当于进程: JSContext相当于线程:

  6. Angular.js实现折叠按钮的经典指令.

    var expanderModule=angular.module('expanderModule',[]) expanderModule.directive('expander',function( ...

  7. 成为java高手的条件

    世界上并没有成为高手的捷径,但一些基本原则是可以遵循的. 1.扎实的基础 数据结构.离散数学.编译原理,这些是所有计算机科学的基础,如果不掌握它们,很难写出高水平的程序.程序人人都会写,但当你发现写到 ...

  8. 20145204&20145212实验二报告

    实验二固件设计 步骤: 1.开发环境的配置,参考实验一 1.将实验代码拷贝到共享文件夹中. 2.在虚拟机中编译代码.对于多线程相关的代码,编译时需要加-lpthread的库.下载调试在超级终端中运行可 ...

  9. css3 动画效果 总结 不断完善~~

    1.transition 动画过程改变某个css属性的效果 (比如宽高 颜色) 语法 transition:    all  所有元素                                + ...

  10. C++程序设计——知识点总结

    C++程序设计课程的总结,方便以后快速查阅和复习 Week 2 从C走进C++ 函数指针 函数名是函数的入口地址,指向函数的指针称为"函数指针". 比如,qsort库函数: voi ...