1.响应式布局

@media响应式界面能够适应不同的设备

媒体功能说明
min-width定义输出设备中的页面最小可见区域宽度
max-width定义输出设备中的页面最大可见区域宽度
  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>响应式布局: 媒体查询</title>
  8. </head>
  9. <body>
  10. <ui>
  11. <li class="box box_first">盒子1</li>
  12. <li class="box box_second">盒子2</li>
  13. <li class="box box_three">盒子3</li>
  14. </ui>
  15. </body>
  16. <style>
  17. html {
  18. font-size: 10px;
  19. }
  20. .box {
  21. background-color: #ffc70e;
  22. color: rgb(255, 255, 255);
  23. border: none;
  24. outline: none;
  25. margin-bottom: 1rem;
  26. }
  27. .box:hover {
  28. cursor: pointer;
  29. opacity: 0.8;
  30. transition: 0.3s;
  31. padding: 0.4rem 0.8rem;
  32. }
  33. .box.box_first {
  34. font-size: 1.5rem;
  35. width: 10rem;
  36. }
  37. .box.box_second {
  38. font-size: 1.5rem;
  39. width: 12rem;
  40. }
  41. .box.box_three {
  42. font-size: 1.5rem;
  43. width: 14rem;
  44. }
  45. /* 移动优先: 从最小的屏幕开始进行适配 */
  46. /* < 346px */
  47. @media (max-width: 346px) {
  48. html {
  49. font-size: 12px;
  50. }
  51. }
  52. /* 347px - 462px */
  53. @media (min-width: 347px) and (max-width: 462px) {
  54. html {
  55. font-size: 14px;
  56. }
  57. }
  58. /* 463px - 959px */
  59. @media (min-width: 463px) and (max-width: 959px) {
  60. html {
  61. font-size: 16px;
  62. }
  63. }
  64. /* >960px */
  65. @media (min-width: 960px) {
  66. html {
  67. font-size: 20px;
  68. }
  69. }
  70. }
  71. </style>
  72. </html>

演示效果:

2.固定定位案例

position属性指定一个元素(静态的,相对的,绝对或固定)的定位方法类型;
属性值说明描述
position: static静态定位默认值。没有定位,元素出现在正常的流中
position: absolute,绝对定位元素的位置相对于最近的已定位父元素,如果元素没有已定位的父元素,那么它的位置相对于<html>
position: fixed,固定定位元素的位置相对于浏览器窗口是固定位置,即使窗口是滚动的它也不会移动
position: relative,相对定位元素仍然在文档流中,所占空间不释放,只有相对原位置进行了偏移
代码演示:
  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. </head>
  9. <body>
  10. <header>
  11. <h2 class="title">固定登录框</h2>
  12. <button onclick="document.querySelector('.modal').style.display='block'">登录</button>
  13. </header>
  14. <!-- 模态框 -->
  15. <div class="modal">
  16. <!-- 1. 半透明的遮罩 -->
  17. <!-- 点击遮罩,关闭表单 -->
  18. <div class="modal-bg" onclick="this.parentNode.style.display='none'"></div>
  19. <!-- 2. 弹层表单 -->
  20. <form action="" class="modal-form">
  21. <fieldset style="display: grid; gap: 1em">
  22. <legend>用户登录</legend>
  23. <input type="email" name="email" placeholder="user@email.com" />
  24. <input type="password" name="password" placeholder="不少于6位" />
  25. <button>登录</button>
  26. </fieldset>
  27. </form>
  28. </div>
  29. <style>
  30. /* 初始化 */
  31. * {
  32. margin: 0;
  33. padding: 0;
  34. box-sizing: border-box;
  35. }
  36. /* 头部样式 */
  37. header {
  38. background-color: rgb(32, 47, 178);
  39. padding: 0.5em 1em;
  40. display: flex;
  41. }
  42. header .title {
  43. font-weight: lighter;
  44. font-style: italic;
  45. color: white;
  46. text-shadow: 1px 1px 1px #555;
  47. letter-spacing: 1px;
  48. }
  49. /* 登录按钮 */
  50. header button {
  51. margin-left: auto;
  52. width: 5em;
  53. border: none;
  54. border-radius: 0.5em;
  55. }
  56. header button:hover {
  57. cursor: pointer;
  58. background-color: coral;
  59. color: white;
  60. box-shadow: 0 0 5px #fff;
  61. transition: 0.3s;
  62. }
  63. /* 模态框表单 */
  64. .modal .modal-form fieldset {
  65. background-color: rgb(91, 181, 241);
  66. border: none;
  67. padding: 2em;
  68. box-shadow: 0 0 5px #888;
  69. }
  70. /* 模态框表单标题 */
  71. .modal .modal-form fieldset legend {
  72. padding: 1em 1em;
  73. background-color: rgb(32, 47, 178);
  74. color: white;
  75. border-radius: 5px;
  76. }
  77. .modal .modal-form {
  78. /* 固定定位 */
  79. position: fixed;
  80. top: 10em;
  81. left: 20em;
  82. right: 20em;
  83. }
  84. /* 半透明的遮罩 */
  85. .modal .modal-bg {
  86. position: fixed;
  87. top: 0;
  88. left: 0;
  89. right: 0;
  90. bottom: 0;
  91. background-color: rgb(0, 0, 0, 0.5);
  92. }
  93. .modal {
  94. display: none;
  95. }
  96. </style>
  97. </body>
  98. </html>

