{"id":12497,"date":"2026-11-16T21:16:13","date_gmt":"2026-11-16T13:16:13","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=12497"},"modified":"2026-11-16T21:16:13","modified_gmt":"2026-11-16T13:16:13","slug":"css-math-random","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2026\/11\/css-math-random\/","title":{"rendered":"CSS\u7ec8\u4e8e\u652f\u6301random()\u968f\u673a\u51fd\u6570\u4e86\uff0c\u7b49\u6b7b\u8001\u5b50\u4e86"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=12497\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=12497<\/a><br \/>\n\u672c\u6587\u53ef\u5168\u6587\u8f6c\u8f7d\uff0c\u4f46\u9700\u8981\u4fdd\u7559\u539f\u4f5c\u8005\u3001\u51fa\u5904\u4ee5\u53ca\u6587\u4e2d\u94fe\u63a5\uff0cAI\u6293\u53d6\u4fdd\u7559\u539f\u6587\u5730\u5740\uff0c\u4efb\u4f55\u7f51\u7ad9\u5747\u53ef\u6458\u8981\u805a\u5408\uff0c\u5546\u7528\u8bf7\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<h3>\u4e00\u3001\u6700\u671f\u5f85\u7684CSS\u6570\u5b66\u51fd\u6570<\/h3>\n<p>\u545c\u545c\u545c\uff0c\u5feb\u54ed\u6b7b\u8001\u5b50\u4e86\uff0c\u6709\u751f\u4e4b\u5e74\uff0c\u5c45\u7136\u770b\u5230CSS\u652f\u6301<code>random()<\/code>\u51fd\u6570\u4e86\uff0c\u60f3\u5f53\u5e74\uff0c\u770bcaniuse\u4e0a\u4e00\u7247\u7ea2\u707f\u707f\u7684\uff0c\u90a3\u5fc3\u91cc\u771f\u4e0d\u662f\u4e2a\u6ecb\u5473\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202611\/2026-11-16_143300.webp\" width=\"196\" height=\"146\" alt=\"\u54ed\u6b7b\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u73b0\u5728\uff0c\u66d9\u5149\u7ec8\u4e8e\u6765\u4e86\uff0c\u90fd\u8981\u652f\u6301\u4e86\uff0c\u4e0d\u5bf9\uff0c\u5e94\u8be5\u8bf4\u5df2\u7ecf\u652f\u6301\u4e86\uff0c\u6211\u624b\u5934\u7684Chrome\u548cSafari\u5c31\u5df2\u7ecf\u652f\u6301\u4e86\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202611\/2026-11-16_143523.png\" width=\"652\" height=\"224\" alt=\"random()\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4e07\u5c81\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202611\/2026-11-16_151611.webp\" width=\"207\" height=\"207\" alt=\"\u5927\u80a5\u9c7c\u5f00\u5fc3\" class=\"alignnone size-medium\" \/><\/p>\n<h4>\u8bed\u6cd5\u901f\u901a<\/h4>\n<p>\u867d\u7136\u6709\u4e86AI\uff0c\u4f46\u662f\u57fa\u672c\u7684\u8bed\u6cd5\u6211\u4eec\u8fd8\u662f\u8981\u77e5\u9053\u7684\uff0c\u4e0d\u7136\u770b\u5230AI\u751f\u6210\u7684\u4ee3\u7801\u90fd\u662f\u4e00\u8138\u61f5\u903c\u3002<\/p>\n<p><span class=\"s\">\u5185\u5fc3OS\uff1a\u867d\u7136\u76ee\u524d\u5927\u80a5\u9c7c\u3001Kimi\u5a18\u3001\u72d0\u72f8\u5a18\u90fd\u4e0d\u592a\u53ef\u80fd\u4e3b\u52a8\u4f7f\u7528<code>random()<\/code>\u51fd\u6570\uff0c\u5927\u5c0f\u59d0\u5012\u662f\u6709\u4e9b\u53ef\u80fd\u6027\u3002<\/span><\/p>\n<pre>random(seed?, min, max, step?)<\/pre>\n<p>\u53c2\u6570\u540e\u9762\u8ddf\u7740\u95ee\u53f7\u8868\u793a\u53ef\u9009\uff0c\u8bf4\u660e<code>min<\/code>\u548c<code>max<\/code>\u662f\u5fc5\u586b\u7684\u3002<\/p>\n<p><strong>\u4e00\u4e9b\u4f7f\u7528\u793a\u610f\uff1a<\/strong><\/p>\n<pre>\/* \u57fa\u672c\u4f7f\u7528 *\/\r\nrandom(0, 100)\r\nrandom(10px, 500px)\r\nrandom(0deg, 360deg)\r\n\r\n\/* \u6b65\u9636\u95f4\u9694 *\/\r\nrandom(0, 100, 10)\r\nrandom(0rad, 1turn, 30deg)\r\n\r\n\/* \u4f7f\u7528\u968f\u673a\u5173\u952e\u5b57 *\/\r\nrandom(auto, 0, 360)\r\nrandom(element-scoped, 0s, 5s)\r\nrandom(property-scoped, 0s, 5s)\r\nrandom(property-index-scoped, 0s, 5s)\r\nrandom(--unique-base, 400px, 100px)\r\nrandom(fixed 0.5, 1em, 40vw)  \/* \u8fd9\u4e2aChrome\u6682\u4e0d\u652f\u6301 *\/\r\nrandom(--unique-base property-scoped, 100dpi, 300dpi)\r\n\r\n\/* \u4f7f\u7528\u968f\u673a\u5173\u952e\u5b57\u548c\u6b65\u9636\u95f4\u9694 *\/\r\nrandom(property-scoped, 0deg, 360deg, 45deg)\r\nrandom(--my-base, 1em, 3rem, 2px)<\/pre>\n<h3>\u4e8c\u3001\u8bed\u6cd5\u901f\u901a \u00b7 \u771f<\/h3>\n<p>\u57fa\u672c\u4f7f\u7528\u6ca1\u4ec0\u4e48\u597d\u8bf4\u7684\uff0c\u5c31\u662f\u524d\u540e\u5355\u4f4d\u7684\u6027\u8d28\u8981\u4e00\u6837\u3002<\/p>\n<p>\u6ce8\u610f\uff0c\u76f8\u540c\u7684\u662f\u524d\u540e\u5355\u4f4d\u7684\u300c\u6027\u8d28\u300d\uff0c\u5e76\u4e0d\u4e00\u5b9a\u975e\u5f97\u662f\u76f8\u540c\u7684\u5355\u4f4d\u3002<\/p>\n<p>\u4f8b\u5982\u4e0b\u9762\u7684\u7528\u6cd5\u4e5f\u662f\u5408\u6cd5\u7684\uff0c<code>20deg<\/code>\u548c<code>1turn<\/code>\u90fd\u5c5e\u4e8e\u89d2\u5ea6\u5355\u4f4d\u503c\uff1a<\/p>\n<pre>img {\r\n  rotate: random(20deg, 1turn);\r\n}<\/pre>\n<p><code>random()<\/code>\u51fd\u6570\u6bd4\u8f83\u96be\u7406\u89e3\u7684\u5c31\u662f\u524d\u9762\u7684\u968f\u673a\u5173\u952e\u5b57\u3002<\/p>\n<p>\u8fd9\u4e1c\u897f\u8fd8\u662f\u633a\u6709\u7528\u7684\u3002<\/p>\n<p>\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u9ed8\u8ba4\uff08\u7701\u7565 key\uff0c\u6548\u679c\u540c<code>property-index-scoped<\/code>\uff09\u3002\u6bcf\u4e2a\u5143\u7d20\u3001\u6bcf\u4e2a\u5c5e\u6027\u5404\u81ea\u72ec\u7acb\u968f\u673a\uff0c\u4e92\u4e0d\u5f71\u54cd\u3002<\/li>\n<li><strong>element-scoped<\/strong>\u3002\u8ba9\u6240\u6709\u5339\u914d\u540c\u4e00\u89c4\u5219\u7684\u5143\u7d20\u5171\u4eab\u540c\u4e00\u4e2a\u968f\u673a\u8ba1\u7b97\u7ed3\u679c\uff0c\u4fdd\u6301\u98ce\u683c\u7edf\u4e00\u3002<\/li>\n<li><strong>property-scoped<\/strong>\u3002\u5728\u540c\u4e00\u4e2a\u5c5e\u6027\u58f0\u660e\u4e2d\u590d\u7528\u968f\u673a\u503c\u3002<\/li>\n<li><strong>\u81ea\u5b9a\u4e49\u6807\u8bc6\u7b26\uff08\u5982 &#8211;size\uff09<\/strong>\u3002\u51e1\u662f\u4f20\u5165\u76f8\u540c\u81ea\u5b9a\u4e49\u540d\u79f0\u7684 <code>random()<\/code> \u8c03\u7528\uff0c\u65e0\u8bba\u51fa\u73b0\u5728\u54ea\u4e2a\u5c5e\u6027\u6216\u5143\u7d20\u4e0a\uff0c\u90fd\u4f1a\u5171\u4eab\u540c\u4e00\u4e2a\u968f\u673a\u6570\u3002<\/li>\n<li><code>fixed &lt;number&gt;<\/code>\u3002\u57fa\u4e8e\u79cd\u5b50\u6570\u503c\uff080~1\uff09\u751f\u6210\u56fa\u5b9a\u968f\u673a\u6570\uff0c\u6bcf\u6b21\u5237\u65b0\u90fd\u662f\u8fd9\u4e2a\u968f\u673a\u503c\u3002<\/li>\n<\/ul>\n<h4>\u901a\u8fc7\u6848\u4f8b\u5b66\u4e60<\/h4>\n<p>\u8ba9\u6211\u60f3\u60f3\u7528\u4ec0\u4e48\u6848\u4f8b\u5e2e\u52a9\u5927\u5bb6\u5b66\u4e60\u2026\u2026<\/p>\n<p>\u6709\u4e86\uff0c\u56fe\u7247\u7684\u5706\u89d2\u5427\u3002<\/p>\n<p>\u5706\u89d2\u6709\u56db\u4e2a\u89d2\uff0c\u8fd8\u6709\u5185\u5916\u5706\u89d2\u533a\u5206\uff0c\u6700\u9002\u5408\u6f14\u793a\u4e86\u3002<\/p>\n<p>\u4e14\u770b\u9ed8\u8ba4\u6548\u679c\uff1a<\/p>\n<pre>img {\r\n    border-radius:\r\n        random(16px, 96px) random(16px, 96px)\r\n        random(16px, 96px) random(16px, 96px);\r\n}<\/pre>\n<p>\u6b64\u65f6\uff0c\u6bcf\u4e2a\u56fe\u7247\u7684\u6bcf\u4e2a\u5706\u89d2\u5927\u5c0f\u90fd\u662f\u968f\u673a\u7684\u3002<\/p>\n<p>\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202611\/2026-11-16_171846.webp\" width=\"535\" height=\"210\" alt=\"\u968f\u673a\u5706\u89d2\u6548\u679c\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5982\u679c\u662f<code>element-scoped<\/code>\u8bed\u6cd5\u4ee3\u7801\uff1a<\/p>\n<pre>img {\r\n    border-radius:\r\n        random(element-scoped, 16px, 96px) random(element-scoped, 16px, 96px)\r\n        random(element-scoped, 16px, 96px) random(element-scoped, 16px, 96px);\r\n}<\/pre>\n<p>\u90a3\u4e48\u540c\u4e00\u4e2a\u56fe\u7247\u7684\u56db\u4e2a\u5706\u89d2\u5927\u5c0f\u662f\u4e00\u6837\uff0c\u4f46\u662f\u4e0d\u540c\u7684\u56fe\u7247\uff08\u867d\u7136\u516c\u7528\u4e00\u4e2a\u9009\u62e9\u5668\uff09\u4e4b\u95f4\u7684\u5706\u89d2\u662f\u968f\u673a\u7684\uff0c\u5c31\u50cf\u4e0b\u56fe\u8fd9\u822c\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202611\/2026-11-16_201526.webp\" width=\"569\" height=\"215\" alt=\"element-scoped\u4f5c\u7528\u533a\u522b\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u81f3\u4e8e<strong>property-scoped<\/strong>\u548c\u81ea\u5b9a\u4e49\u6807\u8bc6\u7b26\uff0c\u5219\u9700\u8981\u5bf9\u6bd4\u6548\u679c\u624d\u80fd\u89c1\u771f\u7ae0\u3002<\/p>\n<p>\u5982\u679c\u662f<strong>property-scoped<\/strong>\uff0c\u90a3\u4e48\u4e0d\u540c\u5143\u7d20\u4e4b\u95f4\u540c\u4e00\u4e2a\u5c5e\u6027\u7684\u5706\u89d2\u968f\u673a\u5927\u5c0f\u662f\u4e00\u6837\u7684\u3002\u800c\u4f7f\u7528\u81ea\u5b9a\u4e49\u6807\u8bc6\u7b26\uff0c\u65e0\u8bba\u54ea\u4e2a\u5143\u7d20\u3001\u54ea\u4e2a\u5c5e\u6027\uff0c\u90fd\u4f7f\u7528\u4e00\u6837\u7684\u968f\u673a\u503c\u3002<\/p>\n<p>\u4e14\u770b\u4e0b\u9762\u7684\u5bf9\u6bd4\u4ee3\u7801\uff1a<\/p>\n<pre>img {\r\n    border-radius: random(property-scoped, 16px, 96px) \/ random(property-scoped, 16px, 96px);\r\n    \/* \u4e24\u5c42\u906e\u7f69\uff1a\u6574\u56fe\u51cf\u53bb\u5c45\u4e2d\u7684\u5c0f\u65b9\u5757\uff0c\u56fe\u7247\u4e2d\u95f4\u5373\u88ab\u6316\u7a7a *\/\r\n    mask: linear-gradient(#000 0 0) exclude, linear-gradient(#000 0 0) center no-repeat;\r\n    mask-size: 100% 100%, random(property-scoped, 16px, 96px) random(property-scoped, 16px, 96px);\r\n}\r\n\r\nimg {\r\n    border-radius: random(--size, 16px, 96px) \/ random(--size, 16px, 96px);\r\n    mask: linear-gradient(#000 0 0) exclude, linear-gradient(#000 0 0) center no-repeat;\r\n    mask-size: 100% 100%, random(--size, 16px, 96px) random(--size, 16px, 96px);\r\n}<\/pre>\n<p>\u524d\u8005\u901a\u8fc7<code>mask<\/code>\u906e\u7f69\u4ea7\u751f\u7684\u9542\u7a7a\u65b9\u683c\u7684\u5927\u5c0f\u548c<code>border-radius<\/code>\u662f\u6ca1\u6709\u5173\u8054\u7684\uff0c\u56e0\u4e3a\u968f\u673a\u503c\u53ea\u4e0e\u5c5e\u6027\u76f8\u5173\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202611\/2026-11-16_202539.webp\" width=\"532\" height=\"209\" alt=\"\u5706\u89d2\u548c\u906e\u7f69\u5c3a\u5bf8\u65e0\u5173\u8054\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4f46\u662f\u540e\u8005\u9542\u7a7a\u7684\u65b9\u683c\u5927\u5c0f\u5219\u662f\u548c<code>border-radius<\/code>\u4fdd\u6301\u4e00\u81f4\uff0c\u5706\u89d2\u8d8a\u5927\uff0c\u6316\u7a7a\u7684\u65b9\u5f62\u8d8a\u5927\uff0c\u5706\u89d2\u8d8a\u5c0f\uff0c\u7a7a\u683c\u4e5f\u5c31\u8d8a\u5c0f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202611\/2026-11-16_202735.webp\" width=\"535\" height=\"225\" alt=\"\u5706\u89d2\u548c\u9542\u7a7a\u9762\u79ef\u76f8\u5173\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u81f3\u4e8e<code>fixed<\/code>\u6570\u503c\u8bed\u6cd5\uff0c\u8fd9\u4e2a\u5c31\u6bd4\u8f83\u597d\u7406\u89e3\u4e86\uff0c\u7ed9\u5b9a\u4e00\u4e2a0~1\u4e4b\u95f4\u7684\u79cd\u5b50\u8ba1\u6570\u503c\uff0c\u8fd4\u56de\u4e00\u4e2a\u6bcf\u6b21\u5237\u65b0\u90fd\u4e0d\u53d8\u7684\u968f\u673a\u503c\uff1a<\/p>\n<pre>random(fixed 0.25, 16px, 96px)<\/pre>\n<p>\u8fd9\u8ba9\u6211\u60f3\u8d77\u4e86\u6211\u4ee5\u524d\u505a\u8fc7\u7684\u4e00\u4e2a\u9700\u6c42\uff0c\u4e00\u5806\u7d20\u6750\u5217\u8868\u9700\u8981\u968f\u673a\u6392\u5217\uff0c\u4f46\u662f\u6bcf\u4e00\u4e2a\u7528\u6237\u7684\u663e\u793a\u987a\u5e8f\u53c8\u662f\u56fa\u5b9a\u7684\uff0c\u5c31\u57fa\u4e8e\u7528\u6237\u7684userid\u751f\u6210\u4e86\u4e00\u4e2a\u56fa\u5b9a\u7684\u968f\u673a\u6392\u5e8f\u7b97\u6cd5\u3002<\/p>\n<p>\u611f\u89c9\u4e0e\u8fd9\u4e2a\u7c7b\u4f3c\u3002<\/p>\n<h4>\u773c\u89c1\u4e3a\u5b9e<\/h4>\n<p>\u4e3a\u4e86\u65b9\u4fbf\u5927\u5bb6\u5b66\u4e60\uff0c\u4e0a\u9762\u7684\u793a\u4f8b\u6211\u4e13\u95e8\u5f04\u4e86\u4e2a\u6f14\u793a\u9875\u9762\uff0c\u611f\u8c22\u5927\u80a5\u9c7c\uff0c\u7c73\u996d\u6ca1\u767d\u5403\uff0c\u867d\u7136\u524d\u524d\u540e\u540e\u8c03\u6574\u4e86\u5f88\u591a\u4e2a\u7248\u672c\uff0c\u7ec8\u4e8e\u662f\u6ee1\u610f\u63d0\u4ea4\u4e86\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/202611\/css-random-key-demo.php\" rel=\"noopener\" target=\"_blank\">CSS random()\u51fd\u6570\u5173\u952e\u5b57\u4f5c\u7528\u5bf9\u6bd4demo<\/a><\/p>\n<h3>\u4e09\u3001\u8981\u4e0d\u6765\u70b9\u66f4\u5b9e\u9645\u7684\u5e94\u7528<\/h3>\n<p>\u4ee5\u4e0b\u6848\u4f8b\u57fa\u4e8eCSS <code>random()<\/code>\u751f\u6210\u7684\u968f\u673a\u5927\u5c0f\u548c\u4f4d\u7f6e\u7684\u661f\u70b9\u80cc\u666f\u56fe\uff0c\u662f\u4f7f\u7528\u54c8\u57fa\u7c73\uff08Gemini\uff09\u751f\u6210\u7684\u3002<\/p>\n<p>iframe\u5b9e\u65f6\u6e32\u67d3\uff08RSS\u8ba2\u9605\u6ca1\u6709\u6548\u679c\uff0c\u53ef\u4ee5<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=12497\">\u8fd4\u56de\u539f\u6587<\/a>\u67e5\u770b\uff09\uff0c\u70b9\u51fb\u6309\u94ae\u53ef\u4ee5\u5237\u65b0\u3002<\/p>\n<p><iframe id=\"randomFrame\" style=\"border:0\" height=\"500\" width=\"100%\"><\/iframe><\/p>\n<p><script>document.getElementById('randomFrame').srcdoc = `<!DOCTYPE html><html lang=\"zh-CN\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0\"><title>CSS random() \u591a\u5c42\u968f\u673a\u80cc\u666f Demo<\/title><\/p>\n<style>*{box-sizing:border-box;margin:0;padding:0}body{min-height:100vh;display:grid;place-items:center;background-color:#090d16;font-family:system-ui,-apple-system,sans-serif;color:#e2e8f0}.starfield-card{width:min(90vw,680px);height:400px;border-radius:16px;border:1px solid rgba(255,255,255,.12);display:grid;place-items:center;text-align:center;padding:24px;box-shadow:0 20px 50px rgba(0,0,0,.5);background:linear-gradient(135deg,#0f172a 0%,#1e1b4b 100%)}@supports (width:random(1px,2px)){.starfield-card{background-image:radial-gradient(circle random(2px,5px) at random(5%,95%) random(5%,95%),rgba(253,224,71,random(.4,.95)) 0%,transparent 100%),radial-gradient(circle random(1px,4px) at random(5%,95%) random(5%,95%),rgba(255,255,255,random(.5,1)) 0%,transparent 100%),radial-gradient(circle random(2px,6px) at random(5%,95%) random(5%,95%),rgba(125,211,252,random(.3,.9)) 0%,transparent 100%),radial-gradient(circle random(3px,7px) at random(5%,95%) random(5%,95%),rgba(192,132,252,random(.3,.8)) 0%,transparent 100%),radial-gradient(circle random(2px,5px) at random(5%,95%) random(5%,95%),hsl(random(180,320) 85% 75% \/ random(.4,.9)) 0%,transparent 100%),radial-gradient(circle random(120px,220px) at random(15%,85%) random(15%,85%),rgba(56,189,248,.14) 0%,transparent 70%),radial-gradient(circle random(140px,260px) at random(15%,85%) random(15%,85%),rgba(168,85,247,.16) 0%,transparent 70%),linear-gradient(160deg,#090d16 0%,#131b2e 55%,#1b1438 100%)}}.badge{display:inline-block;padding:4px 12px;border-radius:999px;font-size:12px;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.15);margin-bottom:12px;color:inherit;text-decoration:none}h1{font-size:22px;font-weight:600;margin-bottom:8px}p{font-size:14px;color:#94a3b8}<\/style>\n<p><\/head><body><\/p>\n<div class=\"starfield-card\">\n<div><a href=\"#\" class=\"badge\" onclick=\"location.reload();return false\">Pure CSS random() - \u70b9\u51fb\u5237\u65b0<\/a><\/p>\n<h1>\u591a\u5c42\u968f\u673a\u661f\u7a7a\u80cc\u666f<\/h1>\n<p>\u5237\u65b0\u9875\u9762\u5373\u53ef\u91cd\u65b0\u968f\u673a\u751f\u6210\u6240\u6709\u661f\u70b9\u4f4d\u7f6e\u3001\u5927\u5c0f\u4e0e\u661f\u4e91\u5149\u6655<\/p>\n<\/div>\n<\/div>\n<p><\/body><\/html>`;<\/script><\/p>\n<p>\u4f7f\u7528\u7684\u662fCSS\u591a\u80cc\u666f\u52a0\u5404\u79cd\u968f\u673a\u5b9e\u73b0\u7684\uff1a<\/p>\n<pre>.starfield-card {\r\n  \/* \r\n   * \u5229\u7528\u591a\u80cc\u666f\u53e0\u52a0\uff08Comma-separated layers\uff09\uff1a\r\n   * \u6bcf\u4e00\u5c42 radial-gradient \u5904\u4e8e\u4e0d\u540c\u7684\u7d22\u5f15\u4f4d\u7f6e\uff08property-index-scoped\uff09\uff0c\r\n   * \u56e0\u6b64\u6bcf\u9897\u661f\u661f\u7684 X \u5750\u6807\u3001Y \u5750\u6807\u3001\u5149\u6655\u534a\u5f84\u548c\u4eae\u5ea6\u90fd\u4f1a\u72ec\u7acb\u968f\u673a\u751f\u6210\u3002\r\n   *\/\r\n  background-image:\r\n    \/* \u661f\u661f 1\uff1a\u504f\u6696\u91d1\u8272\u5fae\u5149 *\/\r\n    radial-gradient(\r\n      circle random(2px, 5px) at random(5%, 95%) random(5%, 95%),\r\n      rgba(253, 224, 71, random(0.4, 0.95)) 0%,\r\n      transparent 100%\r\n    ),\r\n    \/* \u661f\u661f 2\uff1a\u51b7\u767d\u5149\u70b9 *\/\r\n    radial-gradient(\r\n      circle random(1px, 4px) at random(5%, 95%) random(5%, 95%),\r\n      rgba(255, 255, 255, random(0.5, 1)) 0%,\r\n      transparent 100%\r\n    ),\r\n    \/* \u661f\u661f 3\uff1a\u6de1\u84dd\u8272\u5149\u70b9 *\/\r\n    radial-gradient(\r\n      circle random(2px, 6px) at random(5%, 95%) random(5%, 95%),\r\n      rgba(125, 211, 252, random(0.3, 0.9)) 0%,\r\n      transparent 100%\r\n    ),\r\n    \/* \u661f\u661f 4\uff1a\u7d2b\u7f57\u5170\u661f\u4e91\u5fae\u7c92 *\/\r\n    radial-gradient(\r\n      circle random(3px, 7px) at random(5%, 95%) random(5%, 95%),\r\n      rgba(192, 132, 252, random(0.3, 0.8)) 0%,\r\n      transparent 100%\r\n    ),\r\n    \/* \u661f\u661f 5\uff1a\u968f\u673a\u8272\u76f8\u5f69\u661f *\/\r\n    radial-gradient(\r\n      circle random(2px, 5px) at random(5%, 95%) random(5%, 95%),\r\n      hsl(random(180, 320) 85% 75% \/ random(0.4, 0.9)) 0%,\r\n      transparent 100%\r\n    ),\r\n    \/* \u5e95\u5c42\u661f\u4e91\u5927\u5149\u6655 1 *\/\r\n    radial-gradient(\r\n      circle random(120px, 220px) at random(15%, 85%) random(15%, 85%),\r\n      rgba(56, 189, 248, 0.14) 0%,\r\n      transparent 70%\r\n    ),\r\n    \/* \u5e95\u5c42\u661f\u4e91\u5927\u5149\u6655 2 *\/\r\n    radial-gradient(\r\n      circle random(140px, 260px) at random(15%, 85%) random(15%, 85%),\r\n      rgba(168, 85, 247, 0.16) 0%,\r\n      transparent 70%\r\n    ),\r\n    \/* \u6700\u5e95\u5c42\u591c\u7a7a\u5e95\u8272 *\/\r\n    linear-gradient(160deg, #090d16 0%, #131b2e 55%, #1b1438 100%);\r\n}<\/pre>\n<p>\u6240\u4ee5\u5927\u5bb6\u53ef\u4ee5\u770b\u770b\u81ea\u5df1\u9879\u76ee\u6709\u6ca1\u6709\u4ec0\u4e48\u7eaf\u8272\u7684\u80cc\u666f\u7684\uff0c\u53ef\u4ee5\u8ba9AI\u751f\u6210\u8fd9\u4e48\u6bb5CSS\u4ee3\u7801\uff0c\u6d4f\u89c8\u5668\u652f\u6301\u6548\u679c\u9526\u4e0a\u6dfb\u82b1\uff0c\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\uff0c\u4fdd\u6301\u539f\u56e0\uff0c\u7a33\u8d5a\u4e0d\u8d54\u3002<\/p>\n<h3>\u56db\u3001\u597d\u4e86\u634f\uff0c\u5230\u6b64\u4e3a\u6b62\u4e86<\/h3>\n<p>\u8bed\u6cd5\u4e2d\u8fd8\u6709\u4e2a step \u53c2\u6570\u6ca1\u8bb2\uff0c\u4e3a\u4ec0\u4e48\u5462\uff1f<\/p>\n<p>\u8fc7\u4e8e\u7b80\u5355\uff0c\u4e0d\u503c\u5f97\u6d6a\u8d39\u53e3\u820c\uff0c\u6bd4\u65b9\u8bf4<code>random(0, 100, 10)<\/code>\uff0c\u5c31\u8868\u793a\u503c\u5728[0,10,20,30,&#8230;90,100]\u4e4b\u95f4\u968f\u673a\uff0c\u5bf9\u5427\uff0c\u8fd9\u4e2a\u6211\u5bb6\u4e0a\u5c0f\u5b66\u7684\u5a03\u90fd\u61c2\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u81f3\u6b64\uff0c\u8be5\u8bf4\u7684\u5185\u5bb9\u5dee\u4e0d\u591a\u90fd\u8bf4\u5b8c\u4e86\u3002<\/p>\n<p>\u5269\u4e0b\u7684\u5c31\u662f\u9759\u5f85\u5404\u5927\u6d4f\u89c8\u5668\u652f\u6301\u4e86\u3002<\/p>\n<p>\u54e6\uff0c\u5bf9\u4e86\uff0c<code>property-index-scoped<\/code>\u548c<code>property-scoped<\/code>\u8981Safari 27.3\u624d\u652f\u6301\u3002<\/p>\n<p>\u7136\u540ecaniuse\u4e0a\u5173\u4e8e\u51e0\u4e2a\u5173\u952e\u5b57\u7684\u517c\u5bb9\u6027\u6570\u636e\u8c8c\u4f3c\u6709\u95ee\u9898\uff0c\u6211Chrome 157\u8dd1\u4e86\u4e0b\uff0c\u90fd\u662f\u652f\u6301\u7684\u3002<\/p>\n<p>\u4ee5\u53ca\uff0c<code>random()<\/code>\u51fd\u6570\u80af\u5b9a\u8fd8\u4f1a\u6709\u8bb8\u591a\u5176\u4ed6\u7cbe\u5f69\u7684\u6848\u4f8b\u7684\uff0c\u8fd9\u4e2a\u56de\u5934\u8865\u5145\u3002<\/p>\n<p>\u6700\u540e\uff0c\u5927\u5c0f\u59d0Claude\u538b\u8f74\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202611\/2026-11-16_210540.webp\" width=\"177\" height=\"315\" alt=\"claude\u5927\u5c0f\u59d0\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\u53ca\u4fee\u6b63\u4e00\u4e9b\u9519\u8bef\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u539f\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u9519\u8bef\u77e5\u8bc6\u7684\u8bef\u5bfc\uff0c\u540c\u65f6\u6709\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=12497\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=12497<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202611\/2026-11-16_211334.webp\" width=\"160\" height=\"93\" alt=\"\u968f\u673aCSS\u51fd\u6570\u5360\u4f4d\u56fe\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>\u54ed\u6b7b\u6211\u4e86\uff0c\u6709\u751f\u4e4b\u5e74\u5c45\u7136\u89c1\u5230CSS\u652f\u6301random()\u968f\u673a\u51fd\u6570\uff0c\u8fd8\u662f\u6240\u6709\u4e3b\u6d41\u6d4f\u89c8\u5668\u51e0\u4e4e\u540c\u4e00\u65f6\u95f4\u652f\u6301\uff0c\u80fd\u5728\u88abAI\u6dd8\u6c70\u4e4b\u524d\u770b\u5230\u5fc3\u5fc3\u5ff5\u5ff5\u7684\u7279\u6027\u88ab\u652f\u6301\uff0c\u5fc3\u6ee1\u610f\u8db3\u4e86\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[2135,2185,1805,2184,1181,2183,1105],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/12497"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=12497"}],"version-history":[{"count":12,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/12497\/revisions"}],"predecessor-version":[{"id":12523,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/12497\/revisions\/12523"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=12497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=12497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=12497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}