博客列表 >字体单位尺寸、可视窗口大小、表格常用样式、移动端自适应、PC端自适用

字体单位尺寸、可视窗口大小、表格常用样式、移动端自适应、PC端自适用

P粉314265155
P粉314265155原创
2022年07月10日 17:12:10633浏览

字体大小

  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>CSS常用单位</title>
  8. <style>
  9. .em{
  10. font-size: 2em;
  11. color: aqua;
  12. }
  13. .px{
  14. font-size: 15px;
  15. color: blue ;
  16. }
  17. .rem{
  18. font-size: 2rem;
  19. color: rebeccapurple;
  20. }
  21. .baifen{
  22. background-color: aqua;
  23. font-size: 6em;
  24. }
  25. .baifen>.bai {
  26. font-size: 50%;
  27. }
  28. /* 根元素就是 html = :root */
  29. :root{
  30. font-size: 8px;
  31. font-size: 16px;
  32. }
  33. .rot {
  34. background-color: blue;
  35. font-size: 2rem;
  36. }
  37. body{
  38. width: 100vw;
  39. /* 如果高度不写,高度就是很宽度成比例变化 */
  40. height: 100vh;
  41. }
  42. .box{
  43. width: 50vh;
  44. height: 50vh;
  45. background-color: brown;
  46. }![](https://img.php.cn/upload/image/568/864/168/1657431142259767.jpg)
  47. </style>
  48. </head>
  49. <body>
  50. <!-- 1em =1rem=16px 浏览器默认16px 像素是 默认矩形的框 1英寸=96px 1英寸约等于25.4毫米 1mm=(10/43)px≈0.2325px 43mm≈10px
  51. 1 厘米=0.3937 英寸 1 英寸=2.54 厘米 72像素/英寸=28.346像素/厘米 300像素/英寸=118.11像素/厘米
  52. -->
  53. <p class="em">我是em单位尺寸 绝对尺寸单位</p>
  54. <p class="px">我是px单位尺寸 绝对尺寸单位</p>
  55. <p class="rem">我是rem单位尺寸</p>
  56. <div class="baifen">
  57. <p>我是父级尺寸</p>
  58. <p class="bai">我是百分比% 我是相对单位,参照父级单位</p>
  59. </div>
  60. <div class="rot">
  61. 我是根尺寸
  62. </div>
  63. <div class="box">
  64. 我是可视化窗口盒子我是相对单位:vw 高度: vh
  65. </div>
  66. </body>
  67. </html>

表格常用样式

  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. <style>
  9. /* 1、添加表格线 border */
  10. table th,
  11. table tr,
  12. table td{
  13. border: 2px solid rebeccapurple;
  14. }
  15. /* 2、折叠表格线 border-collapse: collapse;*/
  16. table{
  17. border-collapse: collapse;
  18. }
  19. /* 3、表格进行布局设置 */
  20. table{
  21. width: 80%;
  22. /* table 块级元素在父级中的居中 有margin-left margin-right */
  23. margin: auto;
  24. /* 表格内容文字居中 */
  25. text-align: center;
  26. }
  27. table caption {
  28. font-size: 1.2em;
  29. /* 增加外边距,远离标题 */
  30. margin-bottom: 0.6em;
  31. }
  32. table thead {
  33. background-color: lightcyan;
  34. }
  35. /* 给上午添加背景 常规方式 .属性名 或者 table tboday .shangwu */
  36. /* .shangwu{
  37. background-color: blue;
  38. } */
  39. /* 简化写法 ,用伪类写 ,可以进行删选、个性化书写
  40. table tbody tr:first-of-type td:first-of-type
  41. 注意空格
  42. table tbody:not(tbody:nth-of-type(2)) tr:first-of-type td:first-of-type {
  43. */
  44. /* table tbody:not(tbody:nth-of-type(2)) tr:first-of-type td:first-of-type{ */
  45. table tbody:not(tbody:nth-of-type(2)) tr:first-of-type td:first-of-type {
  46. background-color: firebrick;
  47. }
  48. </style>
  49. </head>
  50. <body>
  51. <!-- table>caption+(thead>tr>th)+(tbody>tr>td) -->
  52. <table>
  53. <caption>我是课程表</caption>
  54. <thead>
  55. <tr>
  56. <th>时间</th>
  57. <th>星期一</th>
  58. <th>星期二</th>
  59. <th>星期三</th>
  60. <th>星期四</th>
  61. <th>星期五</th>
  62. </tr>
  63. </thead>
  64. <!-- 我是第一个tbody -->
  65. <tbody>
  66. <tr>
  67. <td rowspan="2" class="shangwu">上午</td>
  68. <td>语文</td>
  69. <td>数学</td>
  70. <td>英语</td>
  71. <td>物理</td>
  72. <td>化学</td>
  73. </tr>
  74. <tr>
  75. <td>语文</td>
  76. <td>数学</td>
  77. <td>英语</td>
  78. <td>物理</td>
  79. <td>化学</td>
  80. </tr>
  81. </tbody>
  82. <!-- 我是第二tbody -->
  83. <tbody>
  84. <tr>
  85. <td colspan="6">中午</td>
  86. </tr>
  87. </tbody>
  88. <!-- 我是第三tbody -->
  89. <tbody>
  90. <tr>
  91. <td rowspan="2">下午</td>
  92. <td>语文</td>
  93. <td>数学</td>
  94. <td>英语</td>
  95. <td>物理</td>
  96. <td>化学</td>
  97. </tr>
  98. <tr>
  99. <td>语文</td>
  100. <td>数学</td>
  101. <td>英语</td>
  102. <td>物理</td>
  103. <td>化学</td>
  104. </tr>
  105. </tbody>
  106. </table>
  107. </body>
  108. </html>

字体图标

  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="./iconfont.css"> -->
  9. <link rel="stylesheet" href="../0708/css/zuoye3.css">
  10. <style>
  11. /* .myicon1{
  12. font-size: 300px;
  13. color: red;
  14. box-shadow: 2px 2px 2px #888;
  15. border: 1px solid #888;
  16. background-color: green;
  17. } */
  18. /* 可以使用 .myicon进行对图标大小的定义,定义属性参考 文字 注意 里面要有myicon属性 */
  19. </style>
  20. </head>
  21. <body>
  22. <!-- 注意 icon-shouye 是字体图标的名称 另外可从下载的 demo_index.html 打开获取操作指导 -->
  23. <span id="shouye" class="iconfont icon-shouye myicon1"></span>
  24. <br>
  25. 首页
  26. </body>
  27. </html>
  1. 注意:引入的css 后面要跟分号,且 在自定义样式的前面,否则不显示
  2. @import '../font_icon/iconfont.css';
  3. /* 2. 自定义图标样式 */
  4. .myicon1{
  5. font-size: 300px;
  6. color: red;
  7. box-shadow: 2px 2px 2px #888;
  8. border: 1px solid #888;
  9. background-color: green;
  10. }

响应式/移动端布局基础:媒体查询

1、按钮随着 根属性变化

  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. <style>
  9. :root{
  10. /* 设置根字号的尺寸 */
  11. font-size: 20px;
  12. /* 等于1.6rem */
  13. }
  14. button{
  15. background-color: blue;
  16. color: aqua;
  17. border: none;
  18. /* outline: 1.875rem; */
  19. /* border: none; 没有边框,背景 */
  20. outline: none;
  21. }
  22. /* :hover 鼠标悬停的基本样式 */
  23. .bin:hover{
  24. /* cursor: pointer; 鼠标变成一个小手 */
  25. cursor: pointer;
  26. /* opacity 选择后的背景透明度变化 80% */
  27. opacity: 0.8;
  28. /* 缓冲过度 注意后面跟着秒数*/
  29. transition: 0.5s;
  30. }
  31. .small{
  32. /* 小按钮 可以用字体大小调节按钮大小.,按钮默认尺寸是 13.333333 */
  33. font-size: 1.5rem;
  34. /* px是绝对值不能用在媒体查询中 往后不要用了 ,在跟字体设置,用rem表示尺寸
  35. ,修改 root 根字体后,这些按键就会动态改变 */
  36. }
  37. .middle{
  38. font-size: 0.6rem;
  39. }
  40. .large{
  41. font-size: 2.5rem;
  42. }
  43. </style>
  44. </head>
  45. <body>
  46. <!-- 媒体、打印机、PC端屏幕显示长宽高等 -->
  47. <!-- 布局前提条件:假设布局固定宽度,高度随着内容自动增长 -->
  48. <!-- 用户使用的布局也是这样的,宽度固定,高度随内容增长
  49. 不会在无限空间进行操作,因为无限空间不能布局
  50. -->
  51. <button class="bin small">提交</button>
  52. <button class="bin middle">重置</button>
  53. <button class="bin large">返回上一页</button>
  54. </body>
  55. </html>

2、移动端按钮随着 屏幕大小变化属性变化

  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. <style>
  9. /* html { */
  10. /* 设置根字号的尺寸 */
  11. /* font-size: 20px; */
  12. /* 等于1.6rem */
  13. /* } */
  14. html {
  15. /* 根字号 */
  16. /* 为了计算方便: 把根字号设置为 10px */
  17. font-size: 10px;
  18. /* 10px = 1rem; */
  19. }
  20. /* button{
  21. background-color: blue;
  22. color: aqua;
  23. border: none; */
  24. /* outline: 1.875rem; */
  25. /* border: none; 没有边框,背景 */
  26. /* outline: none;
  27. } */
  28. /* :hover 鼠标悬停的基本样式 */
  29. /* .btn:hover{ */
  30. /* cursor: pointer; 鼠标变成一个小手 */
  31. /* cursor: pointer; */
  32. /* opacity 选择后的背景透明度变化 80% */
  33. /* opacity: 0.8; */
  34. /* 缓冲过度 注意后面跟着秒数*/
  35. /* transition: 0.5s; */
  36. /* }
  37. */
  38. .btn {
  39. background-color: seagreen;
  40. color: white;
  41. border: none;
  42. outline: none;
  43. }
  44. /* .small{ */
  45. /* 小按钮 可以用字体大小调节按钮大小.,按钮默认尺寸是 13.333333 */
  46. /* font-size: 1.5rem; */
  47. /* px是绝对值不能用在媒体查询中 往后不要用了 ,在跟字体设置,用rem表示尺寸
  48. ,修改 root 根字体后,这些按键就会动态改变 */
  49. /* } */
  50. /* .middle{ */
  51. /* font-size: 0.6rem; */
  52. /* } */
  53. /* .large{
  54. font-size: 2.5rem;
  55. } */
  56. .small {
  57. /* 小按钮: 12px */
  58. /* font-size: 12px; */
  59. /* px: 绝对值,不能用在媒体查询中 */
  60. font-size: 1.2rem;
  61. }
  62. .middle {
  63. /* 中等按钮: 16px; */
  64. /* font-size: 16px; */
  65. font-size: 1.6rem;
  66. }
  67. .large {
  68. /* 大按钮: 20px */
  69. /* font-size: 20px; */
  70. font-size: 2rem;
  71. }
  72. /* 移动优先:一定要从小屏幕开始写 ,安卓的乱七八遭尺寸都有,苹果的比较同意 */
  73. /* 注意:@media是引入的属性,max-width是最大尺寸,是大于
  74. min-width是最小的尺寸是不包含的,小于
  75. 随着改变屏幕的尺寸/手持机的类型,按键大小会变化的 */
  76. /* 375px < width < 414px 注意中间用and连接 */
  77. @media (max-width: 374px) {
  78. html {
  79. font-size: 12px;
  80. }
  81. }
  82. /* 375px < width < 414px */
  83. @media (min-width: 375px) and (max-width: 413px) {
  84. html {
  85. font-size: 14px;
  86. }
  87. }
  88. /* > 414px */
  89. @media (min-width: 414px) {
  90. html {
  91. font-size: 16px;
  92. }
  93. }
  94. @media (min-width: 600px) {
  95. html {
  96. font-size: 18px;
  97. }
  98. }
  99. </style>
  100. </head>
  101. <body>
  102. <!-- 媒体、打印机、PC端屏幕显示长宽高等 -->
  103. <!-- 布局前提条件:假设布局固定宽度,高度随着内容自动增长 -->
  104. <!-- 用户使用的布局也是这样的,宽度固定,高度随内容增长
  105. 不会在无限空间进行操作,因为无限空间不能布局
  106. -->
  107. <button class="btn small">提交</button>
  108. <button class="btn middle">重置</button>
  109. <button class="btn large">返回上一页</button>
  110. </body>
  111. </html>

2、PC端端按钮随着 屏幕大小变化属性变化

```
/ 上面 style 代码增加一下部分。PC端 设置 600 <width< 1200px /
@media (min-width: 600px) and (max-width: 1200px) {
html {

  1. background-color: hotpink;
  2. }
  3. }

``


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议