{"id":159568,"date":"2024-05-08T13:12:49","date_gmt":"2024-05-08T05:12:49","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/159568.html"},"modified":"2024-05-08T13:12:52","modified_gmt":"2024-05-08T05:12:52","slug":"%e5%89%8d%e7%ab%af%e5%bc%80%e5%8f%91%e6%97%b6%e7%9b%92%e5%ad%90%e6%a8%a1%e5%9e%8b%e7%9a%84%e5%ae%bd%e5%ba%a6%e5%a6%82%e4%bd%95%e8%ae%a1%e7%ae%97","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/159568.html","title":{"rendered":"\u524d\u7aef\u5f00\u53d1\u65f6\u76d2\u5b50\u6a21\u578b\u7684\u5bbd\u5ea6\u5982\u4f55\u8ba1\u7b97"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26222129\/eb9a1c26-f9ad-4911-82bf-039d7ec4bd85.webp\" alt=\"\u524d\u7aef\u5f00\u53d1\u65f6\u76d2\u5b50\u6a21\u578b\u7684\u5bbd\u5ea6\u5982\u4f55\u8ba1\u7b97\" \/><\/p>\n<p><p><strong>\u76d2\u5b50\u6a21\u578b\u7684\u5bbd\u5ea6\u8ba1\u7b97<\/strong>\u4f9d\u6258\u4e8eCSS\u7684\u76d2\u6a21\u578b\u6982\u5ff5\uff0c\u5176\u57fa\u672c\u7ec4\u6210\u5305\u62ec\u5185\u5bb9\uff08content\uff09\u3001\u5185\u8fb9\u8ddd\uff08padding\uff09\u3001\u8fb9\u6846\uff08border\uff09\u548c\u5916\u8fb9\u8ddd\uff08margin\uff09\u56db\u4e2a\u90e8\u5206\u3002\u8981\u8ba1\u7b97\u76d2\u5b50\u7684\u5b9e\u9645\u5bbd\u5ea6\uff0c\u9700\u8981\u53e0\u52a0<strong>\u5185\u5bb9\u7684\u5bbd\u5ea6\u3001\u5de6\u53f3\u5185\u8fb9\u8ddd\u3001\u4ee5\u53ca\u5de6\u53f3\u8fb9\u6846\u5bbd\u5ea6<\/strong>\u3002\u5177\u4f53\u800c\u8a00\uff0c\u5b9e\u9645\u5bbd\u5ea6=\u5185\u5bb9\u7684width + \u5de6padding + \u53f3padding + \u5de6border + \u53f3border\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u5916\u8fb9\u8ddd\uff08margin\uff09\u5e76\u4e0d\u8ba1\u5165\u76d2\u5b50\u7684\u5b9e\u9645\u5bbd\u5ea6\u4e2d\uff0c\u4f46\u5b83\u4f1a\u5f71\u54cd\u76d2\u5b50\u4e0e\u5176\u4ed6\u5143\u7d20\u4e4b\u95f4\u7684\u8ddd\u79bb\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u7406\u89e3\u76d2\u6a21\u578b<\/h2>\n<\/p>\n<p><p>\u76d2\u6a21\u578b\u662f\u524d\u7aef\u5f00\u53d1\u65f6\u6781\u4e3a\u91cd\u8981\u7684\u6982\u5ff5\u4e4b\u4e00\u3002\u5728CSS\u4e2d\uff0c\u76d2\u6a21\u578b\u5b9a\u4e49\u4e86\u6587\u6863\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u6846\u67b6\uff0c\u5e76\u5f71\u54cd\u7740\u5143\u7d20\u7684\u5e03\u5c40\u548c\u9875\u9762\u7684\u6574\u4f53\u8bbe\u8ba1\u3002<\/p>\n<\/p>\n<p><h3>\u5185\u5bb9\uff08Content\uff09<\/h3>\n<\/p>\n<p><p>\u5185\u5bb9\u533a\u57df\u662f\u6307\u5143\u7d20\u4e2d\u7528\u4e8e\u5c55\u793a\u5185\u5bb9\u7684\u533a\u57df\uff0c\u5b83\u7684\u5c3a\u5bf8\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>width<\/code>\u548c<code>height<\/code>\u5c5e\u6027\u6765\u786e\u5b9a\u3002<\/p>\n<\/p>\n<p><h3>\u5185\u8fb9\u8ddd\uff08Padding\uff09<\/h3>\n<\/p>\n<p><p>\u5185\u8fb9\u8ddd\u662f\u5185\u5bb9\u533a\u57df\u5916\u56f4\u81f3\u8fb9\u6846\u4e4b\u95f4\u7684\u7a7a\u95f4\u3002\u5b83\u53ef\u4ee5\u5206\u522b\u901a\u8fc7<code>padding-top<\/code>\u3001<code>padding-right<\/code>\u3001<code>padding-bottom<\/code>\u3001<code>padding-left<\/code>\u56db\u4e2a\u5c5e\u6027\u6765\u5355\u72ec\u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<p><h3>\u8fb9\u6846\uff08Border\uff09<\/h3>\n<\/p>\n<p><p>\u8fb9\u6846\u73af\u7ed5\u5728\u5185\u8fb9\u8ddd\u4e4b\u5916\uff0c\u4e3a\u5143\u7d20\u63d0\u4f9b\u4e00\u4e2a\u53ef\u89c6\u7684\u754c\u9650\u3002\u8fb9\u6846\u7684\u7c97\u7ec6\u53ef\u4ee5\u901a\u8fc7<code>border-width<\/code>\u5c5e\u6027\u5b9a\u4e49\u3002<\/p>\n<\/p>\n<p><h3>\u5916\u8fb9\u8ddd\uff08Margin\uff09<\/h3>\n<\/p>\n<p><p>\u5916\u8fb9\u8ddd\u662f\u8fb9\u6846\u4e4b\u5916\u5230\u5176\u5b83\u5143\u7d20\u8fb9\u6846\u7684\u8ddd\u79bb\u3002\u7c7b\u4f3c\u4e8e\u5185\u8fb9\u8ddd\uff0c\u5b83\u4e5f\u6709\u56db\u4e2a\u5355\u72ec\u7684\u5c5e\u6027\uff1a<code>margin-top<\/code>\u3001<code>margin-right<\/code>\u3001<code>margin-bottom<\/code>\u3001<code>margin-left<\/code>\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u8ba1\u7b97\u76d2\u5b50\u5bbd\u5ea6<\/h2>\n<\/p>\n<p><p>\u5f53\u8ba1\u7b97\u76d2\u5b50\u6a21\u578b\u7684\u5bbd\u5ea6\u65f6\uff0c\u9700\u8981\u8003\u8651\u4ee5\u4e0b\u51e0\u4e2aCSS\u5c5e\u6027\uff1a<\/p>\n<\/p>\n<p><h3>\u76d2\u5b50\u5bbd\u5ea6\u8ba1\u7b97\u516c\u5f0f<\/h3>\n<\/p>\n<p><p>\u6838\u5fc3\u8ba1\u7b97\u516c\u5f0f\u5982\u4e0a\u6240\u8ff0\uff0c\u91cd\u70b9\u5728\u4e8e\u7406\u89e3\u6bcf\u4e2a\u503c\u5982\u4f55\u83b7\u5f97\u548c\u5728\u4f55\u5904\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h3>CSS Box-Sizing\u5c5e\u6027<\/h3>\n<\/p>\n<p><p>\u8fd9\u4e2a\u5c5e\u6027\u7684\u9ed8\u8ba4\u503c\u662f<code>content-box<\/code>\uff0c\u610f\u5473\u7740\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u53ea\u5305\u62ec\u5185\u5bb9\u533a\u57df\u3002\u5982\u679c\u8bbe\u7f6e\u4e3a<code>border-box<\/code>\uff0c\u5219\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u4f1a\u5305\u542b\u5185\u5bb9\u3001\u5185\u8fb9\u8ddd\u548c\u8fb9\u6846\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u5b9e\u9645\u5e94\u7528\u573a\u666f\u5206\u6790<\/h2>\n<\/p>\n<p><p>\u76d2\u5b50\u6a21\u578b\u7684\u5bbd\u5ea6\u8ba1\u7b97\u5728\u524d\u7aef\u5f00\u53d1\u4e2d\u975e\u5e38\u5b9e\u7528\uff0c\u5c24\u5176\u662f\u5728\u8fdb\u884c\u9875\u9762\u5e03\u5c40\u548c\u5143\u7d20\u6392\u7248\u65f6\u3002<\/p>\n<\/p>\n<p><h3>\u54cd\u5e94\u5f0f\u8bbe\u8ba1<\/h3>\n<\/p>\n<p><p>\u5728\u54cd\u5e94\u5f0f\u7f51\u9875\u8bbe\u8ba1\u4e2d\uff0c\u6b63\u786e\u7684\u76d2\u5b50\u5bbd\u5ea6\u8ba1\u7b97\u5141\u8bb8\u5143\u7d20\u5728\u4e0d\u540c\u5c4f\u5e55\u5c3a\u5bf8\u4e0b\u4fdd\u6301\u4e00\u81f4\u7684\u5916\u89c2\u548c\u6392\u7248\u3002<\/p>\n<\/p>\n<p><h3>JavaScript\u4ea4\u4e92<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528JavaScript\u5bf9DOM\u5143\u7d20\u8fdb\u884c\u64cd\u4f5c\u65f6\uff0c\u51c6\u786e\u7684\u76d2\u5b50\u6a21\u578b\u5c3a\u5bf8\u8ba1\u7b97\u53ef\u4ee5\u786e\u4fdd\u52a8\u6001\u6548\u679c\u7684\u6b63\u786e\u6027\u53ca\u4ea4\u4e92\u7684\u6d41\u7545\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u907f\u514d\u76d2\u5b50\u6a21\u578b\u8bef\u5dee<\/h2>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u76d2\u5b50\u5bbd\u5ea6\u8ba1\u7b97\u65f6\uff0c\u5f00\u53d1\u8005\u5e94\u5f53\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff0c\u907f\u514d\u56e0\u76d2\u5b50\u6a21\u578b\u8bef\u89e3\u800c\u5bfc\u81f4\u7684\u5e03\u5c40\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h3>\u91cd\u7f6eCSS\u6837\u5f0f<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528CSS\u91cd\u7f6e\uff08Normalize.css\u6216Reset.css\uff09\u6765\u786e\u4fdd\u5728\u4e0d\u540c\u6d4f\u89c8\u5668\u4e2d\u80fd\u591f\u62e5\u6709\u4e00\u81f4\u7684\u76d2\u5b50\u6a21\u578b\u8868\u73b0\u3002<\/p>\n<\/p>\n<p><h3>\u76d2\u5b50\u6a21\u578b\u8f6c\u6362<\/h3>\n<\/p>\n<p><p>\u7406\u89e3<code>box-sizing<\/code>\u5c5e\u6027\u5bf9\u4e8e\u5207\u6362\u4e0d\u540c\u76d2\u5b50\u6a21\u578b\u81f3\u5173\u91cd\u8981\uff0c\u5e76\u80fd\u591f\u6839\u636e\u8bbe\u8ba1\u9700\u6c42\u7075\u6d3b\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u5bf9\u76d2\u5b50\u6a21\u578b\u7684\u5bbd\u5ea6\u8ba1\u7b97\u65b9\u6cd5\u4ee5\u53ca\u5176\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u7684\u5e94\u7528\u8fdb\u884c\u8ba4\u77e5\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u52a0\u7cbe\u51c6\u5730\u8fdb\u884c\u9875\u9762\u5e03\u5c40\uff0c\u521b\u9020\u51fa\u65e2\u7f8e\u89c2\u53c8\u9ad8\u6548\u7684\u524d\u7aef\u8bbe\u8ba1\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>Q1: \u524d\u7aef\u5f00\u53d1\u65f6\u5982\u4f55\u8ba1\u7b97\u76d2\u5b50\u6a21\u578b\u7684\u5bbd\u5ea6\uff1f<\/strong><br \/>\nA1: \u524d\u7aef\u5f00\u53d1\u76d2\u5b50\u6a21\u578b\u7684\u5bbd\u5ea6\u8ba1\u7b97\u53ef\u4ee5\u91c7\u7528\u4e24\u79cd\u65b9\u6cd5\u3002\u4e00\u79cd\u662f\u901a\u8fc7CSS\u7684width\u5c5e\u6027\u76f4\u63a5\u8bbe\u7f6e\u76d2\u5b50\u7684\u5bbd\u5ea6\uff0c\u8fd9\u79cd\u65b9\u5f0f\u6bd4\u8f83\u7b80\u5355\uff0c\u53ef\u4ee5\u76f4\u63a5\u7ed9\u5b9a\u4e00\u4e2a\u5177\u4f53\u7684\u50cf\u7d20\u503c\u6216\u8005\u767e\u5206\u6bd4\u503c\u3002\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u901a\u8fc7\u76d2\u5b50\u7684\u5185\u5bb9\u5bbd\u5ea6\u3001\u5185\u8fb9\u8ddd\u548c\u8fb9\u6846\u5bbd\u5ea6\u8fdb\u884c\u8ba1\u7b97\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u53ef\u4ee5\u4f7f\u7528CSS\u7684\u5c5e\u6027box-sizing\u6765\u63a7\u5236\u76d2\u5b50\u7684\u5bbd\u5ea6\u8ba1\u7b97\u65b9\u5f0f\uff0c\u9ed8\u8ba4\u662fcontent-box\uff0c\u5373\u53ea\u8ba1\u7b97\u5185\u5bb9\u5bbd\u5ea6\uff0c\u4e0d\u5305\u62ec\u5185\u8fb9\u8ddd\u548c\u8fb9\u6846\u5bbd\u5ea6\u3002\u5982\u679c\u5c06box-sizing\u8bbe\u7f6e\u4e3aborder-box\uff0c\u5219\u8ba1\u7b97\u5bbd\u5ea6\u65f6\u4f1a\u5305\u62ec\u5185\u8fb9\u8ddd\u548c\u8fb9\u6846\u5bbd\u5ea6\u3002<\/p>\n<p><strong>Q2: \u5982\u4f55\u6839\u636e\u76d2\u5b50\u6a21\u578b\u7684\u5bbd\u5ea6\u81ea\u9002\u5e94\u5e03\u5c40\uff1f<\/strong><br \/>\nA2: \u5728\u524d\u7aef\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u5b9e\u73b0\u81ea\u9002\u5e94\u5e03\u5c40\uff0c\u5373\u4f7f\u5728\u4e0d\u540c\u8bbe\u5907\u4e0a\u90fd\u80fd\u5448\u73b0\u5408\u9002\u7684\u9875\u9762\u5e03\u5c40\u3002\u6839\u636e\u76d2\u5b50\u6a21\u578b\u7684\u5bbd\u5ea6\u81ea\u9002\u5e94\u5e03\u5c40\u53ef\u4ee5\u91c7\u7528\u4e00\u4e9b\u6280\u672f\u624b\u6bb5\u3002\u4e00\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528CSS\u7684\u767e\u5206\u6bd4\u503c\u6765\u8bbe\u7f6e\u76d2\u5b50\u5bbd\u5ea6\uff0c\u5982\u5c06\u7236\u5143\u7d20\u7684\u5bbd\u5ea6\u8bbe\u7f6e\u4e3a100%\uff0c\u5b50\u5143\u7d20\u7684\u5bbd\u5ea6\u8bbe\u7f6e\u4e3a50%\u3002\u8fd9\u6837\u5b50\u5143\u7d20\u4f1a\u6839\u636e\u7236\u5143\u7d20\u7684\u5bbd\u5ea6\u81ea\u52a8\u8c03\u6574\u5bbd\u5ea6\uff0c\u5b9e\u73b0\u81ea\u9002\u5e94\u3002\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528CSS\u7684flexbox\u5e03\u5c40\uff0c\u901a\u8fc7\u8bbe\u7f6e\u5f39\u6027\u5bb9\u5668\u7684flex\u5c5e\u6027\u6765\u5b9e\u73b0\u81ea\u9002\u5e94\u5e03\u5c40\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5a92\u4f53\u67e5\u8be2\u6765\u6839\u636e\u4e0d\u540c\u8bbe\u5907\u7684\u5bbd\u5ea6\u6dfb\u52a0\u5bf9\u5e94\u7684\u6837\u5f0f\uff0c\u5b9e\u73b0\u54cd\u5e94\u5f0f\u5e03\u5c40\u3002<\/p>\n<p><strong>Q3: \u5728\u54ea\u4e9b\u60c5\u51b5\u4e0b\u4f1a\u5bfc\u81f4\u76d2\u5b50\u6a21\u578b\u7684\u5bbd\u5ea6\u8ba1\u7b97\u4e0d\u51c6\u786e\uff1f<\/strong><br \/>\nA3: \u76d2\u5b50\u6a21\u578b\u7684\u5bbd\u5ea6\u8ba1\u7b97\u53ef\u80fd\u4f1a\u56e0\u4e3a\u4e00\u4e9b\u56e0\u7d20\u5bfc\u81f4\u4e0d\u51c6\u786e\u3002\u5176\u4e2d\u4e00\u4e2a\u56e0\u7d20\u662f\u4f7f\u7528\u4e86\u6d6e\u52a8\u6216\u8005\u7edd\u5bf9\u5b9a\u4f4d\u7684\u5143\u7d20\u3002\u6d6e\u52a8\u548c\u7edd\u5bf9\u5b9a\u4f4d\u7684\u5143\u7d20\u8131\u79bb\u4e86\u6587\u6863\u6d41\uff0c\u4e0d\u4f1a\u5bf9\u5176\u4ed6\u5143\u7d20\u7684\u4f4d\u7f6e\u548c\u5c3a\u5bf8\u4ea7\u751f\u5f71\u54cd\uff0c\u6240\u4ee5\u5728\u8ba1\u7b97\u76d2\u5b50\u7684\u5bbd\u5ea6\u65f6\uff0c\u8fd9\u4e9b\u5143\u7d20\u4e0d\u4f1a\u88ab\u8ba1\u7b97\u5728\u5185\u3002\u8fd8\u6709\u4e00\u4e2a\u56e0\u7d20\u662f\u4f7f\u7528\u4e86\u76d2\u5b50\u6a21\u578b\u7684box-sizing\u5c5e\u6027\u5e76\u8fdb\u884c\u4e86\u4fee\u6539\uff0c\u5c06\u5176\u503c\u8bbe\u7f6e\u4e3aborder-box\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u8ba1\u7b97\u76d2\u5b50\u7684\u5bbd\u5ea6\u65f6\u4f1a\u5305\u62ec\u5185\u8fb9\u8ddd\u548c\u8fb9\u6846\u5bbd\u5ea6\uff0c\u4e0e\u9ed8\u8ba4\u7684content-box\u8ba1\u7b97\u65b9\u5f0f\u4e0d\u540c\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8ba1\u7b97\u7ed3\u679c\u4e0d\u51c6\u786e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u76d2\u5b50\u6a21\u578b\u7684\u5bbd\u5ea6\u8ba1\u7b97\u4f9d\u6258\u4e8eCSS\u7684\u76d2\u6a21\u578b\u6982\u5ff5\uff0c\u5176\u57fa\u672c\u7ec4\u6210\u5305\u62ec\u5185\u5bb9\uff08content\uff09\u3001\u5185\u8fb9\u8ddd\uff08padding\uff09\u3001\u8fb9 [&hellip;]","protected":false},"author":3,"featured_media":159577,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/159568"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=159568"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/159568\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/159577"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=159568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=159568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=159568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}