Blogger Information
Blog 21
fans 0
comment 0
visits 9289
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
rem\vw\px之间换算
P粉116103988
Original
1082 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>Document</title>
  8. </head>
  9. <body>
  10. <div class="text">
  11. <div class="title">
  12. <h2>PHP中文网</h2>
  13. </div>
  14. <div class="content">
  15. PHP中文网,程序员梦想开始的地方!
  16. </div>
  17. </div>
  18. <style>
  19. /* 将1rem设置为100px:方便计算 */
  20. html{
  21. /* font-size: 100px; */
  22. /* 移动端Iphne6/11宽度为375px:100vw=375px */
  23. /* 移动端布局:布局视口=视觉视口 */
  24. font-size: calc(100VW/3.75);
  25. }
  26. /* 重置大小 */
  27. body{
  28. /* font-size: 16px; */
  29. /* 把px转为rem表示,字体就会随着视口宽度的变化而变化 */
  30. font-size: 0.16rem;
  31. }
  32. @media (max-width:330px){
  33. /* 设置移动端视口变小后的最小字体:14px */
  34. /* 16px=1rem,14px=?rem :14/16*1=0.875rem*/
  35. /* 然后将rem转为px:0.875*100=87.5px */
  36. html{
  37. /* 将这里大小固定下来,设备视口宽度小于330px后字体大小将固定为14px */
  38. font-size:87.5px ;
  39. }
  40. }
  41. @media (min-width:470px){
  42. html{
  43. /* 20/16=1.25rem*100px=125px, */
  44. font-size: 125px;
  45. }
  46. }
  47. .text{
  48. background-color: beige;
  49. }
  50. /* .text .title,
  51. .text .content{
  52. width: 980px;
  53. text-align: center;
  54. margin: auto;
  55. } */
  56. </style>
  57. </body>
  58. </html>

效果图如下:

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