Blogger Information
Blog 6
fans 0
comment 0
visits 2615
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
盒模型常用属性、媒体查询及em,rem用法
P粉150142745
Original
389 people have browsed it

演示盒模型常用属性


  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. <div class="box"></div>
  11. <div class="box"></div>
  12. <style>
  13. .box {
  14. width: 200px;
  15. height: 200px;
  16. background-color: blueviolet;
  17. border: 10px solid rgb(230, 238, 195);
  18. padding: 10px;
  19. background-clip: content-box;
  20. box-sizing: border-box;
  21. margin: 20px;
  22. }
  23. </style>
  24. <style>
  25. body {
  26. background-color: rgb(228, 174, 219);
  27. }
  28. @media (max-width: 400px) {
  29. body {
  30. background-color: rgb(241, 230, 208);
  31. }
  32. }
  33. </style>
  34. </body>
  35. </html>
  36. </body>
  37. </html>

实例演示媒体查询

  1. <!-- 实例演示媒体查询 -->
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5. <meta charset="UTF-8" />
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  8. <title>Document</title>
  9. </head>
  10. <body>
  11. <button class="btn samll">btn1</button>
  12. <button class="btn middle">btn2</button>
  13. <button class="btn large">btn3</button>
  14. <style>
  15. html {
  16. font-size: 10px;
  17. }
  18. .btn {
  19. background-color: seagreen;
  20. color: white;
  21. border: none;
  22. outline: none;
  23. }
  24. .btn:hover {
  25. cursor: pointer;
  26. opacity: 0.8;
  27. transition: 0.3s;
  28. padding: 0.4rem 0.8rem;
  29. }
  30. .btn.small {
  31. /* font-size: 12px; */
  32. font-size: 1.2rem;
  33. }
  34. .btn.middle {
  35. /* font-size: 16px; */
  36. font-size: 1.6rem;
  37. }
  38. .btn.large {
  39. /* font-size: 18px; */
  40. font-size: 1.8rem;
  41. }
  42. /* 媒体查询 */
  43. @media (max-width: 374px) {
  44. html {
  45. font-size: 12px;
  46. }
  47. }
  48. /* 374px - 414px 之间 */
  49. @media (min-width: 375px) and (max-width: 413px) {
  50. html {
  51. font-size: 14px;
  52. }
  53. }
  54. /* >414px 之间 */
  55. @media (min-width: 414px) {
  56. html {
  57. font-size: 16px;
  58. }
  59. }
  60. </style>
  61. </body>
  62. </html>

演示em,rem用法

em: 动态的字号,总是相对于自身或祖先元素,如果祖先是根元素,em=rem

  1. <style>
  2. html {
  3. font-size: 10px;
  4. }
  5. div {
  6. font-size: 30px;
  7. }
  8. div span {
  9. font-size: 2em;
  10. }
  11. </style>

rem:静态的字号,总是相对于”根元素”

  1. <style>
  2. html {
  3. font-size: 10px;
  4. }
  5. div {
  6. font-size: 30px;
  7. }
  8. div span {
  9. font-size: 2rem;
  10. }
  11. </style>

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post