{"id":28435,"date":"2024-11-24T17:40:35","date_gmt":"2024-11-24T09:40:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28435\/"},"modified":"2024-11-24T17:40:35","modified_gmt":"2024-11-24T09:40:35","slug":"pain%ef%bc%9acss-%e7%9a%84%e5%8f%a6%e4%b8%80%e4%b8%aa%e6%95%85%e4%ba%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28435\/","title":{"rendered":"PAIN\uff1aCSS \u7684\u53e6\u4e00\u4e2a\u6545\u4e8b"},"content":{"rendered":"<h2> \uff0c\u5373\u5c42\u53e0\u6837\u5f0f\u8868\uff0c\u662f\u7f51\u7edc\u7684\u57fa\u77f3\u6280\u672f\uff0c\u8d1f\u8d23\u7f51\u9875\u7684\u89c6\u89c9\u5448\u73b0\u3002\u867d\u7136\u5b83\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u4f46\u8bb8\u591a\u5f00\u53d1\u4eba\u5458\u53d1\u73b0\u7f16\u5199 css \u662f\u4e00\u79cd\u5177\u6709\u6311\u6218\u6027\uff0c\u6709\u65f6\u751a\u81f3\u4ee4\u4eba\u6cae\u4e27\u7684\u7ecf\u5386\u3002 <\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173223828541900.jpg\" class=\"aligncenter\" title=\"PAIN\uff1aCSS \u7684\u53e6\u4e00\u4e2a\u6545\u4e8b\u63d2\u56fe\" alt=\"PAIN\uff1aCSS \u7684\u53e6\u4e00\u4e2a\u6545\u4e8b\u63d2\u56fe\" \/><\/p>\n<p><strong>\u8ba9\u6211\u4eec\u63a2\u8ba8\u4e00\u4e9b\u8ba9 css \u6210\u4e3a\u8bb8\u591a\u4eba\u5934\u75db\u7684\u5e38\u89c1\u75db\u70b9<\/strong><\/p>\n<p><strong>1.<\/strong><strong>\u6d4f\u89c8\u5668\u652f\u6301\u4e0d\u4e00\u81f4<\/strong><br \/><em>css \u5728\u4e0d\u540c\u6d4f\u89c8\u5668\u4e2d\u7684\u5448\u73b0\u65b9\u5f0f\u53ef\u80fd\u6709\u6240\u4e0d\u540c\uff1b\u4f7f\u7528\u7279\u5b9a\u4e8e\u6d4f\u89c8\u5668\u7684\u524d\u7f00\u548c autoprefixer \u7b49\u5de5\u5177\u6765\u786e\u4fdd\u517c\u5bb9\u6027\u3002<\/em><\/p>\n<pre>.example {\n  -webkit-border-radius: 5px; \/* webkit browsers (e.g., chrome, safari) *\/\n  border-radius: 5px; \/* standard property *\/\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2.<\/strong><strong>\u7279\u5f02\u6027\u6218\u4e89<\/strong><br \/><em>\u8fc7\u4e8e\u5177\u4f53\u7684\u9009\u62e9\u5668\u53ef\u80fd\u4f1a\u8986\u76d6\u66f4\u901a\u7528\u7684\u9009\u62e9\u5668\uff0c\u4ece\u800c\u5bfc\u81f4\u610f\u5916\u7684\u7ed3\u679c\uff1b\u4f7f\u7528\u4e0d\u592a\u5177\u4f53\u7684\u9009\u62e9\u5668\u5e76\u907f\u514d\u5185\u8054\u6837\u5f0f\u3002<\/em><\/p>\n<p><strong>3.<\/strong><strong>\u5e03\u5c40\u6311\u6218<\/strong><br \/><em>\u521b\u5efa\u590d\u6742\u7684\u5e03\u5c40\u53ef\u80fd\u5f88\u56f0\u96be\uff1b<br \/> \u4f7f\u7528 flexbox \u548c grid \u7b49\u73b0\u4ee3\u5e03\u5c40\u6280\u672f<\/em><\/p>\n<pre>.container {\n  display: flex;\n  justify-content: center; \/* horizontal centering *\/\n  align-items: center; \/* vertical centering *\/\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4.<\/strong><strong>\u54cd\u5e94\u5f0f\u8bbe\u8ba1<\/strong><br \/><em>\u786e\u4fdd\u7f51\u7ad9\u5728\u6240\u6709\u8bbe\u5907\u4e0a\u770b\u8d77\u6765\u90fd\u4e0d\u9519\u3002\u6b64\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848\u4f7f\u7528\u5a92\u4f53\u67e5\u8be2\u8c03\u6574\u4e0d\u540c\u5c4f\u5e55\u5c3a\u5bf8\u7684\u6837\u5f0f<\/em><\/p>\n<pre>@media (max-width: 600px) {\n  .container {\n    flex-direction: column;\n  }\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5.<\/strong><strong>\u8c03\u8bd5 css<\/strong><br \/><em>css \u95ee\u9898\u53ef\u80fd\u5f88\u5fae\u5999\u4e14\u96be\u4ee5\u8ffd\u8e2a\uff0c<br \/> \u4f7f\u7528\u6d4f\u89c8\u5668\u5f00\u53d1\u5de5\u5177\u6765\u68c0\u67e5\u548c\u8c03\u8bd5\u6837\u5f0f\uff1bchrome devtools \u7b49\u5de5\u5177\u975e\u5e38\u6709\u5e2e\u52a9\u3002<\/em><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173223828586090.jpg\" class=\"aligncenter\" title=\"PAIN\uff1aCSS \u7684\u53e6\u4e00\u4e2a\u6545\u4e8b\u63d2\u56fe1\" alt=\"PAIN\uff1aCSS \u7684\u53e6\u4e00\u4e2a\u6545\u4e8b\u63d2\u56fe1\" \/><\/p>\n<p>6.<strong>\u6027\u80fd\u95ee\u9898<\/strong><br \/><em>\u5927\u578b\u3001\u672a\u4f18\u5316\u7684 css \u6587\u4ef6\u4f1a\u51cf\u6162\u9875\u9762\u52a0\u8f7d\u65f6\u95f4\uff1b\u7f29\u5c0f css \u6587\u4ef6\u5e76\u4f7f\u7528 cssnano \u7b49\u5de5\u5177\u5bf9\u5176\u8fdb\u884c\u4f18\u5316\u3002<\/em><br \/><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173223828538929.jpg\" class=\"aligncenter\" title=\"PAIN\uff1aCSS \u7684\u53e6\u4e00\u4e2a\u6545\u4e8b\u63d2\u56fe2\" alt=\"PAIN\uff1aCSS \u7684\u53e6\u4e00\u4e2a\u6545\u4e8b\u63d2\u56fe2\" \/><\/p>\n<p><strong>7.<\/strong><strong>\u91cd\u53e0\u5143\u7d20<\/strong><br \/><em>\u5143\u7d20\u610f\u5916\u91cd\u53e0\uff1b\u4f7f\u7528 z-index \u5c5e\u6027\u63a7\u5236\u5806\u53e0\u987a\u5e8f\u3002<\/em><\/p>\n<pre>\n.element1 {\n  z-index: 2;\n}\n.element2 {\n  z-index: 1;\n}\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>8.<\/strong> \u4e0d\u9700\u8981\u7684\u6587\u672c\u6362\u884c<br \/><em>\u5143\u7d20\u5185\u7684\u6587\u672c\u610f\u5916\u6362\u884c\uff1b\u4f7f\u7528\u7a7a\u767d\u5c5e\u6027\u6765\u63a7\u5236\u6587\u672c\u6362\u884c\u3002<\/em><\/p>\n<pre>.no-wrap {\n  white-space: nowrap; \/* prevent text from wrapping *\/\n}\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>9.<\/strong> <strong>\u5b57\u4f53\u5927\u5c0f\u4e0d\u4e00\u81f4<\/strong><br \/><em>\u5728\u4e0d\u540c\u5143\u7d20\u4e4b\u95f4\u5b9e\u73b0\u4e00\u81f4\u7684\u5b57\u4f53\u5927\u5c0f\uff1b\u4f7f\u7528 rem \u5355\u4f4d\u4f7f\u5b57\u4f53\u5927\u5c0f\u76f8\u5bf9\u4e8e\u6839\u5143\u7d20\u3002<\/em><\/p>\n<pre>body {\n  font-size: 16px; \/* define a base font size *\/\n}\nh1 {\n  font-size: 2rem; \/* twice the base font size *\/\n}\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>10.<\/strong> <strong>\u5185\u5bb9\u6ea2\u51fa<\/strong><br \/><em>\u5185\u5bb9\u53ef\u80fd\u4f1a\u6ea2\u51fa\u5176\u5bb9\u5668\uff1b\u4f7f\u7528\u6ea2\u51fa\u5c5e\u6027\u6765\u63a7\u5236\u5982\u4f55\u5904\u7406\u6ea2\u51fa\u3002<\/em><\/p>\n<pre>.overflow-container {\n  overflow: hidden; \/* hide overflowing content *\/\n}\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>11\u3002\u56fe\u50cf\u7f29\u653e<\/strong><br \/><em>\u56fe\u50cf\u53ef\u80fd\u65e0\u6cd5\u6b63\u786e\u7f29\u653e\u6216\u4fdd\u6301\u5176\u7eb5\u6a2a\u6bd4\uff1b\u4f7f\u7528 max-width \u5c5e\u6027\u786e\u4fdd\u56fe\u50cf\u6309\u6bd4\u4f8b\u7f29\u653e\u3002<\/em><\/p>\n<pre>img{\n  max-width: 100%; \/* Scale images proportionally within their containers *\/\n  height: auto; \/* Maintain the aspect ratio *\/\n}\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7ed3\u8bba<\/strong><br \/><em>\u5c3d\u7ba1\u9762\u4e34\u8fd9\u4e9b\u6311\u6218\uff0ccss \u4ecd\u7136\u662f web \u5f00\u53d1\u4eba\u5458\u7684\u4e00\u9879\u57fa\u672c\u6280\u80fd\u3002\u514b\u670d\u75db\u70b9\u7684\u5173\u952e\u662f\u4e0d\u65ad\u5b66\u4e60\u548c\u5b9e\u8df5\u3002<\/em><br \/><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173223828585406.jpg\" class=\"aligncenter\" title=\"PAIN\uff1aCSS \u7684\u53e6\u4e00\u4e2a\u6545\u4e8b\u63d2\u56fe3\" alt=\"PAIN\uff1aCSS \u7684\u53e6\u4e00\u4e2a\u6545\u4e8b\u63d2\u56fe3\" \/><\/p>\n<h2> \u8bf7\u70b9\u8d5e\u5e76\u5173\u6ce8\u6211\uff0c\u6b22\u8fce\u8bc4\u8bba\u3001\u5efa\u8bae\u548c\u201c\u5efa\u8bbe\u6027\u6279\u8bc4\u201d <\/h2>\n<p>\u4ee5\u4e0a\u5c31\u662fPAIN\uff1aCSS \u7684\u53e6\u4e00\u4e2a\u6545\u4e8b\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>\uff0c\u5373\u5c42\u53e0\u6837\u5f0f\u8868\uff0c\u662f\u7f51\u7edc\u7684\u57fa\u77f3\u6280\u672f\uff0c\u8d1f\u8d23\u7f51\u9875\u7684\u89c6\u89c9\u5448\u73b0\u3002\u867d\u7136\u5b83\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u4f46\u8bb8\u591a\u5f00\u53d1\u4eba\u5458\u53d1\u73b0\u7f16\u5199 css \u662f\u4e00\u79cd\u5177\u6709\u6311\u6218\u6027\uff0c\u6709\u65f6\u751a\u81f3\u4ee4\u4eba\u6cae\u4e27\u7684\u7ecf\u5386\u3002 \u8ba9\u6211\u4eec\u63a2\u8ba8\u4e00\u4e9b\u8ba9 css \u6210\u4e3a\u8bb8\u591a\u4eba\u5934\u75db\u7684\u5e38\u89c1\u75db\u70b9 1.\u6d4f\u89c8\u5668\u652f\u6301\u4e0d\u4e00\u81f4css \u5728\u4e0d\u540c\u6d4f\u89c8\u5668\u4e2d\u7684\u5448\u73b0\u65b9\u5f0f\u53ef\u80fd\u6709\u6240\u4e0d\u540c\uff1b\u4f7f\u7528\u7279\u5b9a\u4e8e\u6d4f\u89c8\u5668\u7684\u524d\u7f00\u548c autoprefixer \u7b49\u5de5\u5177\u6765\u786e\u4fdd\u517c\u5bb9\u6027\u3002 .example { -webkit-border-radius: 5px; \/* webkit browsers (e.g., chrome, safari) *\/ border-radius: 5px; \/* standard property *\/ } \u767b\u5f55\u540e\u590d\u5236 2.\u7279\u5f02\u6027\u6218\u4e89\u8fc7\u4e8e\u5177\u4f53\u7684\u9009\u62e9\u5668\u53ef\u80fd\u4f1a\u8986\u76d6\u66f4\u901a\u7528\u7684\u9009\u62e9\u5668\uff0c\u4ece\u800c\u5bfc\u81f4\u610f\u5916\u7684\u7ed3\u679c\uff1b\u4f7f\u7528\u4e0d\u592a\u5177\u4f53\u7684\u9009\u62e9\u5668\u5e76\u907f\u514d\u5185\u8054\u6837\u5f0f\u3002 3.\u5e03\u5c40\u6311\u6218\u521b\u5efa\u590d\u6742\u7684\u5e03\u5c40\u53ef\u80fd\u5f88\u56f0\u96be\uff1b \u4f7f\u7528 flexbox \u548c grid \u7b49\u73b0\u4ee3\u5e03\u5c40\u6280\u672f .container { display: flex; justify-content: center; \/* horizontal centering *\/ align-items: center; \/* vertical centering *\/ } \u767b\u5f55\u540e\u590d\u5236 4.\u54cd\u5e94\u5f0f\u8bbe\u8ba1\u786e\u4fdd\u7f51\u7ad9\u5728\u6240\u6709\u8bbe\u5907\u4e0a\u770b\u8d77\u6765\u90fd\u4e0d\u9519\u3002\u6b64\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848\u4f7f\u7528\u5a92\u4f53\u67e5\u8be2\u8c03\u6574\u4e0d\u540c\u5c4f\u5e55\u5c3a\u5bf8\u7684\u6837\u5f0f [&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-28435","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28435","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=28435"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28435\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}