Web前端 第五周
四、拓展HTML
1.strong与b、em与i
表现形态:都是文本加粗和文本斜体
<body>
<strong>文本1</strong>
<b>文本2</b>
<em>文本3</em>
<i>文本4</i>
</body>
区别:strong和em是具备语义化的,而b和i是不具备语义化的
2.引用标签
- blockquote:引用大段的段落解释
<body>
<p>
<abbr title="World Health Organization">WHO</abbr>成立于1948年。
</p>
</body>
- q :引用小段的短语解释
- abbr :缩写或首字母缩略词
- address :引用文档地址信息
- cite :引用著作的标题
3.iframe嵌套页面
iframe元素会创建包含另一个文档的内联框架(即行内框架)
可以引入其他的html到当前html中显示
- 主要是利用iframe的属性进行样式的调节
<body>
<iframe src="https://www.taobao.com" frameborder="0" scrolling="no" width="400" height="400"></iframe>
</body>
<!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>
iframe{width: 100%;height: 700px;}
</style>
</head>
<body>
<iframe src="https://www.taobao.com" frameborder="0" scrolling="no"></iframe>
</body>
</html>
- 应用场景:数据传输、共享代码、局部刷新、第三方介入等。
4.br与wbr
- br:换行
- wbr:软换行
普通:
<p>
ghjk kjiu ghjk jkui ghjk jkui ghjk kjiu ghjk jkui ghjk jkui
</p>
br:
<p>
ghjk kjiu ghjk jkui ghjk jkui <br> ghjk kjiu ghjk jkui ghjk jkui
</p>
5.pre与code
针对网页中的代码显示效果。
<!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>
</html>
6.map与area
给特殊图形添加链接,area能添加的热区的形状:矩形、圆形、多边形。
7.embed与object
给flash和一些插件进行渲染操作的标签。
<body>
<embed src="./img/flash.swf" type="">
</body>
<body>
<object>
<param name="movie" value="./img/flash.swf">
</object>
</body>
注:object元素需要配合param元素一起完成
8.audio与video
引入音频与视频的标签,属于H5的功能。
9.文字注释与文字方向
- 文字注释:ruby、rt这样一个组合
<body>
<ruby>
寒<rt>hán</rt>冬
</ruby>
</body>
- bdo标签可覆盖默认的文本方向
<body>
<ruby>
寒<rt>hán</rt>冬
</ruby>
<p>
<bdo dir="ltr">高数</bdo>不定积分有理函数
</p>
</body>
<body>
<ruby>
寒<rt>hán</rt>冬
</ruby>
<p>
<bdo dir="rtl">高数</bdo>不定积分有理函数
</p>
</body>
10.扩展link标签
添加网址标题栏的小图标:
<link rel="icon" type="/image/x-icon" href="http://www.mobiletrain.org/favicon.ico">
<!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="icon" type="/image/x-icon" href="http://www.mobiletrain.org/favicon.ico">
</head>
<body>
</body>
</html>
DNS预解析:
11.扩展meta标签
mata添加一些辅助信息。
12.HTML5新语义化标签
- header:页眉
- footer:页脚
- main:主体
- hgroup:标题组合
- nav:导航
注:header、main、footer在一个网页中只能出现一次
- article:独立的内容
- aside:辅助信息的内容
- section:区域
- figure:描述图像或视频
- figcaptain:描述图像或视频的标题部分
- datalist : 选项列表
- details / summary : 文档细节/文档标题
- progress / meter : 定义进度条/定义度量范围
- time :定义日期或时间
- mark : 带有记号的文本
<!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>
<header>
<hgroup>
<h1>主标题</h1>
<h2>副标题</h2>
</hgroup>
<nav>
<ul>
<li>首页</li>
<li>论坛</li>
<li>关于</li>
</ul>
</nav>
</header>
<main>
<article>
<section>
<input type="text" list="elems">
<details name="elems">
<option value="a"></option>
<option value="ab"></option>
<option value="apple"></option>
<option value="abandon"></option>
<option value="aside"></option>
<option value="awww"></option>
</details>
<details open>
<summary>HTML</summary>
<p>超文本标记语言</p>
</details>
<progress min="0" max="10" value="5"></progress>
<meter min="10" max="100" value="80" low="10" high="60"></meter>
<p>
今天是<time title="2-14">情人节</time>,街上人很多
</p>
<p>
今天是<mark>情人节</mark>,街上人很多
</p>
</section>
<section>
<ul>
<li>
<figure>
<img src="./img/youku.jpg" alt="">
<figcaption>
点燃我,温暖你
<br>
欢喜冤家互怼生情
</figcaption>
</figure>
</li>
</ul>
</section>
<section>
<ul>
<li>
<figure>
<img src="./img/youku.jpg" alt="">
<figcaption>
点燃我,温暖你
<br>
欢喜冤家互怼生情
</figcaption>
</figure>
</li>
</ul>
</section>
<section>
<ul>
<li>
<figure>
<img src="./img/youku.jpg" alt="">
<figcaption>
点燃我,温暖你
<br>
欢喜冤家互怼生情
</figcaption>
</figure>
</li>
</ul>
</section>
</article>
<aside></aside>
</main>
<footer></footer>
</body>
</html>
五、弹性布局
1.flex弹性布局
- flex-direction
默认:
<!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;border:1px black solid;margin:20px auto;display: flex;}
#box div{width: 50px;height: 50px;color: white;line-height: 50px;text-align: center;background: darkcyan;}
</style>
</head>
<body>
<div id="box">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</body>
</html>
row-reverse:
#box{width: 300px;height: 300px;border:1px black solid;margin:20px auto;display: flex;flex-direction: row-reverse;}
colum:
colum-revers:
- flex-wrap:用来控制子项整体单行显示还是换行显示
默认:
<!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>
#box2{width: 300px;height: 300px;border:1px black solid;margin:20px auto;display: flex;}
#box2 div{width: 50px;height: 50px;color: white;line-height: 50px;text-align: center;background: darkcyan;}
</style>
</head>
<body>
<div id="box2">
<div>1</div>
<div>2</div>
<div>3</div>
<div>1</div>
<div>2</div>
<div>3</div>
<div>1</div>
<div>2</div>
</div>
</body>
</html>
wrap:
#box2{width: 300px;height: 300px;border:1px black solid;margin:20px auto;display: flex;flex-wrap: wrap;}
wrap-reverse:
#box2{width: 300px;height: 300px;border:1px black solid;margin:20px auto;display: flex;flex-wrap: wrap-reverse;}
- flex-flow:flex布局的flow流动特性。第一个值表示换行,第二个值表示空格,中间用隔开。
#box2{width: 300px;height: 300px;border:1px black solid;margin:20px auto;display: flex;flex-flow: column;}
wrap:
#box2{width: 300px;height: 300px;border:1px black solid;margin:20px auto;display: flex;flex-flow: column wrap;}
- justfity-conten:决定了主轴方向上子项的对齐和分布方式。
默认:
#box3{width: 300px;height: 300px;border:1px black solid;margin:20px auto;display: flex;}
flex-end:
#box3{width: 300px;height: 300px;border:1px black solid;margin:20px auto;display: flex;justify-content: flex-end;}
center:
space-around:
space-between:
space-evenly:
- align-items:
<style>
#box4{width: 300px;height: 300px;border:1px black solid;margin:20px auto;display: flex;}
#box4 div{width: 50px;height: 50px;background: darkcyan;}
</style>
flex-star:
<style>
#box4{width: 300px;height: 300px;border:1px black solid;margin:20px auto;display: flex;justify-content: space-evenly;align-items: flex-start;}
#box4 div{width: 50px;background: darkcyan;}
</style>
center:
flex-end:
- align-content
2.作用在flex子项上的CSS属性
flex-grow:
<style>
#box{width: 300px;height: 300px;border:1px black solid;margin:20px auto;display: flex;}
#box div{width: 50px;height: 50px;color: white;line-height: 50px;text-align: center;background: darkcyan;}
#box div:nth-child(2){background: yellow;color: black;flex-grow: 1;}
</style>
flex-shrink:
#box2 div:nth-child(2){background: yellow;color: black;flex-shrink: 0;}
flex-basis:
#box2 div:nth-child(2){background: yellow;color: black;flex-basis: 100px;}
flex:
#box2 div:nth-child(2){background: yellow;color: black;flex:0 1 auto;}
align-self:
3.Flex案例
- 骰子的点数
<!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>
#box1{width: 100px;height: 100px;border:1px black solid;border-radius: 5px;display: flex;justify-content: center;align-items:center;}
#box1 div{width: 30%;height: 30%;background: black;border-radius: 50%;}
#box2{width: 100px;height: 100px;border:1px black solid;border-radius: 5px;display: flex;justify-content:space-between;}
#box2 div{width: 30%;height: 30%;background: black;border-radius: 50%;}
#box2 div:last-child{align-self: flex-end;}
#box3{width: 100px;height: 100px;border:1px black solid;border-radius: 5px;display: flex;justify-content:space-between;align-items: center;}
#box3 div{width: 30%;height: 30%;background: black;border-radius: 50%;}
#box3 div:first-child{align-self: flex-start;}
#box3 div:last-child{align-self: flex-end;}
#box4{width: 100px;height: 100px;border:1px black solid;border-radius: 5px;display: flex;flex-wrap: wrap;}
#box4 div{width: 100%;display: flex;justify-content: space-between;}
#box4 div:last-child{align-items: flex-end;}
#box4 i{display: block;width: 30%;height: 60%;background: black;border-radius: 50%;}
#box5{width: 100px;height: 100px;border:1px black solid;border-radius: 5px;display: flex;flex-wrap: wrap;}
#box5 div{width: 100%;display: flex;justify-content: center;align-items: center;}
#box5 div:first-child{align-items: flex-start;justify-content: space-between;}
#box5 div:last-child{align-items: flex-end;justify-content: space-between;}
#box5 i{display: block;width: 30%;height: 90%;background: black;border-radius: 50%;}
#box6{width: 100px;height: 100px;border:1px black solid;border-radius: 5px;display: flex;flex-wrap: wrap;}
#box6 div{width: 100%;display: flex;justify-content: space-between;}
#box6 div:first-child{align-items: flex-start;}
#box6 div:last-child{align-items: flex-end;}
#box6 i{display: block;width: 30%;height: 90%;background: black;border-radius: 50%;}
</style>
</head>
<body>
<div id="box1">
<div></div>
</div>
<div id="box2">
<div></div>
<div></div>
</div>
<div id="box3">
<div></div>
<div></div>
<div></div>
</div>
<div id="box4">
<div>
<i></i>
<i></i>
</div>
<div>
<i></i>
<i></i>
</div>
</div>
<div id="box5">
<div>
<i></i>
<i></i>
</div>
<div>
<i></i>
</div>
<div>
<i></i>
<i></i>
</div>
</div>
<div id="box6">
<div>
<i></i>
<i></i>
</div>
<div>
<i></i>
<i></i>
</div>
<div>
<i></i>
<i></i>
</div>
</div>
</body>
</html>
- 两列固定,一列自适应
<!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>
*main{margin: 0;padding: 0;}
#main{display: flex;}
#left{width: 200px;height: 200px;background: khaki;}
#center{flex: 1;height: 300px;background: cornflowerblue;}
#right{width: 150px;height: 200px;background: darkolivegreen;}
</style>
</head>
<body>
<div id="main">
<div id="left"></div>
<div id="center"></div>
<div id="right"></div>
</div>
</body>
</html>
- 百度弹性导航
4.Grid网格布局
二维布局方法,纵横两个方向总是同时存在
<!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: 500px;height: 500px;border: 1px gray dotted;display: grid;
grid-template-rows: 100px auto 25%;
grid-template-columns: 100px 100px 200px 100px;
}
</style>
</head>
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
</div>
</body>
</html>
- grid-template-colum和grid-template-rows
对网格进行横纵划分,形成二维布局。单位可以是像素,百分比,自适应以及fr单位(网格剩余空间比例单位)
注:如果需要添加多个横纵网格时,可以利用repeat()语法进行简化操作。
<style>
.box{width: 300px;height: 300px;border: 1px gray dotted;display: grid;
grid-template-rows:repeat(3,1fr);
grid-template-columns:repeat(3,1fr);
}
</style>
- grid-template-areas和grid-template
grid-template是grid-template-rows、grid-template-columns和grid-template-areas属性的缩写。
<!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;border: 1px gray dotted;display: grid;
grid-template-rows:repeat(3,1fr);
grid-template-columns:repeat(3,1fr);
}
.box div{background: palevioletred;border: 1px black solid;}
.box2{width: 300px;height: 300px;border: 1px gray dotted;display: grid;
grid-template-rows:repeat(3,1fr);
grid-template-columns:repeat(3,1fr);
grid-template-areas:
"a1 a1 a1"
"a2 a2 a3"
"a2 a2 a3";
}
.box2 div{background: palevioletred;border: 1px black solid;}
.box2 div:nth-child(1){grid-area: a1;}
.box2 div:nth-child(2){grid-area: a2;}
.box2 div:nth-child(3){grid-area: a3;}
</style>
</head>
<body>
<div class="box2">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</body>
</html>
- grid-column-gap和grid-row-gap
定义网格中网格间隙的尺寸
.box2{width: 300px;height: 300px;border: 1px gray dotted;display: grid;
grid-template:
"a1 a1 a1" 1fr
"a2 a2 a3" 1fr
"a2 a2 a3" 1fr
/1fr 1fr 1fr;
grid-column-gap: 10px;
grid-row-gap:20px;
}
CSS grid-gap属性是grid-column-gap和grid-row-gap属性的缩写
- justity-items和align-items
注:place-items可以让justity-items和align-items属性写在单个声明中
.box3{width: 300px;height: 300px;border: 1px gray dotted;display: grid;
grid-template-rows:repeat(3,1fr);
grid-template-columns:repeat(3,1fr);
justify-items: end;
align-items: end;
}
.box3 div{background: palevioletred;border: 1px black solid;}
- justity-content和align-content
5.作用在grid子项上的CSS属性
.box div{background: palevioletred;border: 1px black solid;
grid-area: 3/2/4/4; /*第一个值是水平的起始位置,第二个值是垂直的起始位置,第三个值是水平的结束位置,第四个值是垂直的结束位置/
}
<!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: 280px;height: 352px;margin: 20px auto;display: grid;
grid-template-columns: repeat(3,1fr);
grid-template-rows: repeat(4,1fr);
grid-template-areas:
"a1 a2 a2"
"a3 a2 a2"
"a4 a4 a5"
"a6 a7 a7";
grid-gap:6px 6px;
}
.box div{background: red;}
.box div:nth-child(1){grid-area: a1;}
.box div:nth-child(2){grid-area: a2;}
.box div:nth-child(3){grid-area: a3;}
.box div:nth-child(4){grid-area: a4;}
.box div:nth-child(5){grid-area: a5;}
.box div:nth-child(6){grid-area: a6;}
.box div:nth-child(7){grid-area: a7;}
</style>
</head>
<body>
<div class="box">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
</html>