{"id":2325,"date":"2024-11-10T09:05:24","date_gmt":"2024-11-10T01:05:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2325\/"},"modified":"2024-11-10T09:05:24","modified_gmt":"2024-11-10T01:05:24","slug":"scss-%e4%b8%ad%e5%a6%82%e4%bd%95%e7%9b%b4%e6%8e%a5%e8%ae%bf%e9%97%ae%e5%8f%98%e9%87%8f%e7%bb%84%e4%b8%ad%e7%9a%84%e7%89%b9%e5%ae%9a%e5%80%bc%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2325\/","title":{"rendered":"SCSS \u4e2d\u5982\u4f55\u76f4\u63a5\u8bbf\u95ee\u53d8\u91cf\u7ec4\u4e2d\u7684\u7279\u5b9a\u503c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173071530377108.jpg\" class=\"aligncenter\" title=\"SCSS \u4e2d\u5982\u4f55\u76f4\u63a5\u8bbf\u95ee\u53d8\u91cf\u7ec4\u4e2d\u7684\u7279\u5b9a\u503c\uff1f\u63d2\u56fe\" alt=\"SCSS \u4e2d\u5982\u4f55\u76f4\u63a5\u8bbf\u95ee\u53d8\u91cf\u7ec4\u4e2d\u7684\u7279\u5b9a\u503c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 s \u4e2d\u76f4\u63a5\u8bbf\u95ee\u53d8\u91cf\u7ec4\u4e2d\u7684\u503c<\/strong><\/p>\n<p>\u5728 scss \u4e2d\u5b9a\u4e49\u53d8\u91cf\u7ec4\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 $spacer \u8fd9\u6837\u7684\u53d8\u91cf\u540d\u6765\u8bbf\u95ee\u6574\u4e2a\u7ec4\u3002\u4f46\u662f\uff0c\u5982\u679c\u9700\u8981\u5728\u6837\u5f0f\u8868\u4e2d\u76f4\u63a5\u8bbf\u95ee\u7ec4\u4e2d\u7279\u5b9a\u503c\uff0c\u8be5\u600e\u4e48\u505a\u5462\uff1f<\/p>\n<p>\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528 @each \u5faa\u73af\u904d\u5386\u7ec4\u4e2d\u7684\u503c\uff0c\u7136\u540e\u751f\u6210\u5305\u542b\u8be5\u503c\u7684\u5b9e\u9645\u7c7b\uff1a<\/p>\n<pre>$spacer: (\n  sm: 5px,\n  base: 10px,\n  lg: 15px,\n);\n\n@each $key, $value in $spacer {\n  .sp-#{$key} {\n    margin-top: $value;\n  }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f46\u662f\uff0c\u662f\u5426\u6709\u66f4\u7b80\u6d01\u7684\u65b9\u6cd5\u76f4\u63a5\u8bbf\u95ee\u7ec4\u4e2d\u7279\u5b9a\u503c\uff1f<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u662f\u7684\uff0c\u53ef\u4ee5\u4f7f\u7528 sass \u7684 map-get() \u51fd\u6570\uff1a<\/p>\n<pre>.MyClass {\n  margin-top: map-get($spacer, 'sm');\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u76f4\u63a5\u5728 $spacer \u53d8\u91cf\u7ec4\u4e2d\u8bbf\u95ee &#8216;sm&#8217; \u952e\u7684\u503c\uff0c\u8fd9\u662f 5px\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fSCSS \u4e2d\u5982\u4f55\u76f4\u63a5\u8bbf\u95ee\u53d8\u91cf\u7ec4\u4e2d\u7684\u7279\u5b9a\u503c\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728 s \u4e2d\u76f4\u63a5\u8bbf\u95ee\u53d8\u91cf\u7ec4\u4e2d\u7684\u503c \u5728 scss \u4e2d\u5b9a\u4e49\u53d8\u91cf\u7ec4\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 $spacer \u8fd9\u6837\u7684\u53d8\u91cf\u540d\u6765\u8bbf\u95ee\u6574\u4e2a\u7ec4\u3002\u4f46\u662f\uff0c\u5982\u679c\u9700\u8981\u5728\u6837\u5f0f\u8868\u4e2d\u76f4\u63a5\u8bbf\u95ee\u7ec4\u4e2d\u7279\u5b9a\u503c\uff0c\u8be5\u600e\u4e48\u505a\u5462\uff1f \u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528 @each \u5faa\u73af\u904d\u5386\u7ec4\u4e2d\u7684\u503c\uff0c\u7136\u540e\u751f\u6210\u5305\u542b\u8be5\u503c\u7684\u5b9e\u9645\u7c7b\uff1a $spacer: ( sm: 5px, base: 10px, lg: 15px, ); @each $key, $value in $spacer { .sp-#{$key} { margin-top: $value; } } \u767b\u5f55\u540e\u590d\u5236 \u4f46\u662f\uff0c\u662f\u5426\u6709\u66f4\u7b80\u6d01\u7684\u65b9\u6cd5\u76f4\u63a5\u8bbf\u95ee\u7ec4\u4e2d\u7279\u5b9a\u503c\uff1f \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u662f\u7684\uff0c\u53ef\u4ee5\u4f7f\u7528 sass \u7684 map-get() \u51fd\u6570\uff1a .MyClass { margin-top: map-get($spacer, &#8216;sm&#8217;); } \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u6837\u5c31\u53ef\u4ee5\u76f4\u63a5\u5728 $spacer \u53d8\u91cf\u7ec4\u4e2d\u8bbf\u95ee &#8216;sm&#8217; \u952e\u7684\u503c\uff0c\u8fd9\u662f 5px\u3002 \u4ee5\u4e0a\u5c31\u662fSCSS \u4e2d\u5982\u4f55\u76f4\u63a5\u8bbf\u95ee\u53d8\u91cf\u7ec4\u4e2d\u7684\u7279\u5b9a\u503c\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-2325","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=2325"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2325\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}