CSS3选择器
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.pox1~div{
color: #FF0000;
}
a[href]{
font-size: 50px;
}
a[title="百度"]{
color: yellow;
}
a[title^='百']{
color: aqua;
}
</style>
</head>
<body>
<!-- 相邻兄弟选择器:选择box1下一个兄弟(同级) -->
<div class="box1">我是1</div>
<div class="box2">我是2</div>
<!-- 匹配选择器: pox1下同级所有的div-->
<div class="pox1">我是P1</div>
<div class="pox2">我是P2</div>
<div class="pox3">我是P3</div>
<!-- 属性选择器 -->
<!-- ^ :以*开头
$:以*结尾
* :包含*(包含单词就行)
~ 必须为单个单词(为空格用)
|带-的 moren-
-->
<ul>
<li><a href="www.baidu.com" title="百度">超链接1</a></li>
<li><a href="" title="度">超链接2</a></li>
<li><a >超链接3</a></li>
</ul>
</body>
</html>
选择器2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
li:first-child{
color: red;
}
li:nth-child(2){
font-size: 30px;
}
li:last-child{
color: #00FFFF;
}
li:nth-last-child(2){
text-indent: 50px;
}
li:first-of-type{
color: #FFFF00;
}
li:nth-of-type(2){
color: #FFFF00;
}
li:last-of-type{
color: aquamarine;
}
li:nth-last-of-type(2){
text-decoration: underline;
}
</style>
</head>
<body>
<!-- -->
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</body>
</html>
其他伪类选择器
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
:root{
border: solid 10px orange;
}
:empty{
width: 300px;
height: 200px;
border: solid 2px #FFFF00;
}
div:not(.my){
color: #00FFFF;
}
</style>
</head>
<body>
<div>1</div>
<div>2</div>
<div>3</div>
<div class="my"></div>
<div>4</div>
<div>5</div>
</body>
</html>
锚点选择器
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
:empty{
height: 1000px;
}
#skip{
height: 200px;
background-color: aquamarine;
}
:target{
color: bisque;
font-size: 30px;
}
</style>
</head>
<body>
<a href="#skip">你好</a>
<div></div>
<div id="skip">欢迎光临</div>
</body>
</html>
文本选择 伪元素
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
::selection{
background-color: deepskyblue;
}
</style>
</head>
<body>
<div class="box">
2.加载顺序区别
加载页面时,link标签引入的 CSS 被同时加载;@import引入的 CSS 将在页面加载完毕后被加载。
3.兼容性区别
@import是 CSS2.1 才有的语法,故只可在 IE5+ 才能识别;link标签作为 HTML 元素,不存在兼容性问题。
4.DOM可控性区别
可以通过 JS 操作 DOM ,插入link标签来改变样式;由于 DOM 方法是基于文档的,无法使用@import的方式插入样式。
</div>
</body>
</html>
元素追加伪元素
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.box::before{
content: "selection";
color: #7FFFD4;
font-size: 25px;
}
.box::after{
content: "selection";
color: #7FFFD4;
font-size: 25px;
}
</style>
</head>
<body>
<div class="box">
jfhjfghfjgjfkjfjjfkj京东客服经济法
</div>
</body>
</html>
表单状态选择器
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
input:disabled{
background-color: #00FFFF;
}
input:checked{
background-color: #00FFFF;
}
input:enabled{
background-color: #FF0000
}
</style>
</head>
<body>
<form action="">
昵称: <input type="text" disabled="disabled">
<br>
密码: <input type="text" >
</form>
</body>
</html>
JS新增的选择器
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div class="box">1</div>
<div class="box">2</div>
<div class="box">3</div>
<script type="text/javascript">
var obox=document.querySelector('.box');
obox.style.color='blue';
var obox1=document.querySelectorAll('.box')[1];
obox1.style.color='pink';
</script>
</body>
</html>
CSS新属性
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.box{
width: 300px;
height: 300px;
background-color: #00FFFF;
}
.box{
background-image: url() url();
}
.box{
background-image: linear-gradient(to right, red,green,blue);
}
.box{
background-image: radial-gradient(ellipse,red,green,blue);
}
.box{
background-origin: padding-box;
}
.box{
filter:grayscale(100%) ;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>