web标准<—W3C(World Wide Web Consortium,万维网联盟)
组成 |
说明 |
HTML |
网页的结构(页面元素和内容) |
CSS |
网页的表现(页面元素的外观、位置等页面样式,如:颜色、大小等) |
JavaScript |
网页的行为(交互效果) |
HTML结构
1 2 3 4 5 6 7 8 9
| <html> <head> </head> <body> </body> </html>
|
快捷键
生成结构:!+enter(vs code)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> </body> </html>
|
行注释:ctrl+/(IDEA)
块注释:ctrl+shift+/
标题排版
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>【新思想引领新征程】推进长江十年禁渔 谱写长江大保护新篇章</title> </head> <body> <h1 id="title">【新思想引领新征程】推进长江十年禁渔 谱写长江大保护新篇章</h1>
<a href="https://news.cctv.com/" target="_blank">央视网</a> 2024年05月15日 20:07 </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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>【新思想引领新征程】推进长江十年禁渔 谱写长江大保护新篇章</title>
<link rel="stylesheet" href="css/news.css">
</head> <body> <h1 id="title">【新思想引领新征程】推进长江十年禁渔 谱写长江大保护新篇章</h1> <a href="https://news.cctv.com/" target="_blank">央视网</a>
<span>2024年05月15日 20:07</span> </body> </html>
|
方式三:news.css

css注释:/* */
1 2 3 4 5 6 7 8 9 10
| span{ color: #808080; }
|
css选择器:选取需要设置样式的元素(标签)的

优先级:ID>类>元素
元素选择器
1 2 3 4 5 6 7 8
| <style>
span{ color: gray; } </style> ... <span>2024年05月15日 20:07</span>
|
类选择器
1 2 3 4 5 6 7 8
| <style>
.cls{ color: gray; } </style> ... <span class="cls">2024年05月15日 20:07</span>
|
ID选择器
1 2 3 4 5 6 7 8
| <style>
#time{ color: gray; } </style> ... <span class="cls" id="time">2024年05月15日 20:07</span>
|
去除超链接的下划线
1 2 3 4 5 6 7
| <style> a{ text-decoration: none; } </style> ... <a href="https://news.cctv.com/" target="_blank">央视网</a>
|
正文排版
视频音频标签
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <br>
<video src="video/news.mp4" width="500" height="300" controls="controls"></video>
<audio src="audio/news.mp3" controls="controls"></audio>
|
段落标签
图片标签
1 2 3 4 5 6 7 8 9 10 11 12 13
|
<img src="img/1.gif">
|
正文样式
加粗标签b/strong
1 2 3 4
| <p> <b>央视网消息</b> </p>
|
设置行高
1 2 3 4 5 6
| <style> p{ line-height: 2; } </style>
|
首行缩进(空格 )
1
| <strong> 央视网消息</strong>
|
1 2 3 4 5
| <style> p{ text-indent: 2em; } </style>
|

页面布局
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <style> #content-container{ width: 800px; margin-left: auto; margin-right: auto; } </style>
<body> <div id="content-container"> <h1>【新思想引领新征程】推进长江十年禁渔 谱写长江大保护新篇章</h1> <a href="https://news.cctv.com/" target="_blank">央视网</a> <span>2024年05月15日 20:07</span> <p> </p> ... </div> </body>
|
盒子模型
盒子:页面中所有的元素(标签),都可以看做是一个盒子,由盒子将页面中的元素包含在一个矩形区域内,通过盒子的视角更方便的进行页面布局
盒子模型组成:内容区域(content)、内边距区域(padding)、边框区域(border)、外边距区域(margin)
布局标签 |
在网页开发中,常使用 <div> 和 <span> 两个无语义的布局标签进行结构排版和样式控制。 |
<div> 标签特点 |
<span> 标签特点 |
默认独占一行(块级元素) |
默认不换行,可在一行中显示多个(行内元素) |
宽度默认占满父容器,高度由内容撑开 |
宽高均由内容撑开 |
可设置宽高(width 、height ) |
不建议设置宽高,设置无效或不生效 |