01 引入方式
<!DOCTYPE html><html lang="zh"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <!--内联方式--> <style> #A{ width: 60px; height: 40px; background-color:aqua; } </style> <!--外联方式--> <link rel="stylesheet" href="./01 引入方式.css"></head><body> <div style="width: 60px; height: 40px;background-color: burlywood;">零</div><!--内部方式--> <div id="A">一</div> <div class="B">二</div></body></html>
.B{ width: 60px; height: 40px; background-color: blue;}/* 颜色:(RGB模式) R:红色 0-255 G:绿色 0-255 B:蓝色 0-255 1. color:(10,20,30) 2. color:(100%,20%,50%) 3. color:blue 4. color:#fff*//* 原理: 优先原则: 继承原则*/
02 基本选择器
<!DOCTYPE html><html lang="zh"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="./02 基本选择器.css"/></head><body> <div>好好</div> <div id="haha">哈哈</div> <div class="hehe">呵呵</div> <div class="hehe">嗯嗯</div></body></html>
/*通配符*/*{ background-color: aquamarine;}/*标签*/div{ width: 240px; height:320px; background-color: blanchedalmond;}/*ID选择器*/#haha{ width: 240px; height:320px; background-color: chartreuse;}/*class选择器*/.hehe{ width: 240px; height:320px; background-color: darkred;}/* p#p{} 选择p标签下id为p的元素 p.p{} 选择p标签下class为p的元素*/
03 组合选择器
<!DOCTYPE html><html lang="zh"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="./03 组合选择器.css"/></head><body> <div>哈哈 <p>嗯嗯</p> </div> <p>呵呵 </p></body></html>
/*分组选择器*/div,p{ width: 240px; height:240px; background-color: aqua;}p{ font-size: 32px;}/*嵌套选择器*/div p{ font-size: 24px; border:1px solid #ffffff;}/* 子选择器 div > p 同级选择器 div+p*/
04 属性选择器
<!DOCTYPE html><html lang="zh"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="./04 属性选择器.css "></head><body> <div id="11">哈哈</div> <div class="22">呵呵</div> <div class="33">嗯嗯</div> <div class="22 33">好好</div> <div class="44">哦哦</div> <div class="22 44">噢噢</div> <div class="33 44">欧欧</div></body></html>
/*属性选择器1.有属性的S标签基本S[属性]{}2.属性=值的标签[属性=值]{}3.属性包含值的标签[属性~=值]{}4.属性以值开始的标签[属性^=值]{}5.属性以值结束的标签[属性$=值]{}*/div{ width: 160px; height:240px; background-color:#369;}/*所有div都被选择*/div[id]{ width: 160px; height:240px; background-color:#666;}/*有id属性的div被选择*/div[class = "33"]{ width: 160px; height:240px; background-color:#963;}/*属性class="33"的被选择*/div[class~="44"]{ width: 160px; height:240px; background-color:red;}/*属性class包含"44"的被选择*/
05 伪元素选择器
<!DOCTYPE html><html lang="zh"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="./05 伪元素选择器.css"/></head><body> <!--<before>--> <p>哈哈</p> <!--<after>--></body></html>
p::before{ content:"开始";}p::after{ content:"结束";}/* 块元素: 第一行:first-line 第一个字母:first-letter*/
06 背景
<!DOCTYPE html><html lang="zh"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="./06 背景.css"/></head><body> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br></body></html>
body{ /*设置图片背景,默认平铺*/ background-image: url('http://www.pptbz.com/pptpic/UploadFiles_6909/201211/2012111719294197.jpg'); /* background-repeat:repeat-x; 以x轴平铺 background-repeat:repeat-y; 以y轴平铺 */ background-repeat: no-repeat; /*设置不平铺*/ background-position: 50% 10%; /*设置平移*/ background-attachment: fixed; /*固定*/}
07 字体
<!DOCTYPE html><html lang="zh"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="./07 字体.css"/></head><body> <p class="p">hello world</p></body></html>
.p{ /*设置字体*/ font-family: 'Courier New', Courier, monospace; /*设置大小*/ font-size: 24px; /*设置粗细:normal(普通) lighter(小) bold(大)*/ font-weight: bold; /*样式*/ font-style: italic; /*行距*/ line-height: 20px; /* font:style weight size/line-height font-family */ /*字符间距*/ letter-spacing: 10px; /*空格间距*/ word-spacing: 20px; /*书写方向*/ direction:ltr;/*右到左*/ /*水平线 overline 上 line-through 中 underline 下 */ text-decoration: aquamarine line-through; /*对齐 center left right justify(两端对齐) */ text-align:center; /*文字缩进*/ text-indent: 60px; /*英文大小写 uppercase 全大 lowercase 全小 capitalize 首大 */ text-transform: uppercase; /*文字省略*/ width: 300px; background-color: aqua; white-space: nowrap;/*不换行*/ overflow: hidden; /*截掉*/ text-overflow: ellipsis;/*替换为省略号*/}/* 与图片结合的布局 1.垂直对齐:top center bottom vertical-align:top 2.环绕图片: float:left; 3...*/
08 链接
<!DOCTYPE html><html lang="zh"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="./08 链接 列表.css"></head><body> <a href="#1">AAA</a><br> <a href="#1">BBB</a><br> <a href="#2">CCC</a></body></html>
a{ color: aqua;}/*伪类 初始状态 link 被访问 visited 获得焦点 hover 点击 active */a:link {color: #FF0000}a:visited {color: #00FF00}a:hover {color: #FF00FF}a:active {color: #0000FF}
09 盒子框模型
<!DOCTYPE html><html lang="zh"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="./09 盒子框模型.css"></head><body> <div id="a">hello</div> <div id="b">world</div></body></html>
/* 值 上下左右 值 值 上下 左右 值 值 值 值 上 下 左 右内边距 padding 外边距 margin 有重叠问题: 上下 值不同时取大 解决方法: 1.float 2.display:inline-block 嵌套 无内容时子盒不存在边距 解决方法: 1.border 2.padding 3.float:hidden*/#a{ width: 320px; height:240px; border: 2px solid #666; padding: 20px; margin:60px; background-color: aqua;}#b{ width: 320px; height:240px; border: 2px solid #666; margin:20px; background-color: blueviolet;}
10 布局
<!DOCTYPE html><html lang="zh"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="./10 布局.css"></head><body> <div class="div1">div1</div> <div class="div2">div2</div> <div class="div3">div3</div> <div class="div4">div4</div> <div class="div5">div5</div> <div class="div6">div6</div></body></html>
div{ border: 2px solid #666; background-color: aqua; width: 320px; height: 240px;}/*浮动流*/.div1,.div2{ border: 2px solid #666; background-color: aquamarine; width: 160px; height: 120px; float: left;}/*用伪元素清除浮动,转回标准流*/.div2::after{ /* block: 占据一行,可设置宽高 inline: 不占一行,不可设置宽高 */ content:" "; /*增加内容,使元素存在*/ display:block; /*变为块元素*/ clear:both; /*清除浮动*/}/* 其他盒子模型: inline-block 不占一行,可设置宽高 inline-table list-item 类似于<ul> run-in 在后面元素内显示*/
11 定位
<!DOCTYPE html><html lang="zh"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="./11 定位.css"></head><body> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <div id="A">哈哈</div> <div id="B">呵呵 <div id="C">嗯嗯</div> </div> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br></body></html>