HTML笔记
html基础
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| 六级标题标签 <h1>文字<h1> <h2>文字<h2> <h3>文字<h3> <h4>文字<h4> <h5>文字<h5> <h6>文字<h6>
段落标签 <p>文字</p>
换行标签 <br>
水平分割标签 <hr>
|
文本标签
标签 |
说明 |
b |
加粗 |
u |
下划线 |
i |
倾斜 |
s |
删除线 |
标签 |
说明 |
strong |
加粗 |
ins |
下划线 |
em |
倾斜 |
del |
删除线 |
基础标签
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
| 图片 <body> <img src="1.jpg" alt="替换文本" title="这是个鼠标悬停提示" width="500" > </body>
音频 <body> <audio src="./audio/1.mp3" controls autoplay loop></audio> </body>
视频 <body> <video src="./video/白挺 - 你从未离去.mp4 " controls width="1000"></video> </body>
超链接 <body> <a href="https://wwww.baidu.com/" target="_self">跳转到百度 </a> <br> <a href="./01 标题标签.html" target="_blank">跳转</a> </body>
|
列表标签
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
| 无序 <body> <ul> <li>榴莲</li> <li>香蕉</li> <li>苹果</li> </ul> </body>
有序 <body> <ol> <li>第一名</li> <li>第二名</li> <li>第三名</li> </ol> </body>
自定义 <body> <dl> <dt>帮助中心</dt> <dd>账户管理</dd> <dd>购物指南</dd> </dl> </body>
|
表格
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 72 73 74 75 76 77 78 79 80
| 基础表格 <body> <table border="1" width="500" height="100"> <caption>学生成绩单</caption>
<thead> <tr> <th>姓名</th> <th>成绩</th> </tr> </thead> <tbody> <tr> <td>张三</td> <td>100</td> </tr> <tr> <td>李四</td> <td>90</td> </tr> </tbody> <tfoot> <tr> <td>总结</td> <td>都不错</td> </tr> </tfoot> </table> </body>
单元格合并 <body> <table border="1" width="500" height="100"> <caption>学生成绩单</caption>
<thead> <tr> <th>姓名</th> <th>成绩</th> </tr> </thead> <tbody> <tr> <td>张三</td> <td rowspan="2">100</td> <td>考的好</td> </tr> <tr> <td>李四</td> <td>考的好</td> </tr> </tbody> <tfoot> <tr> <td>总结</td> <td colspan="2">都不错</td> </tr> </tfoot> </table> </body>
|
表单
根据type属性不同,有不同作用
标签名 |
type属性 |
作用 |
input |
text |
文本框,输入单行文本 |
input |
password |
密码框 |
input |
radio |
单选框,多选一 |
input |
checkbox |
多选框,多选多 |
input |
file |
文本选择,上传文件 |
input |
submit |
提交按钮 |
input |
reset |
重置按钮 |
input |
button |
普通按钮,默认无功能,需配合js |
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
| <body> <form action="">
文本框:<input type="text" placeholder="输入用户名">
<br> <br>
密码框:<input type="password" placeholder="密码">
<br> <br>
性别:<input type="radio" name="sex" checked>男 <input type="radio" name="sex">女
<br> <br>
多选框:<input type="checkbox" checked>
<br> <br>
上传文件<input type="file" multiple>
<br> <br>
按钮:<input type="submit"> 重置:<input type="reset"> 按钮:<input type="button" value="普通按钮">
</form> </body>
|
标签名 |
type属性 |
作用 |
button |
submit |
提交按钮,提交后端服务器 |
button |
reset |
重置按钮 |
button |
button |
普通按钮,需配合js |
1 2 3 4 5 6
| <body> <button>按钮</button> <button type="submit">提交按钮</button> <button type="reset">重置按钮</button> <button type="button">普通按钮</button> </body>
|
select
下拉菜单
1 2 3 4 5 6 7 8 9
| <body> <select> <option>北京</option> <option>上海</option> <option selected>广州</option> <option>深圳</option> </select> </body>
|
textarea
文本域标签
1 2 3 4
| <body> <textarea cols="200" rows="30"></textarea> </body>
|
label
用于区域选中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <body> 性别: <input type="radio" name="sex" id="1"> <label for="1">男</label>
<label> <input type="radio" name="sex"> 女</label> </body> <body> 性别: <input type="radio" name="sex" id="1"> <label for="1">男</label>
<label> <input type="radio" name="sex"> 女</label> </body>
|
语义标签
1 2 3 4 5 6 7 8 9
| 无语义 <body> <div>div标签</div> <div>div标签</div>
<span>span标签</span> <span>span标签</span>
</body>
|
有语义,手机端标签
标签名 |
语义 |
header |
网页头部 |
nav |
网页导航 |
footer |
网页底部 |
aside |
网页侧边栏 |
section |
网页区块 |
article |
网页文章 |
1 2 3 4 5 6 7 8
| <body> <header>网页头部</header> <nav>网页导航</nav> <footer>网页底部</footer> <aside>侧边栏</aside> <section>网页区块</section> <article>文章</article> </body>
|
字符实体
1 2 3 4
| <body> 这是一段话,用于 字符实体的使用 </body>
|
CSS入门
引入方式 |
书写位置 |
作用范围 |
使用场景 |
内嵌式 |
css写在style标签 |
当前页面 |
小案例 |
外联式 |
css写在单独的css文件中,通过link标签引入 |
多个页面 |
项目中 |
行内式 |
css写在标签style属性中 |
当前标签 |
配合js |
内嵌式
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title>
<style>
p{ color: red;
font-size: 30px;
background-color: aqua; width: 400px; height: 400px; } </style> </head> <body> <p>这是一个p标签</p> </body> </html>
|
外联式&行内式
.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title>
<link rel="stylesheet" href="27 CSS的引入.css"> </head> <body> <p>这是一个p标签</p>
<div style="color: green; font-size: 30px;">这是一个div标签</div> <div>第二个div标签</div> </body> </html>
|
.css
选择器
标签选择器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title>
<style> p{ color:red } </style> </head> <body> <p>这是第一个标签</p> <p>这是第二个标签</p> <p>这是第三个标签</p> </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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title>
<style> .red{ color: red; } .green{ color: green; } .size{ font-size: 66px; } </style> </head> <body> <p class="red">这是第一个标签</p> <p class="green">这是第二个标签</p> <p>这是第三个标签</p> <div class="red size" >这是第四个</div> </body> </html>
|
ID选择器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title>
<style> #blue { color: blue; } </style> </head> <body> <div id="blue">第一个标签</div> </body> </html>
|
通配符选择器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> *{ color: red; } </style> </head> <body> <div>div</div> <p>ppp</p> <h1>h1</h1> <span>span</span> </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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> p{ font-size: 30px;
font-weight: bold;
font-style: italic;
font-family: 黑体,sans-serif; } div{ font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; } </style> </head> <body> <p>这是段落文字</p> <div>第二行文字</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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> p{ font: italic 700 66px 宋体;
font-style: normal;
} </style> </head> <body> <p>标签</p> <div>标签2</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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> p{
text-indent: 2em; } </style> </head> <body> <p>《三体》是刘慈欣创作的长篇科幻小说系列,由《三体》《三体2:黑暗森林》《三体3:死神永生》组成,第一部于2006年5月起在《科幻世界》杂志上连载,第二部于2008年5月首次出版,第三部则于2010年11月出版。 作品讲述了地球人类文明和三体文明的信息交流、生死搏杀及两个文明在宇宙中的兴衰历程。其第一部经过刘宇昆翻译后获得了第73届雨果奖最佳长篇小说奖。2019年,列入“新中国70年70部长篇小说典藏”。 [62] 2020年4月,列入《教育部基础教育课程教材发展中心 中小学生阅读指导目录(2020年版)》高中段文学阅读。 2022年9月,《三体》入选2021十大年度国家IP。 </p> </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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> h1{ text-align: center; } body{ text-align: center; } </style> </head> <body> <h1>标题</h1>
<img src="./1.jpg" width="400" alt=""> </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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ text-decoration: underline; } p{ text-decoration: line-through; } h2{ text-decoration: overline; } a{ text-decoration: none; } </style> </head> <body> <div>div</div> <p>ppppp</p> <h2>h2</h2> <a href="#">超链接</a> </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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> p{
font: italic 400 66px/5 宋体; } </style> </head> <body> <p>文化大革命如火如荼地进行,天文学家叶文洁在其间历经劫难,被带到军方绝秘计划“红岸工程”。叶文洁以太阳为天线,向宇宙发出地球文明的第一声啼鸣,取得了探寻外星文明的突破性进展。三颗无规则运行的太阳主导下,四光年外的“三体文明”百余次毁灭与重生,正被逼迫不得不逃离母星,而恰在此时,他们接收到了地球发来的信息。对人性绝望的叶文洁向三体人暴露了地球的坐标,彻底改变了人类的命运。地球的基础科学出现了异常的扰动,纳米科学家汪淼进入神秘的网络游戏《三体》,开始逐步逼近这个世界的真相。汪淼参加一次玩家聚会时,接触到了地球上应对三体人到来而形成的一个秘密组织ETO。地球防卫组织中国区作战中心通过“古筝计划”,一定程度上挫败了拯救派和降临派扰乱人类科学界和其他领域思想的图谋,获悉处于困境之中的三体人为了得到一个能够稳定生存的世界决定入侵地球。
</p> </body> </html>
|
水平标签居中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 300px; height: 300px; background-color: pink;
margin: 0 auto; } </style> </head> <body> <div></div> </body> </html>
|
综合案例1 新闻网页
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"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width:800px; height:600px; margin: 0 auto; }
.center{ text-align:center; } .color1 { color:#808080;
} .color2 { color:#87ceeb; font-weight: 700; } a{ text-decoration: none; }
.suojin { text-indent: 2em; } </style> </head> <body> <div> <h1 class="center">《自然》评选改变科学的10个计算机代码项目</h1> <p class="center"> <span class="color1"> 2077年01月28日14:58</span> <span class="color2">新浪科技</span> <a href="#">收藏本文</a> </p>
<hr> <p class="suojin">2019年,事件视界望远镜团队让世界首次看到了黑洞的样子。不过,研究人员公布的这张发光环形物体的图像并不是传统的图片,而是经过计算获得的。利用位于美国、墨西哥、智利、西班牙和南极地区的射电望远镜所得到的数据,研究人员进行了数学转换,最终合成了这张标志性的图片。研究团队还发布了实现这一壮举所用的编程代码,并撰文记录这一发现,其他研究者也可以在此基础上进一步加以分析。</p> <p class="suojin">这种模式正变得越来越普遍。从天文学到动物学,在现代每一项重大科学发现的背后,都有计算机的参与。美国斯坦福大学的计算生物学家迈克尔·莱维特因“为复杂化学系统创造了多尺度模型”与另两位研究者分享了2013年诺贝尔化学奖,他指出,今天的笔记本电脑内存和时钟速度是他在1967年开始获奖工作时实验室制造的计算机的1万倍。“我们今天确实拥有相当可观的计算能力,”他说,“问题在于,我们仍然需要思考。”</p> <p class="suojin">如果没有能够解决研究问题的软件,以及知道如何编写并使用软件的研究人员,一台计算机无论再强大,也是毫无用处的。如今的科学研究从根本上已经与计算机软件联系在一起,后者已经渗透到研究工作的各个方面。近日,《自然》(Nature)杂志将目光投向了幕后,着眼于过去几十年来改变科学研究的关键计算机代码,并列出了其中10个关键的计算机项目。</p> <p class="suojin">最初的现代计算机并不容易操作。当时的编程实际上是手工将电线连接成一排排电路来实现的。后来出现了机器语言和汇编语言,允许用户用代码为计算机编程,但这两种语言都需要对计算机的架构有深入的了解,使得许多科学家难以掌握。</p> </div> </body> </html>
|
综合案例2 卡片居中
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> body{ background-color: #f5f5f5; } .pro{ width: 234px; height: 300px; background-color: #fff; margin: 0 auto; text-align: center; } img{ width:160px
} .title{ font-size: 14px; line-height: 25px; } .info{ color: #ccc; font-size: 12px; line-height: 30px; } .money { font-size: 14px; color: #ffa500; } </style> </head> <body> <div class="pro"> <img src="./img/九号平衡车.png" alt=""> <div class="title">九号平衡车</div> <div class="info">成年人的玩具</div> <div class="money">1999元</div> </div> </body> </html>
|
CSS进阶
选择器进阶
后代:空格
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div p{ color: red; } </style> </head> <body> <p>这是一个P标签</p> <div> <p>这是div的的儿子p</p> </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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style>
div>a{ color: red; } </style> </head> <body> <div> 父级 <a href="#">这是div里面的a</a> <p> <a href="#">这是div里面的p中的a</a> </p> </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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> /* p div span h1为红色 */ /* 选择器1,选择器2 */ p, div, span, h1 { color: red; } </style> </head> <body> <p>p</p> <div>div</div> <span>span</span> <h1>h1</h1>
<h2>h2</h2> </body> </html>
|
交集:.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> p.box{ color: red; } </style> </head> <body> <p class="box">这是p标签:box</p> <p>pppppp</p> <div class="box">这是div标签:box</div> </body> </html>
|
伪类hover:鼠标悬停的状态
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> a:hover { color: red; background-color: skyblue; }
div:hover { color: aqua; } </style> </head> <body> <a href="#">这是超链接</a> <div>div</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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ background-color: rgba(0, 0, 0, .5); width: 400px; height: 400px; } </style> </head> <body> <div>div</div> </body> </html>
|
图片
背景平铺
background-repeat(缩写:bgr)
取值 |
效果 |
repeat |
默认值,水平和垂直平铺 |
no-repear |
不平铺 |
repeat-x |
沿水平方向x轴平铺 |
repeat-y |
沿垂直方向y轴平铺 |
背景位置
backg-position(bgp)
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 400px; height: 400px; background-color: pink; background-image: url(./img/九号平衡车.png); background-repeat: no-repeat;
background-position: 50px 0; } </style> </head> <body> <div>文字</div> </body> </html>
|
连写
1 2 3 4 5 6 7
| <style> div{ width: 400px; height: 400px; background: pink url(./img/九号平衡车.png) no-repeat center center; } </style>
|
元素显示模式
块级元素
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 300px; height: 300px; background-color: pink;
} </style> </head> <body> <div>1111</div> <div>2222</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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> span{ width: 300px; height: 300px; background-color: pink;
} </style> </head> <body> <span>span</span> <span>span</span> </body> </html>
|
行内块元素
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> /* 行内块 一行显示多个 加宽高生效 */ /* */ img{ width: 100px; height: 100px; } </style> </head> <body> <img src="./img/九号平衡车.png" alt=""> <img src="./img/九号平衡车.png" alt=""> </body> </html>
|
元素显示模式转换
属性 |
效果 |
使用频率 |
display:block |
转 块级 |
较多 |
display:inline-blcok |
转 行内快 |
较多 |
display:inline |
转 行内 |
极少 |
扩展
标签嵌套
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body>
</body> </html>
|
CSS特性
继承性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ color: red; font-size: 30px; height: 300px; } </style> </head> <body> <div> 这是div标签里面的文字 <span>这是div里面的span</span> </div> </body> </html>
|
Tips
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div { color:red; font-size: 12px; } a{ color: red; } </style> </head> <body> <div> <a href="#" >超链接</a> <h1>一级标题</h1> </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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div { color: green; color: red; } .box { font-size: 30px; } </style> </head> <body> <div class="box">文字</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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box { color: blue; }
body{ color: red; } div{ color: green !important; } </style> </head> <body> <div class="box" id="box " style="color: pink;">测试优先级</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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style>
div #one { color: orange; } .father .son { color: skyblue; } .father p{ color: purple; } div p { color: pink; } </style> </head> <body> <div class="father"> <p class="son" id="one">标签</p> </div> </body> </html>
|
综合1
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> a{ text-decoration: none; width: 100px; height: 50px; background-color: red; display: inline-block; color: white; text-align: center; line-height: 50px; } a:hover{ background-color: orange; } </style> </head> <body> <a href="#">导航1</a> <a href="#">导航2</a> <a href="#">导航3</a> <a href="#">导航4</a> <a href="#">导航5</a> </body> </html>
|
CSS盒子模型
体验
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 300px; height: 300px; background-color: pink; border: 1px solid black; padding: 20px; margin: 50px; } </style> </head> <body> <div>内容电脑</div> <div>内容电脑</div> </body> </html>
|
内容:width和height
1 2 3 4 5 6 7 8 9 10 11
| <style> div { width: 200px; height: 200px; background-color: pink; } </style> </head> <body> <div>文字</div>
|
边框:border使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <style> div{ width: 200px; height: 200px; background-color: pink; border-left: 5px dotted #000; } </style> </head> <body> <div>内容</div>
|
实例 新浪导航
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ height: 40px; border-top: 3px solid #ff8500; border-bottom: 1px solid #edeef0;
}
.box a{ padding: 0 16px; height: 40px; display: inline-block; text-align: center; line-height: 40px; font-size: 12px; color: #4c4c4c; text-decoration: none; } .box a:hover { background-color: #edeef0; color: #ff8400; } </style> </head> <body> <div class="box"> <a href="#">新浪导航</a> <a href="#">新浪导航</a> <a href="#">新浪导航</a> <a href="#">新浪导航</a> </div> <p> <a href="#"></a> </p> </body> </html>
|
内边距:padding
写法
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 300px; height: 300px; background-color: pink; padding: 50px; padding: 10px 20px 40px 80px;
padding: 10px 40px 80px;
padding: 10px 80px; } </style> </head> <body> <div>文字</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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 240x; height: 240px; background: pink; border: 10px solid #000; padding: 20px; div{ width: 100px; height: 100px; background: pink; border: 10 solid #000; padding: 20px; box-sizing: border-box; } } </style> </head> <body> <div>文字</div> </body> </html>
|
外边距 margin
写法同内边距
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 100px; height: 100px; background-color: pink; margin: 50px; } </style> </head> <body> <div>文字</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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> *{ margin: 0; padding: 0; } </style> </head> <body> <p>ppp</p> <p>ppp</p> <h1>h1</h1> <ul> <li>lili</li> </ul> </body> </html>
|
版心居中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 10000px; height: 100px; background-color: pink; margin: 0 auto; } </style> </head> <body> <div>版心</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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> *{ margin: 0; padding: 0; box-sizing: border-box; } .news{ width: 500px; height: 400px; border: 1px solid #ccc; margin: 50px auto; padding: 42px 30px 0; }
.news h2{ border-bottom: 1px solid #ccc; font-size: 30px; line-height: 1; padding-bottom: 9px; }
ul{ list-style: none; } .news li{ height: 50px; border-bottom: 1px dashed #ccc; padding-left: 28px; line-height: 50px; } .news a{ text-decoration: none; color: #666; font-size: 18px; } </style> </head> <body> <div class="news"> <h2>最新文章/New Articles</h2> <ul> <li><a href="#">第一条</a></li> <li><a href="#">第二条</a></li> <li><a href="#">第三条</a></li> <li><a href="#">第四条</a></li> <li><a href="#">第五条</a></li> </ul> </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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div { width: 100px; height: 100px; background-color: pink ; } .one { margin-bottom: 60px; } .two { margin-top: 5opx; } </style> </head> <body> <div class="one">11</div> <div class="two">22</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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .father { width: 300px; height: 300px; background-color: pink; /* 解决方法 */ /* 1.给父级设置border-top或者padding-top */ /* padding-top: 50px; */ /* border-top: 1px solid #000; */
/* 2.给父级元素设置overflow */ /* overflow: hidden; */
/* 3.转换成行内块元素 */ /* 4.设置浮动 */ } .son { width: 100px; height: 100px; background-color: skyblue;
/* 塌陷 子级会带着父级一起移动 */ /* margin-top: 50px; */ } </style> </head> <body> <div class="father"> <div class="son">son</div> </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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> span{ padding: 100px; } </style> </head> <body>
<span>span</span> <span>span</span> </body> </html>
|
CSS浮动
结构伪类
基本用法
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style>
</style>s </head> <body> <ul> <li>这是第1个li</li> <li>这是第2个li</li> <li>这是第3个li</li> <li>这是第4个li</li> <li>这是第5个li</li> <li>这是第6个li</li> <li>这是第7个li</li> <li>这是第8个li</li> </ul> </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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> li:nth-child(2n) { background-color: pink; } </style> </head> <body> <ul> <li>这是第1个</li> <li>这是第2个</li> <li>这是第3个</li> <li>这是第4个</li> <li>这是第5个</li> <li>这是第6个</li> <li>这是第7个</li> <li>这是第8个</li> </ul> </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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .father{ width: 300px; height: 300px; background-color: pink; } .father::before{ content: "第一项"; color: aquamarine; width: 100px; height: 100px; background-color: blue; display: block; } .father::after { content: "第三项"; } </style> </head> <body> <div class="father">第二项</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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ display: inline-block; width: 100px; height: 100px; } .one{ background-color: pink; } .two { background-color: blue; } </style> </head> <body> <div class="one">1</div> <div class="two">2</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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style>
div{ width: 100px; height: 100px; } .one{ background-color: pink; float: left; } .two{ background-color: skyblue; float: left; } </style> </head> <body>
<div class="one">1</div> <div class="two">2</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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .one{ width: 100px; height: 100px; background-color: pink; float: left; margin-top: 50px; } .two{ width: 200px; height: 200px; background-color: skyblue; float: left;
margin: 0 auto; } .three{ width: 300px; height: 300px; background-color: red; } </style> </head> <body> <div class="one">1</div> <div class="two">2</div> <div class="three">3</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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .top { margin: 0 auto; width: 1000px; background-color: pink; } .bottom{ height: 100px; background-color: green; } .left { float: left; width: 200px; height: 300px; background-color: #ccc; } .right { float: right; width: 790px; height: 300px; background-color: skyblue; } </style> </head> <body> <div class="top"> <div class="left"></div> <div class="right"></div> </div> <div class="bottom"></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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .top { margin: 0 auto; width: 1000px; background-color: pink; } .bottom{ height: 100px; background-color: green; } .left { float: left; width: 200px; height: 300px; background-color: #ccc; } .right { float: right; width: 790px; height: 300px; background-color: skyblue; } .clearfix { clear: both; } </style> </head> <body> <div class="top"> <div class="left"></div> <div class="right"></div>
<div class="clearfix"></div> </div> <div class="bottom"></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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .top { margin: 0 auto; width: 1000px; background-color: pink; } .bottom{ height: 100px; background-color: green; } .left { float: left; width: 200px; height: 300px; background-color: #ccc; } .right { float: right; width: 790px; height: 300px; background-color: skyblue; }
.clearfix::after { content: '';
display: block; clear: both;
height: 0; visibility: hidden; } </style> </head> <body> <div class="top clearfix" > <div class="left"></div> <div class="right"></div>
</div> <div class="bottom"></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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .top { margin: 0 auto; width: 1000px; background-color: pink; } .bottom{ height: 100px; background-color: green; } .left { float: left; width: 200px; height: 300px; background-color: #ccc; } .right { float: right; width: 790px; height: 300px; background-color: skyblue; }
.clearfix::before, .clearfix::after{ content: ''; display: table; }
.clearfix::after{
clear: both; } </style> </head> <body> <div class="top clearfix"> <div class="left"></div> <div class="right"></div> </div> <div class="bottom"></div> </body> </html>
|
overflow
1 2 3 4 5 6 7 8 9 10 11
| .top { margin: 0 auto; width: 1000px; /* 父级设置高度 */ /* height: 300px; */ background-color: pink;
/* overflow添加 */ overflow: hidden; }
|
综合案例
小米布局
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> *{ margin: 0; padding: 0; } .top { height: 40px; background-color: #333; } .header{ width: 1226px; height: 100px; background-color: #ffc0cb; margin: 0 auto; } .content{ width: 1226px; height: 460px; background-color: green; margin: 0 auto; } .left { width: 234px; height: 460px; background-color: #ffa500; float: left; } .right{ width: 992px; height: 460px; background-color: #87ceeb; float: right; }
</style> </head> <body> <div class="top"></div> <div class="header">头部</div> <div class="content"> <div class="left">left</div> <div class="right">right</div> </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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> *{ margin: 0; padding: 0; } .box{ margin: 0 auto; width: 1226px; height: 614px; } .left{ float: left; width: 234px; height: 614px; background-color: #800080; } .right { float: right; width: 978px; height: 614px; }
ul{ list-style: none; } .right li{ float: left; margin-right: 14px; margin-bottom: 14px;
width: 234px; height: 300px; background-color:skyblue; } .right li:nth-child(4n) { margin-right: 0; } </style> </head> <body> <div class="box"> <div class="left"></div> <div class="right"> <ul> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> </ul> </div> </div> </body> </html>
|
学成在线项目
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>学成在线</title> <link rel="stylesheet" href="./css/index.css"> </head> <body>
<div class="header wrapper"> <h1> <a href="#"><img src="./images/logo.png" alt=""></a> </h1> <div class="nav"> <ul> <li><a href="#">首页</a></li> <li><a href="#">课程</a></li> <li><a href="#">职业规划</a></li> </ul> </div>
<div class="search"> <input type="text" placeholder="请输入关键词"> <button></button> </div>
<div class="user"> <img src="./images/user.png" alt=""> <span>Alax</span> </div> </div>
<div> <div class="banner"> <div class="wrapper"> <div class="left"> <ul> <li><a href="#">前端开发<span>></span></a></li> <li><a href="#">前端开发<span>></span></a></li> <li><a href="#">前端开发<span>></span></a></li> <li><a href="#">前端开发<span>></span></a></li> <li><a href="#">前端开发<span>></span></a></li> <li><a href="#">前端开发<span>></span></a></li> <li><a href="#">前端开发<span>></span></a></li> <li><a href="#">前端开发<span>></span></a></li> <li><a href="#">前端开发<span>></span></a></li> </ul> </div> <div class="right"> <h2>我的课程表</h2> <div class="content"> <dl> <dt>继续学习 程序语言设计</dt> <dd>正在学习-适用对象</dd> </dl> <dl> <dt>继续学习 程序语言设计</dt> <dd>正在学习-适用对象</dd> </dl> <dl> <dt>继续学习 程序语言设计</dt> <dd>正在学习-适用对象</dd> </dl> </div> <a href="#" class="more">全部课程</a> </div> </div> </div>
<div class="goods wrapper"> <h2>精品推荐</h2> <ul> <li><a href="#">JQuery</a></li> <li><a href="#">JQuery</a></li> <li><a href="#">JQuery</a></li> <li><a href="#">JQuery</a></li> <li><a href="#">JQuery</a></li> <li><a href="#">JQuery</a></li> </ul> <a href="#" class="xing">修改兴趣</a> </div>
<div class="box wrapper"> <div class="title"> <h2>精品推荐</h2> <a href="#">查看全部</a> </div>
<div class="content clearfix"> <ul> <li> <a href="#"> <img src="./images/course07.png" alt=""> <h3>Think PHP 5.0 博客系统实战项目演练</h3> <p><span>高级</span> • 1125人在学习</p> </a> </li> <li> <a href="#"> <img src="./images/course07.png" alt=""> <h3>Think PHP 5.0 博客系统实战项目演练</h3> <p><span>高级</span> • 1125人在学习</p> </a> </li> <li> <a href="#"> <img src="./images/course07.png" alt=""> <h3>Think PHP 5.0 博客系统实战项目演练</h3> <p><span>高级</span> • 1125人在学习</p> </a> </li> <li> <a href="#"> <img src="./images/course07.png" alt=""> <h3>Think PHP 5.0 博客系统实战项目演练</h3> <p><span>高级</span> • 1125人在学习</p> </a> </li> <li> <a href="#"> <img src="./images/course07.png" alt=""> <h3>Think PHP 5.0 博客系统实战项目演练</h3> <p><span>高级</span> • 1125人在学习</p> </a> </li> <li> <a href="#"> <img src="./images/course07.png" alt=""> <h3>Think PHP 5.0 博客系统实战项目演练</h3> <p><span>高级</span> • 1125人在学习</p> </a> </li> <li> <a href="#"> <img src="./images/course07.png" alt=""> <h3>Think PHP 5.0 博客系统实战项目演练</h3> <p><span>高级</span> • 1125人在学习</p> </a> </li> <li> <a href="#"> <img src="./images/course07.png" alt=""> <h3>Think PHP 5.0 博客系统实战项目演练</h3> <p><span>高级</span> • 1125人在学习</p> </a> </li> <li> <a href="#"> <img src="./images/course07.png" alt=""> <h3>Think PHP 5.0 博客系统实战项目演练</h3> <p><span>高级</span> • 1125人在学习</p> </a> </li> <li> <a href="#"> <img src="./images/course07.png" alt=""> <h3>Think PHP 5.0 博客系统实战项目演练</h3> <p><span>高级</span> • 1125人在学习</p> </a> </li> </ul> </div> </div>
<div class="footer"> <div class="wrapper"> <div class="left"> <img src="./images/logo.png" alt=""> <p>学成在线致力于普及中国最好的教育它与中国一流大学和机构合作提供在线课程。<br> © 2017年XTCG Inc.保留所有权利。-沪ICP备15025210号</p> <a href="#">下载APP</a> </div> <div class="right"> <dl> <dt>合作伙伴</dt> <dd><a href="#">合作机构</a></dd> <dd><a href="#">合作导师</a></dd>
</dl> <dl> <dt>合作伙伴</dt> <dd><a href="#">合作机构</a></dd> <dd><a href="#">合作导师</a></dd>
</dl> <dl> <dt>合作伙伴</dt> <dd><a href="#">合作机构</a></dd> <dd><a href="#">合作导师</a></dd>
</dl> </div> </div> </div> </div> </body> </html>
|
CSS
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
| * { margin: 0; padding: 0; box-sizing: border-box; }
li { list-style: none; } a { text-decoration: none; }
.clearfix:before,.clearfix:after { content:""; display:table; } .clearfix:after { clear:both; }
body{ background-color: #f3f5f7; }
.wrapper{ width: 1200px; margin: 0 auto; }
.header{ height: 42px;
margin: 30px auto; }
h1{ float: left; }
.nav{ float: left; margin-left: 70px; height: 42px; }
.nav li{ float: left; margin-right: 26px; }
.nav li a{ display: block; padding: 0 9px; height: 42px; line-height: 42px; font-size: 18px; color:#050505;
}
.nav li a:hover{ border-bottom: 2px solid #00a4ff;
}
.search{ float: left; margin-left: 59px; width: 412px; height: 40px; border: 1px solid #00a4ff; }
.search input{ float: left; padding-left: 20px; width: 360px; height: 38px; border: 0; }
.search input::placeholder{ font-size: 14px; color: #bfbfbf; }
.search button{ float: left; width: 50px; height: 40px; background-image: url(../images/btn.png); border: 0; }
.user{ float: right; margin-right: 35px; height: 42px; line-height: 42px; }
.user img{ vertical-align: middle; }
.banner{ height: 420px; background-color: #1c036c; }
.banner .wrapper{ height: 420px; background-image: url(../images/banner2.png); }
.banner .left{ float: left; padding: 0 20px; width: 190px; height: 420px; background-color: rgba(0, 0, 0, 0.3);
line-height: 44px; }
.banner .left span { float: right; }
.banner .left a{ font-size: 14px; color: #fff; }
.banner .left a:hover { color: #00b4ff; }
.banner .right{ float: right; margin-top: 50px; width: 228px; height: 300px; background-color: #fff; }
.banner .right h2{ height: 48px; background-color: #9bceea; text-align: center; line-height: 48px; font-size: 18px; color: #fff; }
.banner .right .content{ padding: 0 18px; }
.banner .right .content dl{ padding: 12px; border-bottom: 2px solid #e5e5e5; }
.banner .right .content dt{ font-size: 16px; color: #4e4e4e; }
.banner .right .content dd{ font-size: 14px; color: #4e4e4e; }
.banner .right .more{ display: block; margin: 4px auto 0; width: 200px; height: 40px; border: 1px solid #00a4ff; font-size: 16px; color: #00a4ff; font-weight: 700;
text-align: center; line-height: 40px; }
.goods{ margin-top: 8px; padding-left: 34px; padding-right: 26px; height: 60px; background-color: #fff; box-shadow: 0px 2px 3px 0px rgba(118, 118, 118, 0.2);
line-height: 60px; }
.goods h2{ float: left; font-size: 16px; color: #00a4ff; font-weight: 400; }
.goods ul{ float: left; margin-left: 30px; }
.goods ul li { float: left; }
.goods li a{ border-left: 1px solid #bfbfbf; padding: 0 30px; font-size: 16px; color:#050505 ; }
.goods .xing{ float: right; font-size: 14px; color: #00a4ff; }
.box{ margin-top: 35px; }
.box .title{ height: 40px; }
.box .title h2{ float: left; font-size: 20px; color: #494949; font-weight: 400; }
.box .title a{ float: right; margin-right: 30px; font-size: 12px; color: #a5a5a5; }
.box .content li{ float: left; margin-right: 15px; margin-bottom: 15px; width: 228px; height: 270px; background-color: #fff; }
.box .content li:nth-child(5n) { margin-right: 0; }
.box .content li h3{ padding: 20px; font-size: 14px; color: #050505; font-weight: 400; }
.box .content li p{ padding: 0 20px; font-size: 12px; color: #999; }
.box .content li span{ color: #ff7c2d; }
.footer{ margin-top: 40px; padding-top: 30px; height: 417px; background-color: #fff; }
.footer .left{ float: left; }
.footer .left p{ margin: 20px 0 10px; font-size: 12px; color: #666; }
.footer .left a{ display: inline-block; width: 120px; height: 36px; border: 1px solid #00a4ff; text-align: center; line-height: 36px; font-size: 16px; color: #00a4ff;
}
.footer .right{ float: right; }
.footer .right dl{ float: left; margin-right: 120px; }
|
CSS定位
属性名 position
定位方式 |
属性值 |
静态定位 |
static |
相对定位 |
relative |
绝对定位 |
absolute |
固定定位 |
fixed |
设置偏移值
方向 |
属性名 |
属性值 |
含义 |
水平 |
left |
数字+px |
距离左边的距离 |
水平 |
right |
数字+px |
距离右边的距离 |
垂直 |
top |
数字+px |
距离上边的距离 |
垂直 |
bottom |
数字+px |
距离下边的距离 |
相对定位
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ position: relative; right: 200px; bottom: 400px; left: 100px; top: 200px;
width: 200px; height: 200px; background-color: pink; } </style> </head> <body> <p>测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位</p> <p>测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位</p> <p>测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位</p> <p>测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位</p> <div class="box">box</div> <p>测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位</p> <p>测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位</p> <p>测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位</p> <p>测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位</p> <p>测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位测试定位</p>
</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
| <style> .box{
position: absolute; left: 0; top: 0;
width: 200px; height: 200px; background-color: pink; } </style>
|
子绝父相
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .father{ position: relative; width: 400px; height: 400px; background-color: pink; } .son{
width: 300px; height: 300px; background-color: skyblue; } .sun{ position: absolute;
right: 20px; bottom: 50px;
width: 200px; height: 200px; background-color: green; }
</style> </head> <body> <div class="father"> <div class="son"> <div class="sun"></div> </div> </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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ position: absolute; left: 50%;
transform: translate(-50%, -50%);
top: 50%;
width: 301px; height: 300px; background-color: pink; } </style> </head> <body> <div class="box"></div> </body> </html>
|
固定定位
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <style> .box{ position: fixed; left: 0; top: 0;
width: 200px; height: 200px; background-color: pink; } </style>
|
元素的层级关系
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 200px; height: 200px; } .one{ position: absolute; left: 20px; top: 50px; background-color: pink;
z-index: 1; } .two{ position: absolute; left: 50px; top: 100px; background-color: skyblue; }
</style> </head> <body> <div class="one">one</div> <div class="two">two</div> </body> </html>
|
CSS装饰
垂直对齐方式
vertical-aligin
属性值 |
效果 |
baseline |
默认 基线对齐 |
top |
顶部对齐 |
middle |
中部对齐 |
bottom |
底部对齐 |
五个问题的场景解决
01
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> input { height: 50px; box-sizing: border-box;
vertical-align: middle; }
</style> </head> <body> <input type="text"><input type="button" value="搜索"> </body> </html>
|
02
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> img { vertical-align: middle; } </style> </head> <body> <img src="../images/1.jpg" alt=""><input type="text"> </body> </html>
|
03
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .father { width: 400px; height: 400px; background-color: pink; }
input { vertical-align: top; }
</style> </head> <body> <div class="father"> <input type="text"> </div> </body> </html>
|
04
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .father { width: 400px; background-color: pink; }
img { display: block; }
</style> </head> <body> <div class="father"> <img src="../images/1.jpg" alt=""> </div> </body> </html>
|
05
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .father { width: 600px; height: 600px; background-color: pink; line-height: 600px; text-align: center; }
img { vertical-align: middle; } </style> </head> <body> <div class="father"> <img src="../images/1.jpg" alt=""> </div> </body> </html>
|
光标类型
cursor
属性值 |
效果 |
default |
默认值 通常是箭头 |
pointer |
小手,提示可以点击 |
text |
工字型 提示可以选择文字 |
move |
十字光标,提示可以移动 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=, initial-scale=1.0"> <title>Document</title> <style> div{ width: 200px; height: 200px; background-color: pink;
cursor: pointer; } </style> </head> <body> <div> div </div> </body> </html>
|
边框圆角
border-radius
基础
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <style> .box{ margin: 50px auto; width: 200px; height: 200px; background-color: pink;
border-radius: 10px 80px; } </style> </head> <body> <div class="box"></div> </body>
|
应用 画圆和胶囊
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .one{ width: 200px; height: 200px; background-color: pink; border-radius: 50%; }
.two{ width: 300px; height: 200px; background-color: skyblue; border-radius: 100px; } </style> </head> <body> <div class="one"></div>
<div class="two"></div> </body> </html>
|
overflow溢出部分显示效果
visible |
默认值 溢出可见 |
hidden |
溢出隐藏 |
scroll |
无论是否溢出,都显示滚动条 |
auto |
根据是否溢出,自动显示或隐藏滚动条 |
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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 300px; height: 300px; background-color: pink;
overflow: auto; } </style> </head> <body> <div class="box">我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,我是div,测试溢出效果,</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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 200px; height: 200px; } .one{ display: none; background-color: pink; } .two{ background-color: skyblue; } </style> </head> <body> <div class="one">1</div> <div class="two">2</div> </body> </html>
|
鼠标悬停 显示二维码
1 2 3 4 5 6 7 8 9 10 11 12 13
| .code{ position: absolute; left: 50%; top: 40px;
display: none;
transform: translate(-50%); } /* 鼠标悬停a 显示二维码图片 */ .nav li a:hover img{ display: block; }
|
透明属性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 400px; height: 400px; background-color: pink;
opacity: 0.5; } </style> </head> <body> <div> <img src="../img/九号平衡车.png" alt=""> </div> </body> </html>
|