目录
0108 CSS3基础
0109 层级选择器
示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
/* 自带选择器 */
.box>li {
border: 1px solid red;
}
/* 当前元素的后面的第一个兄弟 */
/* .child+li{
background: yellow;
} */
/* ~当前元素的后面的所有的亲兄弟 */
.child~li{
background: yellow;
}
.container+p{
background: red;
}
</style>
</head>
<body>
<ul class="box">
<li>1111
<ul>
<li>111-111</li>
<li>111-222</li>
<li>111-333</li>
</ul>
</li>
<li class="child">2222</li>
<li>3333</li>
<li>44444</li>
<li>5555</li>
</ul>
<div class="container">div-1111</div>
<p>p-11111</p>
<p>p-22222</p>
<div>
<p>p-33333333</p>
</div>
</body>
</html>
0110 属性选择器
示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
/* 属性选择器 */
div[class]{
background: yellow;
}
/* div.box1{
} */
p[class]{
background: red;
}
/* 完全匹配 */
/* div[class=box1]{
border: 1px solid blue;
} */
/* 包含就匹配 */
div[class~=box1]{
border: 1px solid blue;
}
input[name]{
background: yellow;
}
input[type=email]{
background: red;
}
/* 模糊匹配 */
/* class^=b 以这个开头的
class$=b 以这个结尾的
class*=b 包含某个字符 */
div[class^="b"]{
color: green;
}
div[class$="3"]{
color: white;
}
</style>
</head>
<body>
<div class="box1">div-11111</div>
<div class="box2">div-22222</div>
<div>div-33333</div>
<div class="box1">div-44444</div>
<p class="p1">p-11111</p>
<p class="p2">p-22222</p>
<p>p-33333</p>
<div>
<h1>注册页面</h1>
用户名:<input type="text" name="username"/><br />
密码:<input type="password" name="password"/><br />
年龄:<input type="number" name="age"/><br />
邮箱:<input type="email" /><br />
<input type="submit">
</div>
</body>
</html>
0111 结构伪类选择器
示例代码1:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
.box{
width: 940px;
height: 100px;
margin: 0 auto;
background: yellow;
}
.box div{
float: left;
width: 300px;
height: 100px;
background-color: red;
margin-right: 20px;
}
.box div:last-child{
margin-right: 0;
}
</style>
</head>
<body>
<!-- 通过某种结构关系查找页面元素
比如:
匹配某元素第一个子元素
匹配某元素最后一个子元素 -->
<div class="box">
<div></div>
<div></div>
<div></div>
</div>
</body>
</html>
示例代码2:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
/* li:first-child{
background: yellow;
}
li:last-child{
background: red;
} */
/* 第几个 */
/* li:nth-child(2){
background: blue;
} */
/* 第几个 偶数 2n(even) 奇数 2n+1 2n-1(odd)*/
li:nth-child(odd){
background: yellow;
}
</style>
</head>
<body>
<ul>
<li>11111</li>
<li>22222</li>
<li>33333</li>
<li>44444</li>
<li>55555</li>
</ul>
</body>
</html>
示例代码3:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
div{
border: 1px solid black;
}
div p:only-child{
background: red;
}
</style>
</head>
<body>
<div>
<p>1111</p>
<p>2222</p>
</div>
<div>
<p>11111</p>
</div>
</body>
</html>
示例代码4:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
div{
width: 100px;
height: 100px;
}
div:empty{
background: yellow;
}
</style>
</head>
<body>
<div>
11111
</div>
<div></div>
</body>
</html>
示例代码5:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
:root,body{
height: 100%;
background: yellow;
}
</style>
</head>
<body>
</body>
</html>
0112 目标伪类选择器
E:target
选择匹配E的所有元素,且匹配元素被相关URL指向
示例代码1:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
ul{
list-style: none;
position: fixed;
right: 0;
top: 100px;
}
li{
width: 100px;
height: 50px;
line-height: 50px;
text-align: center;
border: 1px solid black;
}
div{
height: 600px;
border: 1px solid #cccccc;
/* background: yellow; */
}
div:target{
background: yellow;
}
/* 锚点作用:页面不同区域的跳转,使用a链接
<a href="#锚点名字"></a>
<div id="锚点名字"></div>
*/
</style>
</head>
<body>
<ul>
<li><a href="#a">京东秒杀</a></li>
<li><a href="#b">双11</a></li>
<li><a href="#c">频道优选</a></li>
<li><a href="#d">特色广场</a></li>
</ul>
<div id="a">
京东秒杀
</div>
<div id="b">
双11
</div>
<div id="c">
频道优选
</div>
<div id="d">
特色广场
</div>
</body>
</html>
示例代码2:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
div.content{
display: none;
}
div.content:target{
display: block;
}
</style>
</head>
<body>
<div>
<a href="#aaa">aaa</a>
<div id="aaa" class="content">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Officia ex molestias aperiam atque minima beatae quis ab
dolorem harum explicabo. Itaque temporibus quos esse
dignissimos repellendus doloribus, a architecto quis.
</div>
</div>
<div>
<a href="#bbb">bbb</a>
<div id="bbb" class="content">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Officia ex molestias aperiam atque minima beatae quis ab
dolorem harum explicabo. Itaque temporibus quos esse
dignissimos repellendus doloribus, a architecto quis.
</div>
</div>
<div>
<a href="#ccc">ccc</a>
<div id="ccc" class="content">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Officia ex molestias aperiam atque minima beatae quis ab
dolorem harum explicabo. Itaque temporibus quos esse
dignissimos repellendus doloribus, a architecto quis.
</div>
</div>
</body>
</html>
0113 UI状态伪类选择器
3、UI 元素状态伪类选择器
E:enabled 匹配所有用户界面 (form表单) 中处于可用状态的E元素
E:disabled 匹配所有用户界面 (form表单) 中处于不可用状态的E元素
E:checked 匹配所有用户界面 (form表单)中处于选中状态的元素E
E:selection 匹配E元察中被用户选中或处于高亮状态的部分
示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
input:enabled{
/* background: red; */
}
input:disabled{
background: yellow;
}
/* 焦点 会匹配此选择器 */
input:focus{
background: blue;
}
input[type=checkbox]{
/* 去掉默认样式 */
appearance: none;
width: 20px;
height: 20px;
border: 1px solid black;
}
input:checked{
background: red;
}
div::selection{
background: yellow;
color: red;
}
</style>
</head>
<body>
<form action="">
用户者<input type="text" /><br />
密码<input type="password" /><br />
记住用户名 <input type="checkbox" /><br />
<input type="submit" disabled/>
</form>
<div>
Lorem ipsum dolor sit, amet consectetur adipisicing elit.
Ea molestiae placeat veniam et ducimus, excepturi animi
est eius deserunt in architecto? Tenetur similique rerum
ratione voluptatem suscipit aperiam doloribus dolorem!
</div>
</body>
</html>
0114 否定和动态伪类选择器
示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
/* li:not(:first-child){
background: yellow;
} */
li:nth-child(2n+1){
background: yellow;
}
div{
width: 100px;
height: 100px;
}
div:not(:empty){
background: red;
}
</style>
</head>
<body>
<ul>
<li>1111</li>
<li>2222</li>
<li>3333</li>
<li>4444</li>
</ul>
<div>111111</div>
<div></div>
</body>
</html>
0115 文本阴影
示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
div{
text-shadow: 0px -10px 1px red,0px 10px 1px yellow;
/* text-shadow: 0px -10px 1px red; */
}
/* 10px 水平方向位移
10px 垂直方向位移
1px 模糊程度
red 阴影颜色 */
</style>
</head>
<body>
<div>大家好</div>
</body>
</html>
0116 盒子阴影
代码示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
div{
width: 100px;
height: 100px;
background: yellow;
margin: 0 auto;
box-shadow: 10px 10px 1px red inset;
/* box-shadow: 10px 10px 1px red; */
}
</style>
</head>
<body>
<div>
</div>
</body>
</html>
0117 圆角边框上
示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
div{
width: 200px;
height: 200px;
background: green;
margin: 0 auto;
/* border-radius: 10px 50px 70px 100px; */
/* px 或者百分比
v1,四个角都一样
v1,v2,左上右下,左下右上 一致
v1,v2,v3 左上,左下右上,右下
v1,v2,v3,v4 顺时针
*/
border-top-left-radius: 10px;
border-top-right-radius: 30px;
border-bottom-left-radius: 60px;
border-bottom-right-radius: 100px;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
0118 圆角边框下
示例代码1:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
div{
width: 200px;
height: 200px;
background: green;
margin: 0 auto;
padding: 20px;
border: 20px solid red;
/* border-radius: 30px/60px; */
/* 30px/60px 水平/垂直 支持border-radius */
/* border-top-left-radius: 30px/60px; 不支持的*/
/* border-radius: 10px 20px 30px 40px/50px 60px 70px 80px; */
border-radius: 50%;
/* 一半===盒子的一半 */
}
</style>
</head>
<body>
<div></div>
</body>
</html>
示例代码2:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
div{
width: 500px;
height: 200px;
background: green;
margin: 0 auto;
/* border-radius: 10%; */
border-radius: 50px;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
示例代码3:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
div{
width: 100px;
height: 50px;
background: green;
margin: 0 auto;
border-radius: 50px 50px 0 0;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
示例代码4:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
div{
width: 200px;
height: 200px;
background: green;
margin: 0 auto;
border-radius: 200px 0 0 0;
}
</style>
</head>
<body>
<div></div>
</body>
</html>