{"id":3514,"date":"2024-11-10T17:30:24","date_gmt":"2024-11-10T09:30:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3514\/"},"modified":"2024-11-10T17:30:24","modified_gmt":"2024-11-10T09:30:24","slug":"less-%e4%b8%ad%e7%9a%84-calc-%e8%ae%a1%e7%ae%97%e4%b8%ba%e4%bd%95%e5%8f%98%e6%88%90%e5%9b%ba%e5%ae%9a%e7%99%be%e5%88%86%e6%af%94%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3514\/","title":{"rendered":"Less \u4e2d\u7684 Calc \u8ba1\u7b97\u4e3a\u4f55\u53d8\u6210\u56fa\u5b9a\u767e\u5206\u6bd4\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173104903262293.jpg\" class=\"aligncenter\" title=\"Less \u4e2d\u7684 Calc \u8ba1\u7b97\u4e3a\u4f55\u53d8\u6210\u56fa\u5b9a\u767e\u5206\u6bd4\uff1f\u63d2\u56fe\" alt=\"Less \u4e2d\u7684 Calc \u8ba1\u7b97\u4e3a\u4f55\u53d8\u6210\u56fa\u5b9a\u767e\u5206\u6bd4\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u95ee\u9898\uff1aless \u4e2d\u7684 calc \u8ba1\u7b97\u5f02\u5e38\uff0c\u7ed3\u679c\u4e3a\u4f55\u53d8\u6210\u56fa\u5b9a\u767e\u5206\u6bd4\uff1f<\/strong><\/p>\n<p>\u5728\u8fdb\u884c CSS \u6837\u5f0f\u5f00\u53d1\u65f6\uff0c\u4f7f\u7528 Less \u9884\u9047\u5230\u4e00\u4e2a\u95ee\u9898\u3002\u5728\u4e00\u4e2a\u6b63\u5f0f\u73af\u5883\u548c\u6d4b\u8bd5\u73af\u5883\u4e2d\u4f7f\u7528\u4e86\u4ee5\u4e0b Less \u4ee3\u7801\uff1a<\/p>\n<pre>.element {\n  width: calc((100% - 40px) \/ 4);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u800c\uff0c\u5728\u6d4b\u8bd5\u73af\u5883\u4e2d\uff0ccalc \u8ba1\u7b97\u540e\u7684\u503c\u610f\u5916\u5730\u53d8\u6210\u4e86\u56fa\u5b9a\u7684 15%\u3002<\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><\/p>\n<p>\u5728 Less \u4e2d\uff0c\u6d89\u53ca\u4e0d\u540c\u5355\u4f4d\u6df7\u5408\u8fd0\u7b97\u7684 calc \u8868\u8fbe\u5f0f\u4f1a\u9047\u5230\u4e00\u4e2a\u7279\u6b8a\u60c5\u51b5\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u5728 Less \u4e2d\uff0ccalc(100% &#8211; 40px) \u8fd9\u6837\u7684\u5e26\u6709\u5355\u4f4d\u6df7\u5408\u7684\u8fd0\u7b97\u4f1a\u88ab Less \u89e3\u6790\u5ffd\u7565\u5355\u4f4d\uff0c\u5168\u90e8\u6309\u7167\u767e\u5206\u6bd4\u8ba1\u7b97\u3002\u56e0\u6b64\uff0c\u4e0a\u8ff0\u8868\u8fbe\u5f0f\u7684\u8ba1\u7b97\u88ab\u89e3\u6790\u4e3a calc(60% \/ 4) = calc(15%)\u3002<\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6709\u4e24\u79cd\u6b63\u786e\u7684\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528\u5355\u4f4d\u7b26\u53f7\uff1a<\/p>\n<pre>.element {\nwidth: calc((~\"100% - 40px\") \/ 4);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u5b9a\u4e49\u53d8\u91cf\u5e76\u4f7f\u7528\u53d8\u91cf\uff1a<\/p>\n<pre>@myHeight: 30px;\n.element {\nwidth: calc((~\"100% - @{myHeight}\") \/ 4);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u53ef\u4ee5\u786e\u4fdd Less \u6b63\u786e\u89e3\u6790\u5355\u4f4d\uff0c\u5e76\u83b7\u5f97\u9884\u671f\u7684\u8ba1\u7b97\u7ed3\u679c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fLess \u4e2d\u7684 Calc \u8ba1\u7b97\u4e3a\u4f55\u53d8\u6210\u56fa\u5b9a\u767e\u5206\u6bd4\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>\u95ee\u9898\uff1aless \u4e2d\u7684 calc \u8ba1\u7b97\u5f02\u5e38\uff0c\u7ed3\u679c\u4e3a\u4f55\u53d8\u6210\u56fa\u5b9a\u767e\u5206\u6bd4\uff1f \u5728\u8fdb\u884c CSS \u6837\u5f0f\u5f00\u53d1\u65f6\uff0c\u4f7f\u7528 Less \u9884\u9047\u5230\u4e00\u4e2a\u95ee\u9898\u3002\u5728\u4e00\u4e2a\u6b63\u5f0f\u73af\u5883\u548c\u6d4b\u8bd5\u73af\u5883\u4e2d\u4f7f\u7528\u4e86\u4ee5\u4e0b Less \u4ee3\u7801\uff1a .element { width: calc((100% &#8211; 40px) \/ 4); } \u767b\u5f55\u540e\u590d\u5236 \u7136\u800c\uff0c\u5728\u6d4b\u8bd5\u73af\u5883\u4e2d\uff0ccalc \u8ba1\u7b97\u540e\u7684\u503c\u610f\u5916\u5730\u53d8\u6210\u4e86\u56fa\u5b9a\u7684 15%\u3002 \u89e3\u7b54\uff1a \u5728 Less \u4e2d\uff0c\u6d89\u53ca\u4e0d\u540c\u5355\u4f4d\u6df7\u5408\u8fd0\u7b97\u7684 calc \u8868\u8fbe\u5f0f\u4f1a\u9047\u5230\u4e00\u4e2a\u7279\u6b8a\u60c5\u51b5\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u5728 Less \u4e2d\uff0ccalc(100% &#8211; 40px) \u8fd9\u6837\u7684\u5e26\u6709\u5355\u4f4d\u6df7\u5408\u7684\u8fd0\u7b97\u4f1a\u88ab Less \u89e3\u6790\u5ffd\u7565\u5355\u4f4d\uff0c\u5168\u90e8\u6309\u7167\u767e\u5206\u6bd4\u8ba1\u7b97\u3002\u56e0\u6b64\uff0c\u4e0a\u8ff0\u8868\u8fbe\u5f0f\u7684\u8ba1\u7b97\u88ab\u89e3\u6790\u4e3a calc(60% \/ 4) = calc(15%)\u3002 \u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6709\u4e24\u79cd\u6b63\u786e\u7684\u65b9\u6cd5\uff1a \u4f7f\u7528\u5355\u4f4d\u7b26\u53f7\uff1a .element { width: calc((~&#8221;100% &#8211; 40px&#8221;) \/ 4); } \u767b\u5f55\u540e\u590d\u5236 \u5b9a\u4e49\u53d8\u91cf\u5e76\u4f7f\u7528\u53d8\u91cf\uff1a [&hellip;]<\/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-3514","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3514","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=3514"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3514\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}