0%
内容概要
- 分组与嵌套
- 伪类选择器
- 伪元素选择器
- 选择器优先级
- css属性相关(操作标签样式)
- 浮动
- 定位
- 模态框
- 透明度
内容详细
分组与嵌套
1 2 3 4 5 6
| div,p,span { color: yellow; } #d1,.c1,span { color: orange; }
|
伪类选择器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body { background-color: black; } a:link { color: red; } a:hover { color: aqua; } a:active { color: black; } a:visited { color: darkgray; } p { color: darkgray; font-size: 48px; } p:hover { color: white; } input:focus { background-color: red; } </style> </head> <body> <a href="https://www.jd.com/">小轩在不在?</a> <p>点我有你好看哦</p> <input type="text"> </body> </html>
|
伪元素选择器
1 2 3 4 5 6 7 8 9 10 11 12 13
| p:first-letter { font-size: 48px; color: orange; } p:before { /*在文本开头 同css添加内容*/ content: '你说的对'; color: blue; } p:after { content: '雨露均沾'; color: orange; } ps:before和after通常都是用来清除浮动带来的影响:父标签塌陷的问题(后面马上讲)
|
选择器优先级
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| """ id选择器 类选择器 标签选择器 行内式 """ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#d1 { color: aqua; } </style>
</head> <body> <p id="d1" class="c1" style="color: blue">贤妻果然很识趣,有前途~</p> </body> </html>
|
css属性相关
1 2 3 4 5 6 7 8 9 10 11 12 13
| <style> p { background-color: red; height: 200px; width: 400px; } span { background-color: green; height: 200px; width: 400px; } </style>
|
字体属性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| p {
}
|
文字属性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| p {
font-size: 16px; text-indent: 32px; } a { text-decoration: none; }
|
背景图片
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> #d1 { height: 500px; background-color: red; } #d2 { height: 500px; background-color: green; } #d3 { height: 500px; background-image: url("222.png"); background-attachment: fixed; } #d4 { height: 500px; background-color: aqua; } </style> </head> <body> <div id="d1"></div> <div id="d2"></div> <div id="d3"></div> <div id="d4"></div> </body> </html>
|
边框
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style>
p { background-color: red;
border-width: 5px; border-style: solid; border-color: green;
} div {
border: 3px solid red;
} #d1 { background-color: greenyellow; height: 400px; width: 400px; border-radius: 50%; } </style> </head> <body> <p>穷人 被diss到了 哭泣.png</p> <div>妈拉个巴子,妈拉个巴子,妈拉个巴子,妈拉个巴子</div> <div id="d1"></div> </body> </html>
|
display属性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> </style> </head> <body> <div style="display: none">div1</div> <div>div2</div> <div style="visibility: hidden">单纯的隐藏 位置还在</div> <div>div4</div>
</body> </html>
|
盒子模型
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| """ 盒子模型 就以快递盒为例 快递盒与快递盒之间的距离(标签与标签之间的距离 margin外边距) 盒子的厚度(标签的边框 border) 盒子里面的物体到盒子的距离(内容到边框的距离 padding内边距) 物体的大小(内容 content) 如果你想要调整标签与标签之间的距离 你就可以调整margin 浏览器会自带8px的margin,一般情况下我们在写页面的时候,上来就会先将body的margin去除 """ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body { margin: 0;
}
#d1 { margin-bottom: 50px; }
#d2 { margin-top: 20px; }
#dd { margin: 0 auto; } p { border: 3px solid red;
} </style> </head> <body>
<p>ppp</p>
</body> </html>
|
浮动
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| """浮动的元素 没有块儿级一说 本身多大浮起来之后就只能占多大""" 只要是设计到页面的布局一般都是用浮动来提前规划好 <style> body { margin: 0; } #d1 { height: 200px; width: 200px; background-color: red; float: left; } #d2 { height: 200px; width: 200px; background-color: greenyellow; float: right; } </style>
|
解决浮动带来的影响
溢出属性
1 2 3 4 5 6 7 8 9
| p { height: 100px; width: 50px; border: 3px solid red; }
|
定位
静态
所有的标签默认都是静态的static,无法改变位置
相对定位(了解)
相对于标签原来的位置做移动relative
绝对定位(常用)
相对于已经定位过的父标签做移动(如果没有父标签那么就以body为参照)
eg:小米网站购物车
当你不知道页面其他标签的位置和参数,只给了你一个父标签的参数,让你基于该标签左定位
固定定位(常用)
相对于浏览器窗口固定在某个位置
eg:右侧小广告
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body { margin: 0; } #d1 { height: 100px; width: 100px; background-color: red; left: 50px; top: 50px; position: relative;
}
#d2 { height: 100px; width: 200px; background-color: red; position: relative; } #d3 { height: 200px; width: 400px; background-color: yellowgreen; position: absolute; left: 200px; top: 100px; }
#d4 { position: fixed; bottom: 10px; right: 20px;
height: 50px; width: 100px; background-color: white; border: 3px solid black; } </style> </head> <body>
<div style="height: 500px; color: rgb(152, 26, 26);">></div> <div style="height: 500px; color: rgb(152, 26, 26);">></div> <div style="height: 500px; color: rgb(152, 26, 26);">></div> <div id="d4">回到顶部</div>
</body> </html>
ps:浏览器是优先展示文本内容的
|
验证浮动和定位是否脱离文档流(原来的位置是否还保留)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| """ 浮动 相对定位 绝对定位 固定定位 """ # 不脱离文档流 1.相对定位 # 脱离文档流 1.浮动 2.绝对定位 3.固定定位
<div style="height: 100px;width: 200px;"></div> <div style="height: 100px;width: 200px;position: fixed;bottom: 10px;right: 20px"></div> <div style="height: 100px;width: 200px;"></div>
|
z-index模态框
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| eg:百度登陆页面 其实是三层结构 1.最底部是正常内容(z=0) 最远的 2.黑色的透明区(z=99) 中间层 3.白色的注册区域(z=100) 离用户最近
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body { margin: 0; } .cover { position: fixed; left: 0; top: 0; right: 0; bottom: 0; background-color: rgba(0,0,0,0.5); z-index: 99; } .modal { background-color: white; height: 200px; width: 400px; position: fixed; left: 50%; top: 50%; z-index: 100; margin-left: -200px; margin-top: -100px;
} </style> </head> <body> <div>这是最底层的页面内容</div> <div class="cover"></div> <div class="modal"> <h1>登陆页面</h1> <p>username:<input type="text"></p> <p>password:<input type="text"></p> <button>点我点我~</button> </div> </body> </html>
|
透明度opacity
1 2 3 4 5
| rgba只能影响颜色 而opacity可以修改颜色和字体
opacity: 0.5;
|