{"id":27203,"date":"2024-11-24T12:20:12","date_gmt":"2024-11-24T04:20:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27203\/"},"modified":"2024-11-24T12:20:12","modified_gmt":"2024-11-24T04:20:12","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-css-%e5%ae%9e%e7%8e%b0%e5%be%ae%e4%bf%a1%e8%be%93%e5%85%a5%e6%b3%95%e8%bf%9b%e5%ba%a6%e6%9d%a1%e6%8c%89%e9%92%ae%e6%95%88%e6%9e%9c%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27203\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 CSS \u5b9e\u73b0\u5fae\u4fe1\u8f93\u5165\u6cd5\u8fdb\u5ea6\u6761\u6309\u94ae\u6548\u679c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173121086745078.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 CSS \u5b9e\u73b0\u5fae\u4fe1\u8f93\u5165\u6cd5\u8fdb\u5ea6\u6761\u6309\u94ae\u6548\u679c\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 CSS \u5b9e\u73b0\u5fae\u4fe1\u8f93\u5165\u6cd5\u8fdb\u5ea6\u6761\u6309\u94ae\u6548\u679c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u7528  \u5b9e\u73b0\u8f93\u5165\u6cd5\u8fdb\u5ea6\u6761\u6309\u94ae\u6548\u679c<\/strong><\/p>\n<p>\u5728\u524d\u7aef\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u521b\u5efa\u5177\u6709\u52a8\u6001\u6548\u679c\u7684 ui \u7ec4\u4ef6\u3002\u5fae\u4fe1\u8f93\u5165\u6cd5\u4e2d\u72ec\u7279\u7684\u8fdb\u5ea6\u6761\u6309\u94ae\u5c31\u662f\u8fd9\u6837\u4e00\u4e2a\u4f8b\u5b50\u3002\u901a\u8fc7\u5229\u7528 css\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u5b9e\u73b0\u7c7b\u4f3c\u7684\u6548\u679c\u3002<\/p>\n<p><strong>css \u5b9e\u73b0\u6b65\u9aa4<\/strong><\/p>\n<p>\u8981\u521b\u5efa\u5fae\u4fe1\u8f93\u5165\u6cd5\u8fdb\u5ea6\u6761\u6309\u94ae\u6548\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>1. \u521b\u5efa\u57fa\u7840\u6309\u94ae<\/strong><\/p>\n<pre>.button {\n  width: 100px;\n  height: 50px;\n  background: #ccc;\n  border-radius: 5px;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 linear-gradient \u521b\u5efa\u8fdb\u5ea6\u6761<\/strong><\/p>\n<pre>.button::after {\n  content: \"\";\n  position: absolute;\n  top: 0;\n  left: 0;\n  width: 0%;\n  height: 100%;\n  background: linear-gradient(90deg, #008000 0%, #00b300 100%);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4f7f\u7528 background-position \u63a7\u5236\u8fdb\u5ea6\u6761\u4f4d\u7f6e<\/strong><\/p>\n<pre>.button:hover::after {\n  animation: progress 1s linear;\n}\n\n@keyframes progress {\n  0% {\n    width: 0%;\n  }\n  50% {\n    width: 50%;\n  }\n  100% {\n    width: 100%;\n  }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u4f7f\u7528 background-clip \u9690\u85cf\u8fdb\u5ea6\u6761\u90e8\u5206<\/strong><\/p>\n<pre>.button::after {\n  background-clip: content-box;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528 css \u521b\u5efa\u51fa\u7c7b\u4f3c\u4e8e\u5fae\u4fe1\u8f93\u5165\u6cd5\u8fdb\u5ea6\u6761\u6309\u94ae\u7684\u6548\u679c\u3002<\/p>\n<p><strong>\u517c\u5bb9\u6027<\/strong><\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u79cd\u6280\u672f\u53ef\u80fd\u5728\u67d0\u4e9b\u6d4f\u89c8\u5668\u4e2d\u5b58\u5728\u517c\u5bb9\u6027\u95ee\u9898\u3002\u5177\u4f53\u6765\u8bf4\uff0cbackground-clip: content-box \u53ef\u80fd\u4f1a\u5728 firefox \u548c safari \u4e2d\u5931\u6548\u3002\u5bf9\u4e8e\u8fd9\u4e9b\u6d4f\u89c8\u5668\uff0c\u53ef\u4ee5\u4f7f\u7528\u66ff\u4ee3\u7684\u65b9\u6cd5\u6765\u5b9e\u73b0\u7c7b\u4f3c\u7684\u6548\u679c\uff0c\u4f8b\u5982\u4f7f\u7528\u5e26\u6709\u8fc7\u6e21\u7684 animation\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 CSS \u5b9e\u73b0\u8f93\u5165\u6cd5\u8fdb\u5ea6\u6761\u6309\u94ae\u6548\u679c\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>\u7528 \u5b9e\u73b0\u8f93\u5165\u6cd5\u8fdb\u5ea6\u6761\u6309\u94ae\u6548\u679c \u5728\u524d\u7aef\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u521b\u5efa\u5177\u6709\u52a8\u6001\u6548\u679c\u7684 ui \u7ec4\u4ef6\u3002\u5fae\u4fe1\u8f93\u5165\u6cd5\u4e2d\u72ec\u7279\u7684\u8fdb\u5ea6\u6761\u6309\u94ae\u5c31\u662f\u8fd9\u6837\u4e00\u4e2a\u4f8b\u5b50\u3002\u901a\u8fc7\u5229\u7528 css\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u5b9e\u73b0\u7c7b\u4f3c\u7684\u6548\u679c\u3002 css \u5b9e\u73b0\u6b65\u9aa4 \u8981\u521b\u5efa\u5fae\u4fe1\u8f93\u5165\u6cd5\u8fdb\u5ea6\u6761\u6309\u94ae\u6548\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b 1. \u521b\u5efa\u57fa\u7840\u6309\u94ae .button { width: 100px; height: 50px; background: #ccc; border-radius: 5px; } \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528 linear-gradient \u521b\u5efa\u8fdb\u5ea6\u6761 .button::after { content: &#8220;&#8221;; position: absolute; top: 0; left: 0; width: 0%; height: 100%; background: linear-gradient(90deg, #008000 0%, #00b300 100%); } \u767b\u5f55\u540e\u590d\u5236 3. \u4f7f\u7528 background-position \u63a7\u5236\u8fdb\u5ea6\u6761\u4f4d\u7f6e .button:hover::after [&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-27203","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27203","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=27203"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27203\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}