设计稿一般以750px作为整屏宽度,而网站最小字体大小为12px,所以这里以750/12 = 62.5作为屏幕水平栏栅数量,同时12px也是蓝湖默认的rem方案根字体大小。
    我们在入口文件中添加以下逻辑即可。

    1. (() => {
    2. const setFontSize = () => {
    3. let clientWidth = document.documentElement.clientWidth;
    4. if (clientWidth > 750) {
    5. clientWidth = 750;
    6. } else if (clientWidth < 320) {
    7. clientWidth = 320;
    8. }
    9. global.rootFontSize = clientWidth / 62.5; // 这里用了一个全局的rootFontSize保存根字体大小,以便在其他地方用到,全局变量可自行定义
    10. document.getElementsByTagName('html')[0].style.fontSize = `${global.rootFontSize}px`;
    11. }
    12. window.onresize = setFontSize;
    13. setFontSize();
    14. })();

    配合最大宽度为750px的公共版心可以友好支持PC端

    1. .box {
    2. max-width: 750px;
    3. min-height: 100vh;
    4. background-color: white;
    5. margin: 0 auto;
    6. }

    示例:

    1. .header {
    2. position: relative;
    3. height: 33.33rem;
    4. background: linear-gradient(-30deg, #33CA88, #37DD8F);
    5. padding: 7.83rem 3.17rem;
    6. overflow: hidden;
    7. .circle {
    8. position: absolute;
    9. width: 34.5rem;
    10. height: 34.5rem;
    11. top: -17.25rem;
    12. right: -17.25rem;
    13. z-index: 2;
    14. }
    15. .title {
    16. font-size: 6rem;
    17. font-family: PingFang SC;
    18. font-weight: 800;
    19. color: #FFFFFF;
    20. text-shadow: 0rem 1rem 1rem rgba(0, 113, 67, 0.3);
    21. background: linear-gradient(180deg, #FFFFFF 46.240234375%, #44FFB3 100%);
    22. -webkit-background-clip: text;
    23. -webkit-text-fill-color: transparent;
    24. }
    25. .time {
    26. margin-top: 2.67rem;
    27. width: 15rem;
    28. height: 3.33rem;
    29. background: rgba(0, 113, 67, 0.3);
    30. border-radius: 2rem;
    31. display: flex;
    32. flex-direction: row;
    33. justify-content: center;
    34. align-items: center;
    35. overflow: hidden;
    36. .timeIcon {
    37. width: 1.67rem;
    38. height: 1.67rem;
    39. margin-right: 0.58rem;
    40. }
    41. .timeText {
    42. font-size: 2rem;
    43. font-family: PingFang SC;
    44. font-weight: 500;
    45. color: #FFFFFF;
    46. }
    47. }
    48. }
    1. <div className="box">
    2. <div className={styles.header}>
    3. <img className={styles.circle} src="/assets/images/circle.png" alt="" />
    4. <div className={styles.title}>舌诊</div>
    5. <div className={styles.time}>
    6. <img className={styles.timeIcon} src="/assets/images/clock.png" alt="" />
    7. <div className={styles.timeText}>预计5分钟</div>
    8. </div>
    9. </div>
    10. </div>

    image.png