欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

0701作业

程序员文章站 2022-06-05 17:42:50
...

字体图标、布局原理、盒模型

1.字体图标的用法实例

字体图标使用阿里图标[https://www.iconfont.cn/]

登录后下载所需图标文件,将font_icon文件夹中的iconfont.css文件引入文档中即可使用。

  • 直接引入文档中
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>字体图标</title>
  8. <link rel="stylesheet" href="./font_icon/iconfont.css">
  9. <style>
  10. .icon-kefu{
  11. font-size: 2em;
  12. color: skyblue;
  13. }
  14. .icon-gouwuche{
  15. font-size: 3em ;
  16. color: tomato;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <span class="iconfont icon-kefu"></span>
  22. <span class="iconfont icon-shezhi"></span>
  23. <span class="iconfont icon-gouwuche"></span>
  24. </body>
  25. </html>
  • 通过引入css文件来访问该图标(更推荐这种方式 ,在主文档中会更简洁,并且在后期的维护中也更方便的调整字体图标的样式)

html文件:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>字体图标,引用css样式表</title>
  8. <link rel="stylesheet" href="./style1.css">
  9. </head>
  10. <body>
  11. <span class="iconfont icon-kefu"></span>
  12. <span class="iconfont icon-shezhi"></span>
  13. <span class="iconfont icon-gouwuche"></span>
  14. </body>
  15. </html>

css文件:

  1. @import url("./font_icon/iconfont.css");
  2. /* 以下是用户自定义的字体图标样式 */
  3. .icon-kefu{
  4. font-size: 2em;
  5. color: skyblue;
  6. }
  7. .icon-gouwuche{
  8. font-size: 3em ;
  9. color: tomato;
  10. }

2.布局的原则与元素的默认排列方式与元素类型

  • 布局的原则与元素的默认排列方式

布局的前提 宽度受限,高度不受限

排列方式有两种 水平布局和垂直布局

默认的内联元素布局是按照html文档的元素顺序从左向右依次排列(文档流),当前行没有空间之后,自动将元素转入下一行

块元素独占一行

  • 元素类型:

内联元素:display:inline
块元素:display:block

3.盒模型的常用属性

  1. width
  2. height
  3. border
  4. padding
  5. margin
  6. box-sizing: 改变了盒子大小的计算方式

演示代码:

  1. <div class="box">Hello World!</div>
  2. <div class="box">Hello World!</div>
  3. <style>
  4. .box {
  5. width: 150px;
  6. height: 150px ;
  7. border: 5px dashed red;
  8. background-color: violet;
  9. background-clip: content-box;
  10. padding: 10px;
  11. margin: 15px;
  12. }
  13. .box{
  14. /* border-box : width / height = padding + border + width/height */
  15. box-sizing: border-box;
  16. /* border-box : width / height = width/height */
  17. /* box-sizing: content-box; */
  18. }
  19. /* 实现所有元素样式的初始化 */
  20. *{
  21. padding: 0;
  22. margin: 0;
  23. box-sizing: border-box;
  24. }
  25. </style>

box-sizing属性图示说明

border-box : width / height = padding + border + width/height */
box-sizing: border-box;
0701作业

默认计算:
border-box : width / height = width/height
box-sizing: content-box;
0701作业