演示效果:

3.flex常用属性,实例演示

1.display:flex;(定义了一个flex容器)
2.flex-direction(决定主轴的方向)
属性值说明
row默认值,水平从左到右
colunm垂直从上到下
row-reverse水平从右到左
column-reverse垂直从下到上
3.flex-wrap(定义如何换行)
属性值说明
nowrap默认值,不换行
wrap换行
wrap-reverse换行,且颠倒行顺序,第一行在下方
4.子元素order(默认情况下flex order会按照书写顺训呈现,可以通过order属性改变,数值小的在前面,还可以是负数)
  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>Document</title>
  8. </head>
  9. <body>
  10. <div class="parent">
  11. <span class="item">item1</span>
  12. <pan class="item">item2</pan>
  13. <pan class="item">item3</pan>
  14. <pan class="item">item4</pan>
  15. <pan class="item">item5</pan>
  16. </div>
  17. </body>
  18. <style>
  19. .parent {
  20. display: flex;
  21. flex-flow: row nowrap;
  22. place-content: center;
  23. height: 12em;
  24. }
  25. .item {
  26. width: 3.6em;
  27. background-color: rgb(0, 255, 85);
  28. margin: 10px;
  29. color: rgb(255, 255, 255);
  30. text-align: center;
  31. }
  32. .parent :first-of-type {
  33. background-color: rgb(230, 46, 230);
  34. order: -1;
  35. }
  36. .parent :last-of-type {
  37. background-color: rgb(83, 20, 255);
  38. order: 3;
  39. }
  40. </style>
  41. </html>

演示效果:

更多相关文章

  1. 在Android里完美实现基站和WIFI定位
  2. Android(安卓)GPS定位的简单应用
  3. AsyncTask实例代码演示Android异步任务
  4. android ListView根据字母排序和定位
  5. android 三种定位方式
  6. 解决MySQL 5.7中定位DDL被阻塞的问题
  7. 室内定位导航系统设计实现指南
  8. android ListView根据字母排序和定位
  9. Android(安卓)使用GSM定位

随机推荐

  1. Swagger 自动生成 Dubbo 服务的接口文档,
  2. 介绍 Java 中的内存泄漏
  3. 诊断 Java.lang.OutOfMemoryError(OOM)
  4. 不想用 Swagger?可以试试这个神器!
  5. 测试领域,小白问题大集合(适合未入门和入
  6. Scala 与 Java 的交互操作
  7. Swagger(丝袜哥)3.0 官方 Starter 终于出了
  8. 到底要不要考研?
  9. Java 线程面试题 Top 50
  10. 推荐一款神仙颜值的 ZooKeeper 客户端工