{"id":28426,"date":"2024-11-24T10:44:20","date_gmt":"2024-11-24T02:44:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28426\/"},"modified":"2024-11-24T10:44:20","modified_gmt":"2024-11-24T02:44:20","slug":"ui-%e5%bc%80%e5%8f%91%e4%ba%ba%e5%91%98%e7%9a%84-css-%e6%8a%80%e5%b7%a7","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28426\/","title":{"rendered":"UI \u5f00\u53d1\u4eba\u5458\u7684 CSS \u6280\u5de7"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173200918798957.jpg\" class=\"aligncenter\" title=\"UI \u5f00\u53d1\u4eba\u5458\u7684 CSS \u6280\u5de7\u63d2\u56fe\" alt=\"UI \u5f00\u53d1\u4eba\u5458\u7684 CSS \u6280\u5de7\u63d2\u56fe\" \/><\/p>\n<h2> \u7b80\u4ecb\uff1a\u63d0\u5347\u60a8\u7684  \u6e38\u620f\u6c34\u5e73 <\/h2>\n<p>\u563f\uff0cui \u5f00\u53d1\u4eba\u5458\u670b\u53cb\u4eec\uff01\u60a8\u51c6\u5907\u597d\u5c06\u60a8\u7684 css \u5230\u65b0\u7684\u6c34\u5e73\u4e86\u5417\uff1f\u65e0\u8bba\u60a8\u662f\u7ecf\u9a8c\u4e30\u5bcc\u7684\u4e13\u4e1a\u4eba\u58eb\u8fd8\u662f\u521a\u521a\u8d77\u6b65\uff0c\u6211\u4eec\u90fd\u66fe\u9047\u5230\u8fc7\u6837\u5f0f\u8868\u4f3c\u4e4e\u6709\u81ea\u5df1\u7684\u60f3\u6cd5\u7684\u65f6\u523b\u3002\u4f46\u4e0d\u8981\u5bb3\u6015\uff01\u6211\u6709\u4e00\u4e9b\u6f02\u4eae\u7684 css \u6280\u5de7\uff0c\u5b83\u4eec\u4e00\u5b9a\u4f1a\u8ba9\u60a8\u7684\u751f\u6d3b\u66f4\u8f7b\u677e\uff0c\u8ba9\u60a8\u7684\u8bbe\u8ba1\u66f4\u4ee4\u4eba\u5370\u8c61\u6df1\u523b\u3002<\/p>\n<p>\u5728\u8fd9\u7bc7\u535a\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u63a2\u7d22 10 \u4e2a\u5f88\u68d2\u7684 css \u6280\u5de7\uff0c\u5b83\u4eec\u5c06\u5e2e\u52a9\u60a8\u89e3\u51b3\u5e38\u89c1\u7684\u8bbe\u8ba1\u6311\u6218\uff0c\u6539\u8fdb\u60a8\u7684\u5de5\u4f5c\u6d41\u7a0b\uff0c\u5e76\u4e3a\u60a8\u7684\u9879\u76ee\u589e\u6dfb\u4e00\u4e9b\u989d\u5916\u7684\u9b45\u529b\u3002\u8fd9\u4e9b\u4e0d\u4ec5\u4ec5\u662f\u4e00\u4e9b\u8001\u6280\u5de7\u2014\u2014\u5b83\u4eec\u5b9e\u7528\u3001\u5f3a\u5927\uff0c\u5e76\u4e14\u975e\u5e38\u9002\u5408\u50cf\u6211\u4eec\u8fd9\u6837\u60f3\u8981\u521b\u5efa\u4ee4\u4eba\u60ca\u53f9\u7684 web \u4f53\u9a8c\u7684 ui \u5f00\u53d1\u4eba\u5458\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u62ff\u8d77\u4f60\u6700\u559c\u6b22\u7684\u996e\u6599\uff0c\u653e\u677e\u4e00\u4e0b\uff0c\u8ba9\u6211\u4eec\u6df1\u5165 css hack \u7684\u4e16\u754c\uff01<\/p>\n<h2> 1. css \u53d8\u91cf\u7684\u9b54\u529b <\/h2>\n<h3> \u4ec0\u4e48\u662f css \u53d8\u91cf\uff1f <\/h3>\n<p>\u6211\u4eec\u7684 css hack \u5217\u8868\u4e2d\u7684\u7b2c\u4e00\u4e2a\u662f css \u53d8\u91cf\u7684\u4f7f\u7528\uff0c\u4e5f\u79f0\u4e3a css \u81ea\u5b9a\u4e49\u5c5e\u6027\u3002\u5982\u679c\u60a8\u8fd8\u6ca1\u6709\u5f00\u59cb\u4f7f\u7528\u8fd9\u4e9b\uff0c\u90a3\u4e48\u60a8\u5c31\u5927\u9971\u53e3\u798f\u4e86\uff01<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>css \u53d8\u91cf\u5141\u8bb8\u60a8\u5b58\u50a8\u7279\u5b9a\u503c\u5e76\u5728\u6574\u4e2a\u6837\u5f0f\u8868\u4e2d\u91cd\u590d\u4f7f\u7528\u5b83\u4eec\u3002\u5f53\u60a8\u4f7f\u7528\u989c\u8272\u3001\u5b57\u4f53\u6216\u60a8\u53d1\u73b0\u81ea\u5df1\u7ecf\u5e38\u91cd\u590d\u7684\u4efb\u4f55\u503c\u65f6\uff0c\u8fd9\u5c24\u5176\u6709\u7528\u3002<\/p>\n<h3> \u5982\u4f55\u4f7f\u7528 css \u53d8\u91cf <\/h3>\n<p>\u4ee5\u4e0b\u662f\u5982\u4f55\u8bbe\u7f6e\u548c\u4f7f\u7528 css \u53d8\u91cf\u7684\u5feb\u901f\u793a\u4f8b\uff1a<\/p>\n<pre>:root {\n  --main-color: #3498db;\n  --secondary-color: #2ecc71;\n  --font-size: 16px;\n}\n\n.button {\n  background-color: var(--main-color);\n  font-size: var(--font-size);\n}\n\n.header {\n  color: var(--secondary-color);\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> \u597d\u5904 <\/h3>\n<ul>\n<li>\u6613\u4e8e\u66f4\u65b0\uff1a\u5728\u4e00\u5904\u66f4\u6539\u503c\uff0c\u7136\u540e\u968f\u5904\u66f4\u65b0\u3002<\/li>\n<li>\u63d0\u9ad8\u53ef\u8bfb\u6027\uff1a\u4f7f\u60a8\u7684 css \u66f4\u52a0\u8bed\u4e49\u5316\u4e14\u66f4\u6613\u4e8e\u7406\u89e3\u3002<\/li>\n<li>\u652f\u6301\u4e3b\u9898\uff1a\u975e\u5e38\u9002\u5408\u521b\u5efa\u660e\u6697\u6a21\u5f0f\u6216\u591a\u79cd\u914d\u8272\u65b9\u6848\u3002<\/li>\n<\/ul>\n<h2> 2. ::before \u548c ::after \u4f2a\u5143\u7d20\u7684\u5a01\u529b <\/h2>\n<h3> \u7406\u89e3\u4f2a\u5143\u7d20 <\/h3>\n<p>\u6211\u4eec\u7684 css \u9ed1\u5ba2\u5de5\u5177\u5e93\u4e2d\u7684\u4e0b\u4e00\u4e2a\u662f ::before \u548c ::after \u4f2a\u5143\u7d20\u3002\u8fd9\u4e9b\u5c0f\u5b9d\u77f3\u5141\u8bb8\u60a8\u5411\u5143\u7d20\u6dfb\u52a0\u5185\u5bb9\uff0c\u800c\u65e0\u9700\u6dfb\u52a0\u989d\u5916\u7684 html \u6807\u8bb0\u3002<\/p>\n<h3> \u5b9e\u9645\u7528\u9014 <\/h3>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e9b\u4f2a\u5143\u7d20\u6765\u5b9e\u73b0\u5404\u79cd\u70ab\u9177\u7684\u6548\u679c\uff1a<\/p>\n<ul>\n<li>\u6dfb\u52a0\u88c5\u9970\u5143\u7d20<\/li>\n<li>\u521b\u5efa\u7c7b\u4f3c\u5de5\u5177\u63d0\u793a\u7684\u4fe1\u606f\u6c14\u6ce1<\/li>\n<li>\u52a8\u6001\u751f\u6210\u5185\u5bb9<\/li>\n<li>\u521b\u5efa\u590d\u6742\u7684\u5e03\u5c40<\/li>\n<\/ul>\n<h3> \u793a\u4f8b\uff1a\u521b\u5efa\u62a5\u4ef7\u5757 <\/h3>\n<p>\u8fd9\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u8bf4\u660e\u5982\u4f55\u4f7f\u7528 ::before \u548c ::after \u521b\u5efa\u65f6\u5c1a\u7684\u5f15\u7528\u5757\uff1a<\/p>\n<pre>blockquote {\n  position: relative;\n  padding: 20px;\n  background: #f9f9f9;\n}\n\nblockquote::before,\nblockquote::after {\n  content: '\"';\n  font-size: 50px;\n  position: absolute;\n  color: #ccc;\n}\n\nblockquote::before {\n  top: 0;\n  left: 10px;\n}\n\nblockquote::after {\n  bottom: -20px;\n  right: 10px;\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2> 3. flexbox\uff1a\u4f60\u7684\u5e03\u5c40\u6700\u597d\u7684\u670b\u53cb <\/h2>\n<h3> flexbox \u7684\u7075\u6d3b\u6027 <\/h3>\n<p>flexbox \u5e76\u4e0d\u5b8c\u5168\u662f\u4e00\u4e2a hack\uff0c\u4f46\u5b83\u662f\u4e00\u4e2a\u5982\u6b64\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u503c\u5f97\u5728\u6b64\u5217\u8868\u4e2d\u5360\u6709\u4e00\u5e2d\u4e4b\u5730\u3002\u5982\u679c\u60a8\u5c1a\u672a\u4f7f\u7528 flexbox\uff0c\u90a3\u4e48\u60a8\u5c31\u9519\u8fc7\u4e86\u5728 css \u4e2d\u521b\u5efa\u5e03\u5c40\u7684\u6700\u7075\u6d3b\u3001\u6700\u6709\u6548\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002<\/p>\n<h3> \u5173\u952e flexbox \u5c5e\u6027 <\/h3>\n<ul>\n<li> \u663e\u793a\uff1a\u67d4\u6027\uff1b &#8211; \u5c06\u5143\u7d20\u53d8\u6210\u5f39\u6027\u5bb9\u5668<\/li>\n<li> flex-direction &#8211; \u63a7\u5236\u5f39\u6027\u9879\u76ee\u7684\u65b9\u5411<\/li>\n<li> justify-content &#8211; \u6cbf\u4e3b\u8f74\u5bf9\u9f50\u9879\u76ee<\/li>\n<li> align-items &#8211; \u6cbf\u6a2a\u8f74\u5bf9\u9f50\u9879\u76ee<\/li>\n<\/ul>\n<h3> \u7b80\u5355\u7684 flexbox \u5e03\u5c40 <\/h3>\n<p>\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528 flexbox \u521b\u5efa\u54cd\u5e94\u5f0f\u5e03\u5c40\u7684\u5feb\u901f\u793a\u4f8b\uff1a<\/p>\n<pre>.container {\n  display: flex;\n  justify-content: space-between;\n  flex-wrap: wrap;\n}\n\n.item {\n  flex: 0 1 calc(33.333% - 20px);\n  margin: 10px;\n}\n\n@media (max-width: 768px) {\n  .item {\n    flex: 0 1 calc(50% - 20px);\n  }\n}\n\n@media (max-width: 480px) {\n  .item {\n    flex: 0 1 100%;\n  }\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u7075\u6d3b\u7684\u7f51\u683c\uff0c\u968f\u7740\u5c4f\u5e55\u5c3a\u5bf8\u7684\u51cf\u5c0f\uff0c\u7f51\u683c\u53ef\u4ee5\u4ece\u4e09\u5217\u8c03\u6574\u4e3a\u4e24\u5217\uff0c\u7136\u540e\u8c03\u6574\u4e3a\u4e00\u5217\u3002<\/p>\n<h2> 4. css \u7f51\u683c\u9769\u547d <\/h2>\n<h3> \u7f51\u683c\u4e0e flexbox <\/h3>\n<p>\u867d\u7136 flexbox \u975e\u5e38\u9002\u5408\u4e00\u7ef4\u5e03\u5c40\uff0c\u4f46 css grid \u901a\u8fc7\u4e8c\u7ef4\u5e03\u5c40\u5c06\u5176\u63d0\u5347\u5230\u4e86\u4e00\u4e2a\u65b0\u7684\u6c34\u5e73\u3002\u5b83\u975e\u5e38\u9002\u5408\u8f7b\u677e\u521b\u5efa\u590d\u6742\u7684\u9875\u9762\u7ed3\u6784\u3002<\/p>\n<h3> \u57fa\u672c\u7f51\u683c\u8bbe\u7f6e <\/h3>\n<p>\u4ee5\u4e0b\u662f\u8bbe\u7f6e\u7b80\u5355\u7f51\u683c\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre>.grid-container {\n  display: grid;\n  grid-template-columns: repeat(3, 1fr);\n  grid-gap: 20px;\n}\n\n.grid-item {\n  background-color: #f0f0f0;\n  padding: 20px;\n  text-align: center;\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> \u5148\u8fdb\u7684\u7f51\u683c\u6280\u672f <\/h3>\n<p>\u60a8\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u547d\u540d\u7f51\u683c\u533a\u57df\u6765\u53d1\u6325\u7f51\u683c\u7684\u771f\u6b63\u521b\u610f\uff1a<\/p>\n<pre>.grid-container {\n  display: grid;\n  grid-template-areas:\n    \"header header header\"\n    \"sidebar main main\"\n    \"footer footer footer\";\n  grid-gap: 20px;\n}\n\n.header { grid-area: header; }\n.sidebar { grid-area: sidebar; }\n.main { grid-area: main; }\n.footer { grid-area: footer; }\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u5e26\u6709\u9875\u7709\u3001\u4fa7\u8fb9\u680f\u3001\u4e3b\u8981\u5185\u5bb9\u533a\u57df\u548c\u9875\u811a\u7684\u5e03\u5c40\uff0c\u6240\u6709\u8fd9\u4e9b\u90fd\u53ea\u9700\u51e0\u884c css\uff01<\/p>\n<h2> 5. \u638c\u63e1 css \u8fc7\u6e21 <\/h2>\n<h3> \u5e73\u6ed1\u79fb\u52a8\u4e0e\u8fc7\u6e21 <\/h3>\n<p>css \u8fc7\u6e21\u5141\u8bb8\u60a8\u5728\u7ed9\u5b9a\u7684\u6301\u7eed\u65f6\u95f4\u5185\u5e73\u6ed1\u5730\u66f4\u6539\u5c5e\u6027\u503c\u3002\u5b83\u4eec\u662f\u65e0\u9700 javascript \u5373\u53ef\u5411 ui \u5143\u7d20\u6dfb\u52a0\u5fae\u5999\u52a8\u753b\u7684\u597d\u65b9\u6cd5\u3002<\/p>\n<h3> \u57fa\u672c\u8f6c\u6362\u8bed\u6cd5 <\/h3>\n<p>\u8f6c\u6362\u7684\u57fa\u672c\u8bed\u6cd5\u662f\uff1a<\/p>\n<pre>.element {\n  transition: property duration timing-function delay;\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> \u5b9e\u4f8b\uff1a\u6309\u94ae\u60ac\u505c\u6548\u679c <\/h3>\n<p>\u8ba9\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u6309\u94ae\uff0c\u60ac\u505c\u65f6\u989c\u8272\u4f1a\u5e73\u6ed1\u53d8\u5316\uff1a<\/p>\n<pre>.button {\n  background-color: #3498db;\n  color: white;\n  padding: 10px 20px;\n  border: none;\n  transition: background-color 0.3s ease;\n}\n\n.button:hover {\n  background-color: #2980b9;\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u6309\u94ae\uff0c\u5f53\u60a8\u5c06\u9f20\u6807\u60ac\u505c\u5728\u5176\u4e0a\u65b9\u65f6\uff0c\u8be5\u6309\u94ae\u4f1a\u5e73\u6ed1\u5730\u6539\u53d8\u989c\u8272\uff0c\u4ece\u800c\u4e3a\u7528\u6237\u63d0\u4f9b\u826f\u597d\u7684\u89c6\u89c9\u53cd\u9988\u3002<\/p>\n<h2> 6. css \u5f62\u72b6\u7684\u9b54\u529b <\/h2>\n<h3> \u6253\u7834\u5e38\u89c4 <\/h3>\n<p>css \u5f62\u72b6\u5141\u8bb8\u60a8\u521b\u5efa\u975e\u77e9\u5f62\u5e03\u5c40\uff0c\u8fd9\u53ef\u4ee5\u4e3a\u60a8\u7684\u8bbe\u8ba1\u6dfb\u52a0\u72ec\u7279\u4e14\u6709\u8da3\u7684\u5916\u89c2\u3002<\/p>\n<h3> \u4f7f\u7528\u5916\u90e8\u5f62\u72b6 <\/h3>\n<p>shape-outside \u5c5e\u6027\u5b9a\u4e49\u4e86\u5185\u8054\u5185\u5bb9\u5e94\u73af\u7ed5\u7684\u5f62\u72b6\u3002\u8fd9\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<pre>.circle-shape {\n  width: 200px;\n  height: 200px;\n  float: left;\n  shape-outside: circle(50%);\n  clip-path: circle(50%);\n  background: #3498db;\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4f1a\u521b\u5efa\u4e00\u4e2a\u6587\u672c\u5c06\u73af\u7ed5\u7684\u5706\u5f62\u5f62\u72b6\uff0c\u4ece\u800c\u521b\u5efa\u4e00\u4e2a\u89c6\u89c9\u4e0a\u6709\u8da3\u7684\u5e03\u5c40\u3002<\/p>\n<h3> \u5c06\u5f62\u72b6\u4e0e\u56fe\u50cf\u76f8\u7ed3\u5408 <\/h3>\n<p>\u60a8\u8fd8\u53ef\u4ee5\u5c06 shape-outside \u4e0e\u56fe\u50cf\u4e00\u8d77\u4f7f\u7528\u6765\u521b\u5efa\u66f4\u590d\u6742\u7684\u5f62\u72b6\uff1a<\/p>\n<pre>.image-shape {\n  float: left;\n  shape-outside: url('path-to-your-image.png');\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4f7f\u5f97\u6587\u672c\u53ef\u4ee5\u56f4\u7ed5\u56fe\u50cf\u7684\u8f6e\u5ed3\u6d41\u52a8\uff0c\u4ece\u800c\u521b\u5efa\u6587\u672c\u548c\u89c6\u89c9\u6548\u679c\u7684\u65e0\u7f1d\u96c6\u6210\u3002<\/p>\n<h2> 7. css \u8ba1\u6570\u5668\u7684\u5a01\u529b <\/h2>\n<h3> \u4f7f\u7528 css \u81ea\u52a8\u7f16\u53f7 <\/h3>\n<p>css \u8ba1\u6570\u5668\u5c31\u50cf css \u7ef4\u62a4\u7684\u53d8\u91cf\uff0c\u5176\u503c\u53ef\u4ee5\u901a\u8fc7 css \u89c4\u5219\u9012\u589e\u3002\u5b83\u4eec\u975e\u5e38\u9002\u5408\u521b\u5efa\u7f16\u53f7\u5217\u8868\u6216\u90e8\u5206\uff0c\u65e0\u9700\u989d\u5916\u7684\u6807\u8bb0\u3002<\/p>\n<h3> \u8bbe\u7f6e\u8ba1\u6570\u5668 <\/h3>\n<p>\u4ee5\u4e0b\u662f\u8bbe\u7f6e\u548c\u4f7f\u7528\u8ba1\u6570\u5668\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre>body {\n  counter-reset: section;\n}\n\nh2::before {\n  counter-increment: section;\n  content: \"section \" counter(section) \": \";\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u81ea\u52a8\u4f7f\u7528\u201csection 1:\u201d\u3001\u201csection 2:\u201d\u7b49\u5bf9\u60a8\u7684 h2 \u5143\u7d20\u8fdb\u884c\u7f16\u53f7\u3002<\/p>\n<h3> \u5d4c\u5957\u8ba1\u6570\u5668 <\/h3>\n<p>\u60a8\u751a\u81f3\u53ef\u4ee5\u4e3a\u5b50\u90e8\u5206\u521b\u5efa\u5d4c\u5957\u8ba1\u6570\u5668\uff1a<\/p>\n<pre>body {\n  counter-reset: section;\n}\n\nh2 {\n  counter-reset: subsection;\n}\n\nh2::before {\n  counter-increment: section;\n  content: \"section \" counter(section) \": \";\n}\n\nh3::before {\n  counter-increment: subsection;\n  content: counter(section) \".\" counter(subsection) \" \";\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u4e3a\u60a8\u7684\u7ae0\u8282\u548c\u5c0f\u8282\u521b\u5efa\u4e00\u4e2a\u7f16\u53f7\u7cfb\u7edf\uff0c\u4f8b\u5982\u201c1.1\u201d\u3001\u201c1.2\u201d\u3001\u201c2.1\u201d\u7b49\u3002<\/p>\n<h2> 8. \u4f7f\u7528 css \u81ea\u5b9a\u4e49\u6eda\u52a8\u6761 <\/h2>\n<h3> \u8bbe\u7f6e\u6eda\u52a8\u6761\u6837\u5f0f <\/h3>\n<p>\u60a8\u77e5\u9053\u53ef\u4ee5\u4f7f\u7528 css \u8bbe\u7f6e\u6eda\u52a8\u6761\u6837\u5f0f\u5417\uff1f\u867d\u7136\u8fd9\u5e76\u4e0d\u9002\u7528\u4e8e\u6240\u6709\u6d4f\u89c8\u5668\uff0c\u4f46\u5b83\u53ef\u4ee5\u5728\u652f\u6301\u7684\u6d4f\u89c8\u5668\u4e2d\u4e3a\u60a8\u7684\u8bbe\u8ba1\u589e\u6dfb\u4e00\u62b9\u4eae\u8272\u3002<\/p>\n<h3> webkit \u6eda\u52a8\u6761\u6837\u5f0f <\/h3>\n<p>\u4ee5\u4e0b\u662f\u5982\u4f55\u5728 webkit \u6d4f\u89c8\u5668\u4e2d\u8bbe\u7f6e\u6eda\u52a8\u6761\u6837\u5f0f\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>::-webkit-scrollbar {\n  width: 10px;\n}\n\n::-webkit-scrollbar-track {\n  background: #f1f1f1;\n}\n\n::-webkit-scrollbar-thumb {\n  background: #888;\n}\n\n::-webkit-scrollbar-thumb:hover {\n  background: #555;\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u5e26\u6709\u7070\u8272\u62c7\u6307\u7684\u81ea\u5b9a\u4e49\u6eda\u52a8\u6761\uff0c\u9f20\u6807\u60ac\u505c\u65f6\u4f1a\u53d8\u6697\u3002<\/p>\n<h3> \u8de8\u6d4f\u89c8\u5668\u6eda\u52a8\u6761\u6837\u5f0f <\/h3>\n<p>\u8981\u83b7\u5f97\u66f4\u8de8\u6d4f\u89c8\u5668\u517c\u5bb9\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u65b0\u7684\u6eda\u52a8\u6761\u989c\u8272\u548c\u6eda\u52a8\u6761\u5bbd\u5ea6\u5c5e\u6027\uff1a<\/p>\n<pre>* {\n  scrollbar-width: thin;\n  scrollbar-color: #888 #f1f1f1;\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4f1a\u5728\u652f\u6301\u8fd9\u4e9b\u5c5e\u6027\u7684\u6d4f\u89c8\u5668\u4e2d\u8bbe\u7f6e\u4e00\u4e2a\u5e26\u6709\u7070\u8272\u6ed1\u5757\u548c\u6d45\u7070\u8272\u8f68\u9053\u7684\u7ec6\u6eda\u52a8\u6761\u3002<\/p>\n<h2> 9.\u7eaf css \u5de5\u5177\u63d0\u793a <\/h2>\n<h3> \u65e0\u9700 javascript\uff01 <\/h3>\n<p>\u5de5\u5177\u63d0\u793a\u662f\u63d0\u4f9b\u9644\u52a0\u4fe1\u606f\u800c\u4e0d\u4f1a\u4f7f\u7528\u6237\u754c\u9762\u6df7\u4e71\u7684\u597d\u65b9\u6cd5\u3002\u4f60\u731c\u600e\u4e48\u7740\uff1f\u60a8\u53ea\u9700\u4f7f\u7528 css \u5373\u53ef\u521b\u5efa\u5b83\u4eec\uff01<\/p>\n<h3> \u57fa\u672c css \u5de5\u5177\u63d0\u793a <\/h3>\n<p>\u8fd9\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u7eaf css \u5de5\u5177\u63d0\u793a\uff1a<\/p>\n<pre>.tooltip {\n  position: relative;\n  display: inline-block;\n  border-bottom: 1px dotted black;\n}\n\n.tooltip .tooltiptext {\n  visibility: hidden;\n  width: 120px;\n  background-color: black;\n  color: #fff;\n  text-align: center;\n  border-radius: 6px;\n  padding: 5px 0;\n  position: absolute;\n  z-index: 1;\n  bottom: 125%;\n  left: 50%;\n  margin-left: -60px;\n  opacity: 0;\n  transition: opacity 0.3s;\n}\n\n.tooltip:hover .tooltiptext {\n  visibility: visible;\n  opacity: 1;\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8981\u4f7f\u7528\u5b83\uff0c\u60a8\u53ef\u4ee5\u50cf\u8fd9\u6837\u6784\u5efa html\uff1a<\/p>\n<pre>&lt;div class=\"tooltip\"&gt;hover over me\n  &lt;span class=\"tooltiptext\"&gt;tooltip text&lt;\/span&gt;\n&lt;\/div&gt;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4f1a\u521b\u5efa\u4e00\u4e2a\u5de5\u5177\u63d0\u793a\uff0c\u5f53\u60a8\u5c06\u9f20\u6807\u60ac\u505c\u5728\u6587\u672c\u4e0a\u65f6\uff0c\u4f1a\u51fa\u73b0\u4e00\u4e2a\u5de5\u5177\u63d0\u793a\uff0c\u5e76\u5177\u6709\u5e73\u6ed1\u7684\u6de1\u5165\u6548\u679c\u3002<\/p>\n<h2> 10.\u7eaf css \u624b\u98ce\u7434 <\/h2>\n<h3> \u65e0\u9700 javascript \u5373\u53ef\u6269\u5c55\u5185\u5bb9 <\/h3>\n<p>\u6211\u4eec\u6700\u7ec8\u7684 css hack \u662f\u4e00\u4e2a\u6f02\u4eae\u7684\u624b\u98ce\u7434\u6548\u679c\uff0c\u4e0d\u9700\u8981\u4efb\u4f55 javascript\u3002\u8fd9\u5bf9\u4e8e\u5e38\u89c1\u95ee\u9898\u89e3\u7b54\u90e8\u5206\u6216\u60a8\u60f3\u8981\u5c55\u5f00\u548c\u6298\u53e0\u7684\u4efb\u4f55\u5185\u5bb9\u975e\u5e38\u6709\u7528\u3002<\/p>\n<h3> \u4ec5 css \u7684\u624b\u98ce\u7434 <\/h3>\n<p>\u4ee5\u4e0b\u662f\u521b\u5efa\u7eaf css \u624b\u98ce\u7434\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre>.accordion {\n  max-width: 500px;\n  margin: 0 auto;\n}\n\n.accordion-item {\n  border-bottom: 1px solid #ddd;\n}\n\n.accordion-header {\n  display: block;\n  padding: 15px;\n  background-color: #f4f4f4;\n  color: #333;\n  text-decoration: none;\n  position: relative;\n  cursor: pointer;\n}\n\n.accordion-header::after {\n  content: '+';\n  position: absolute;\n  right: 15px;\n  top: 50%;\n  transform: translatey(-50%);\n}\n\n.accordion-content {\n  max-height: 0;\n  overflow: hidden;\n  transition: max-height 0.3s ease-out;\n}\n\n.accordion-item input[type=\"checkbox\"] {\n  display: none;\n}\n\n.accordion-item input[type=\"checkbox\"]:checked ~ .accordion-content {\n  max-height: 1000px;\n}\n\n.accordion-item input[type=\"checkbox\"]:checked ~ .accordion-header::after {\n  content: '-';\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u662f html \u7ed3\u6784\uff1a<\/p>\n<pre>&lt;div class=\"accordion\"&gt;\n  &lt;div class=\"accordion-item\"&gt;\n    &lt;input type=\"checkbox\" id=\"item1\"&gt;\n    &lt;label class=\"accordion-header\" for=\"item1\"&gt;Section 1&lt;\/label&gt;\n    &lt;div class=\"accordion-content\"&gt;\n      &lt;p&gt;Content for section 1...&lt;\/p&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n  &lt;!-- Repeat for more accordion items --&gt;\n&lt;\/div&gt;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u53ef\u6269\u5c55\u7684\u624b\u98ce\u7434\uff0c\u7eaf\u7cb9\u4f7f\u7528 css\uff0c\u65e0\u9700 javascript\uff01<\/p>\n<h2> \u7ed3\u8bba\uff1a\u638c\u63e1 css hack <\/h2>\n<p>\u597d\u4e86\uff0c\u4f19\u8ba1\u4eec\uff01\u6211\u4eec\u5df2\u7ecf\u4ecb\u7ecd\u4e86 10 \u4e2a\u5f88\u68d2\u7684 css \u6280\u5de7\uff0c\u5b83\u4eec\u53ef\u4ee5\u771f\u6b63\u63d0\u5347\u60a8\u7684 ui \u5f00\u53d1\u6c34\u5e73\u3002\u4ece css \u53d8\u91cf\u7684\u7075\u6d3b\u6027\u5230\u4f2a\u5143\u7d20\u7684\u9b54\u529b\uff0c\u4ece flexbox \u548c grid \u7b49\u5e03\u5c40\u5927\u5e08\u5230\u5de5\u5177\u63d0\u793a\u548c\u624b\u98ce\u7434\u7b49\u7eaf\u7cb9 css \u9a71\u52a8\u7684\u4ea4\u4e92\u5143\u7d20\uff0c\u8fd9\u4e9b\u6280\u672f\u4e3a\u521b\u5efa\u5f15\u4eba\u5165\u80dc\u4e14\u9ad8\u6548\u7684\u7528\u6237\u754c\u9762\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u53ef\u80fd\u6027\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fUI \u5f00\u53d1\u4eba\u5458\u7684 CSS \u6280\u5de7\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>\u7b80\u4ecb\uff1a\u63d0\u5347\u60a8\u7684 \u6e38\u620f\u6c34\u5e73 \u563f\uff0cui \u5f00\u53d1\u4eba\u5458\u670b\u53cb\u4eec\uff01\u60a8\u51c6\u5907\u597d\u5c06\u60a8\u7684 css \u5230\u65b0\u7684\u6c34\u5e73\u4e86\u5417\uff1f\u65e0\u8bba\u60a8\u662f\u7ecf\u9a8c\u4e30\u5bcc\u7684\u4e13\u4e1a\u4eba\u58eb\u8fd8\u662f\u521a\u521a\u8d77\u6b65\uff0c\u6211\u4eec\u90fd\u66fe\u9047\u5230\u8fc7\u6837\u5f0f\u8868\u4f3c\u4e4e\u6709\u81ea\u5df1\u7684\u60f3\u6cd5\u7684\u65f6\u523b\u3002\u4f46\u4e0d\u8981\u5bb3\u6015\uff01\u6211\u6709\u4e00\u4e9b\u6f02\u4eae\u7684 css \u6280\u5de7\uff0c\u5b83\u4eec\u4e00\u5b9a\u4f1a\u8ba9\u60a8\u7684\u751f\u6d3b\u66f4\u8f7b\u677e\uff0c\u8ba9\u60a8\u7684\u8bbe\u8ba1\u66f4\u4ee4\u4eba\u5370\u8c61\u6df1\u523b\u3002 \u5728\u8fd9\u7bc7\u535a\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u63a2\u7d22 10 \u4e2a\u5f88\u68d2\u7684 css \u6280\u5de7\uff0c\u5b83\u4eec\u5c06\u5e2e\u52a9\u60a8\u89e3\u51b3\u5e38\u89c1\u7684\u8bbe\u8ba1\u6311\u6218\uff0c\u6539\u8fdb\u60a8\u7684\u5de5\u4f5c\u6d41\u7a0b\uff0c\u5e76\u4e3a\u60a8\u7684\u9879\u76ee\u589e\u6dfb\u4e00\u4e9b\u989d\u5916\u7684\u9b45\u529b\u3002\u8fd9\u4e9b\u4e0d\u4ec5\u4ec5\u662f\u4e00\u4e9b\u8001\u6280\u5de7\u2014\u2014\u5b83\u4eec\u5b9e\u7528\u3001\u5f3a\u5927\uff0c\u5e76\u4e14\u975e\u5e38\u9002\u5408\u50cf\u6211\u4eec\u8fd9\u6837\u60f3\u8981\u521b\u5efa\u4ee4\u4eba\u60ca\u53f9\u7684 web \u4f53\u9a8c\u7684 ui \u5f00\u53d1\u4eba\u5458\u3002 \u6240\u4ee5\uff0c\u62ff\u8d77\u4f60\u6700\u559c\u6b22\u7684\u996e\u6599\uff0c\u653e\u677e\u4e00\u4e0b\uff0c\u8ba9\u6211\u4eec\u6df1\u5165 css hack \u7684\u4e16\u754c\uff01 1. css \u53d8\u91cf\u7684\u9b54\u529b \u4ec0\u4e48\u662f css \u53d8\u91cf\uff1f \u6211\u4eec\u7684 css hack \u5217\u8868\u4e2d\u7684\u7b2c\u4e00\u4e2a\u662f css \u53d8\u91cf\u7684\u4f7f\u7528\uff0c\u4e5f\u79f0\u4e3a css \u81ea\u5b9a\u4e49\u5c5e\u6027\u3002\u5982\u679c\u60a8\u8fd8\u6ca1\u6709\u5f00\u59cb\u4f7f\u7528\u8fd9\u4e9b\uff0c\u90a3\u4e48\u60a8\u5c31\u5927\u9971\u53e3\u798f\u4e86\uff01 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b css \u53d8\u91cf\u5141\u8bb8\u60a8\u5b58\u50a8\u7279\u5b9a\u503c\u5e76\u5728\u6574\u4e2a\u6837\u5f0f\u8868\u4e2d\u91cd\u590d\u4f7f\u7528\u5b83\u4eec\u3002\u5f53\u60a8\u4f7f\u7528\u989c\u8272\u3001\u5b57\u4f53\u6216\u60a8\u53d1\u73b0\u81ea\u5df1\u7ecf\u5e38\u91cd\u590d\u7684\u4efb\u4f55\u503c\u65f6\uff0c\u8fd9\u5c24\u5176\u6709\u7528\u3002 \u5982\u4f55\u4f7f\u7528 css \u53d8\u91cf \u4ee5\u4e0b\u662f\u5982\u4f55\u8bbe\u7f6e\u548c\u4f7f\u7528 css \u53d8\u91cf\u7684\u5feb\u901f\u793a\u4f8b\uff1a :root { &#8211;main-color: #3498db; &#8211;secondary-color: #2ecc71; &#8211;font-size: 16px; } .button { [&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-28426","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28426","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=28426"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28426\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}