{"id":156450,"date":"2020-09-17T18:29:23","date_gmt":"2020-09-17T10:29:23","guid":{"rendered":"http:\/\/4563.org\/?p=156450"},"modified":"2020-09-17T18:29:23","modified_gmt":"2020-09-17T10:29:23","slug":"%e5%88%86%e4%ba%ab%e4%b8%80%e4%b8%aa%e4%b8%8e-postcss-%e5%92%8c-viewport-%e9%85%8d%e5%a5%97%e4%bd%bf%e7%94%a8%e7%9a%84%e5%85%a8%e6%96%b0%e9%80%82%e9%85%8d%e5%8d%95%e4%bd%8d-pv","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=156450","title":{"rendered":"\u5206\u4eab\u4e00\u4e2a\u4e0e postcss \u548c viewport \u914d\u5957\u4f7f\u7528\u7684\u5168\u65b0\u9002\u914d\u5355\u4f4d: pv"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5206\u4eab\u4e00\u4e2a\u4e0e postcss \u548c viewport \u914d\u5957\u4f7f\u7528\u7684\u5168\u65b0\u9002\u914d\u5355\u4f4d: pv               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : pomeloTT <\/span>  <span><i><\/i> 6<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h2>\u80cc\u666f<\/h2>\n<ul>\n<li>\n<p>\u65e7\u7684 rem \u9002\u914d\u65b9\u6848\uff08\u65e0\u8bba\u662f\u76f4\u63a5\u4f7f\u7528 rem\uff0c\u8fd8\u662f\u914d\u5408 flexiblejs \u7b49 lib \u5e93\u8fdb\u884c\u89c6\u53e3\u7f29\u653e\uff09\u5df2\u7ecf\u75b2\u6001\u5c3d\u663e\uff0c\u4e14\u968f\u7740\u5b89\u5353\u9ad8\u6e05\u5c4f\u7684\u4e0d\u65ad\u51fa\u73b0\uff0c\u540c\u65f6 data-dpr \u4ecd\u6709\u8fdb\u4e00\u6b65\u589e\u52a0\u7684\u53ef\u80fd\u6027\uff0crem \u663e\u5f97\u5e76\u4e0d\u662f\u90a3\u4e48\u7a33\u56fa\u4e0e\u79f0\u5fc3\u5982\u610f\u3002<\/p>\n<\/li>\n<li>\n<p>\u9996\u5148\u622a\u6b62\u81f3\u53d1\u6587\u65e5\u671f\uff0cviewport \u7684\u517c\u5bb9\u6027\u5982\u4e0b\uff1a <img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/09\/20200918_5f6429b6afbe1.png\" alt=\"\u5206\u4eab\u4e00\u4e2a\u4e0e postcss \u548c viewport \u914d\u5957\u4f7f\u7528\u7684\u5168\u65b0\u9002\u914d\u5355\u4f4d: pv\" \/> \u53ef\u4ee5\u770b\u5230\uff0cviewport \u7684\u517c\u5bb9\u6027\u652f\u6301\u5df2\u7ecf\u53d8\u5f97\u975e\u5e38\u597d\uff0c\u56e0\u6b64\u6709\u673a\u4f1a\u629b\u5f03\u4e00\u5207\u5916\u63a5\u5e93\uff0c\u76f4\u63a5\u4f7f\u7528\u539f\u751f\u7684 viewport \u3002\u5c31\u50cf\u6700\u65e9\u4f7f\u7528 sublime \u5230\u73b0\u5728\u7684 vscode\uff0c\u90fd\u9700\u8981\u91cd\u65b0\u914d\u7f6e\u63d2\u4ef6 px2rem, \u6362\u4e86\u7f16\u8f91\u5668\uff0c\u6362\u4e86\u73af\u5883\uff0c\u5f00\u53d1\u5c31\u4f1a\u53d8\u5f97\u5f88\u964c\u751f\u3002\u518d\u52a0\u4e0a\u4e0d\u540c\u63d2\u4ef6\u5feb\u6377\u952e\u89e6\u53d1\u6761\u4ef6\u4e5f\u4e0d\u540c\uff0c\u8fd9\u5c31\u7ed9\u539f\u672c\u5c31\u5f88\u714e\u71ac\u7684\u524d\u7aef\u5f00\u53d1\u53c8\u589e\u52a0\u4e86\u590d\u6742\u5ea6\u3002\u597d\u5728 postcss \u51fa\u73b0\u4e86\uff0c\u5b83\u5141\u8bb8\u6211\u4eec\u7528\u66f4\u52a0\u5f7b\u5e95\uff08\u76f8\u6bd4 less \u548c scss \u800c\u8a00\uff09\u7684\u7f16\u7a0b\u601d\u7ef4\u6216\u8005\u8bf4\u9762\u5411\u5bf9\u8c61\u7684\u601d\u7ef4\u53bb\u5bf9 css \u505a\u9884\u5904\u7406\u3002<\/p>\n<\/li>\n<li>\n<p>\u56de\u5230 px \u8f6c vw \u7684\u95ee\u9898\u4e0a\uff0c\u89e3\u51b3\u6b64\u95ee\u9898\u53ef\u4ee5\u4f7f\u7528\u4e0e postcss \u5b98\u65b9\u517c\u5bb9\u7684\u63d2\u4ef6 postcss-px2vw-pv \u89e3\u51b3\uff1a<\/p>\n<\/li>\n<li>\n<p>\u5b98\u65b9\u6587\u6863\uff1a https:\/\/github.com\/pomelott\/postcss-px2vw-pv<\/p>\n<\/li>\n<li>\n<p>\u6b64\u63d2\u4ef6\u4f7f\u7528\u5168\u65b0\u7684\u7f6e\u6362\u5355\u4f4d pv\uff0c\u7528 postcss \u81ea\u52a8\u5bf9\u5404\u79cd\u590d\u6742 css \u6837\u5f0f\u505a\u8ba1\u7b97\u4e0e\u8f6c\u6362\uff0c\u800c\u4e0d\u5fc5\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u518d\u8003\u8651\u5404\u79cd\u5feb\u6377\u952e\u3001\u7f16\u8f91\u5668\u63d2\u4ef6\u4ee5\u53ca\u8f6c\u6362\u914d\u7f6e\u7b49\u3002<\/p>\n<\/li>\n<\/ul>\n<h2>\u5b89\u88c5<\/h2>\n<pre><code>    npm i postcss-px2vm-pv -D <\/code><\/pre>\n<pre><code>    yarn add postcss-px2vw-pv --dev <\/code><\/pre>\n<h2>\u914d\u7f6e\u9009\u9879<\/h2>\n<p>| \u9009\u9879 | \u7c7b\u578b | \u9ed8\u8ba4\u503c | \u63cf\u8ff0 | |:&#8212;:|:&#8212;:|:&#8212;:|:&#8212;:| | width | number | 750 | \u8bbe\u8ba1\u7a3f\u50cf\u7d20\u5bbd\u5ea6 | | decimal | number | 4 | \u6362\u7b97\u540e\u5c0f\u6570\u70b9\u540e\u7684\u4fdd\u7559\u4f4d\u6570 | | comment | boolean | true | \u662f\u5426\u751f\u6210\u63d2\u4ef6\u76f8\u5173\u6ce8\u91ca |<\/p>\n<pre><code>    module.exports = {         plugins: [             require('postcss-px2vw-pv')         ]     } <\/code><\/pre>\n<h2>\u5feb\u901f\u4f7f\u7528<\/h2>\n<ul>\n<li>\u9996\u5148\u6dfb\u52a0 postcss \u81f3\u5f00\u53d1\u73af\u5883\u4e2d\uff0c\u6b64\u5904\u4e0d\u505a\u8d58\u8ff0\uff0c\u4e0d\u660e\u767d\u7684\u53ef\u4e0a postcss \u5b98\u65b9\u67e5\u770b\u3002<\/li>\n<li>\u4f8b\u5982\uff1a<\/li>\n<\/ul>\n<pre><code>    module.exports = {         plugins: [             require('postcss-px2vw-pv')({                   width: 1080             })         ]     } <\/code><\/pre>\n<ul>\n<li>\u7136\u540e\u5bf9 postcss-px2vw-pv \u8fdb\u884c\u914d\u7f6e\uff0c\u6216\u4f7f\u7528\u9ed8\u8ba4\u914d\u7f6e\u9879\u4e5f\u53ef\u3002<\/li>\n<li>\u4f8b\u5982\u4e00\u4e2a div \u7684\u5bbd\u5ea6\u662f \u2019500px\u2018\uff0c \u90a3\u4e48\u4f60\u53ef\u4ee5\u4f7f\u7528 \u2019500pv\u2018 \u8fdb\u884c\u66ff\u6362\uff0c\u63d2\u4ef6\u4f1a\u6839\u636e\u8bbe\u8ba1\u7a3f\u5bbd\u5ea6\u81ea\u52a8\u8ba1\u7b97\u5e76\u751f\u6210\u65b0\u7684 css \u6837\u5f0f\u3002<\/li>\n<\/ul>\n<h2>\u5c0f\u4f8b\u5b50<\/h2>\n<ul>\n<li>\u5728 750 \u5bbd\u5ea6\u7684\u8bbe\u8ba1\u7a3f\u4e0b\uff0c \u4f7f\u7528 500px \u7684\u5bbd\u5ea6\uff0c10px \u7684\u6a2a\u5411\u4f4d\u79fb<\/li>\n<\/ul>\n<pre><code>    .box {         width: 500pv;         transform: translateX(10pv);     } <\/code><\/pre>\n<ul>\n<li>\u751f\u6210\u7684\u6700\u7ec8\u6837\u5f0f\u5982\u4e0b\uff1a<\/li>\n<\/ul>\n<pre><code>    .box {         width: 66.666667vw;         transform: translateX(1.333333vw);     } <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3268138\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SergeGao <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6548\u679c\u8ddf rem,flexiblejs \u7f29\u653e\u6709\u5565\u4e0d\u4e00\u6837\u5462?                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3268139\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : weixiangzhe <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             pv \u5177\u4f53\u6709\u4ec0\u4e48\u4e0d\u540c\u5462                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3268140\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : weixiangzhe <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u770b\u4e86\u4e0b pv \u5c31\u662f\u5bf9\u5e94\u8bbe\u8ba1\u7a3f\u5927\u5c0f 750 \u7684\u503c \u7136\u540e\u6309\u6bd4\u4f8b\u8f6c\u6210 vw\uff0c\u652f\u6301\u4e00\u4e0b\uff0c\u8c8c\u4f3c\u5df2\u7ecf\u7c7b\u4f3c\u7684 postcss \u7684\u5185\u5bb9\u4e86\uff0c\u4f30\u8ba1\u7528\u4e0d\u4e0a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3268141\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : gouflv <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             px2viewport \u5c31\u633a\u597d\u7684\uff0c\u6ca1\u5fc5\u8981\u81ea\u5df1\u53d1\u660e\u5355\u4f4d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5206\u4eab\u4e00\u4e2a\u4e0e postcss \u548c v&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/156450"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=156450"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/156450\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=156450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=156450"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=156450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}