{"id":10230,"date":"2021-12-13T22:40:05","date_gmt":"2021-12-13T14:40:05","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10230"},"modified":"2022-01-05T17:29:09","modified_gmt":"2022-01-05T09:29:09","slug":"css-meida-user-experience","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2021\/12\/css-meida-user-experience\/","title":{"rendered":"\u4f60\u4e0d\u77e5\u9053\u7684CSS media\u67e5\u8be2\u4e0e\u7528\u6237\u4f53\u9a8c"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10230\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10230<\/a> \u946b\u7a7a\u95f4-\u946b\u751f\u6d3b<br \/>\n\u672c\u6587\u6b22\u8fce\u5206\u4eab\u4e0e\u805a\u5408\uff0c\u5168\u6587\u8f6c\u8f7d\u5c31\u4e0d\u5fc5\u4e86\uff0c\u5c0a\u91cd\u7248\u6743\uff0c\u5708\u5b50\u5c31\u8fd9\u4e48\u5927\uff0c\u82e5\u6025\u7528\u53ef\u4ee5\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<p><script>window.wxShareImgUrl = 'https:\/\/www.zhangxinxu.com\/study\/image\/share\/202112-media-ue.jpg';if(!\/zhangxinxu\/.test(location.host)){document.body.addEventListener('mousedown',function(){location.href='https:\/\/www.zhangxinxu.com\/wordpress\/?p=10230'});}<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202112\/media-ue.jpg\" width=\"480\" height=\"299\" alt=\"media\u4e0e\u7528\u6237\u4f53\u9a8c\" class=\"alignright clip thumb size-medium\" \/><\/p>\n<h3>\u4e00\u3001\u4ec0\u4e48\u662f\u5a92\u4f53\u67e5\u8be2\uff1f<\/h3>\n<p>\u5a92\u4f53\u67e5\u8be2\u53ef\u4ee5\u770b\u6210\u662f\u6d4f\u89c8\u5668\u63d0\u4f9b\u7684\u83b7\u53d6\u2f64\u6237\u7cfb\u7edf\u53c2\u6570\u548c\u8bbe\u7f6e\u7684\u63a5\u2f1d\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4e0d\u5c11\u524d\u7aef\u5f00\u53d1\u6709\u8fd9\u4e48\u4e2a\u8ba4\u77e5\u8bef\u533a\uff0c\u5c31\u662f\u8ba4\u4e3a\u5a92\u4f53\u67e5\u8be2\u53ea\u80fd\u7528\u5728 CSS \u4e2d\uff0c\u5c31\u50cf\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n<pre>@media (max-width: 480px) {\r\n    \/* css here *\/\r\n}<\/pre>\n<p>\u5b9e\u9645\u4e0a\u4e0d\u662f\u7684\uff0c\u6211\u4eec\u5728 HTML \u548c JavaScript \u4e2d\u4e5f\u662f\u53ef\u4ee5\u4f7f\u7528\u5a92\u4f53\u67e5\u8be2\u7684\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u53ef\u4ee5\u5355\u72ec\u628a\u79fb\u52a8\u7aef\u7684 CSS \u5355\u72ec\u63d0\u51fa\u6765\uff1a<\/p>\n<pre>&lt;link rel=\"stylesheet\" href=\"default.css\"&gt;\r\n&lt;link rel=\"stylesheet\" href=\"mobile.css\" media=\"(max-width: 480px)\"&gt;<\/pre>\n<p>\u4f7f\u7528\u5a92\u4f53\u67e5\u8be2\u63a7\u5236\u56fe\u50cf\u8d44\u6e90\u7684\u52a0\u8f7d\uff08\u60f3\u4e86\u89e3\u66f4\u591a &lt;picture&gt; \u5143\u7d20\u77e5\u8bc6\uff0c\u53ef<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2021\/07\/html-picture\/\">\u8bbf\u95ee\u8fd9\u7bc7\u6587\u7ae0<\/a>\uff09\uff1a<\/p>\n<pre>&lt;picture&gt;\r\n  &lt;source srcset=\"rect.png\" media=\"(min-width: 480px)\"&gt;\r\n  &lt;img src=\"square.png\"&gt;\r\n&lt;\/picture&gt;<\/pre>\n<p>\u5982\u679c\u662f\u5728 JS \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 matchMedia \u8fd9\u4e2a API \u65b9\u6cd5\u5224\u65ad\u662f\u4e0d\u662f\u5339\u914d\u5bf9\u5e94\u7684\u5a92\u4f53\u67e5\u8be2\uff1a<\/p>\n<pre>if (matchMedia('(max-width: 480px)').matches) {\r\n    \/\/ js here\r\n}<\/pre>\n<p>\u6ce8\u610f\uff0c\u5728 JS \u5e94\u7528\u4e2d\uff0c\u5982\u679c\u53c2\u6570\u662f CSS \u58f0\u660e\uff08\u4e5f\u5c31\u662f\u51fa\u73b0\u4e86\u5192\u53f7\uff09\uff0c\u5916\u9762\u9700\u8981\u6709\u4e2a\u62ec\u53f7\uff0c\u5426\u5219\u8bed\u6cd5\u4e0d\u6b63\u786e\uff0c\u4e5f\u5c31\u662f <code>matchMedia('max-width:480px')<\/code> \u662f\u65e0\u6548\u7684\u3002<\/p>\n<p>\u76ee\u524d\uff0c\u5a92\u4f53\u67e5\u8be2\u5e94\u7528\u6700\u591a\u7684\u5c31\u662f\u54cd\u5e94\u5f0f\u5e03\u5c40\u7684\u5f00\u53d1\u3002<\/p>\n<p>\u5b9e\u9645\u4e0a\uff0cmeida query \u5a92\u4f53\u67e5\u8be2\u9664\u4e86\u5b9e\u73b0\u5e94\u5f0f\u5f00\u53d1\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u501f\u52a9\u5e2e\u52a9\u6211\u4eec\u63d0\u5347\u2f64\u6237\u4f53\u9a8c\uff0c\u8fd9\u662f\u5f88\u591a\u524d\u7aef\u5f00\u53d1\u6240\u4e0d\u77e5\u9053\u7684\u3002<\/p>\n<h3>\u4e8c\u3001\u63d0\u5347\u64cd\u4f5c\u4fbf\u5229\u6027<\/h3>\n<p>\u968f\u7740\u8bbe\u5907\u7aef\u7684\u79cd\u7c7b\u7684\u591a\u6837\u5316\uff0cWeb \u4ea7\u54c1\u4e0d\u4ec5\u4ec5\u5728\u4f20\u7edf\u7684\u6d4f\u89c8\u5668\u4e0a\u663e\u793a\uff0c\u4ea4\u4e92\u65b9\u5f0f\u4e5f\u4e0d\u4ec5\u4ec5\u662f\u9f20\u6807\u6216\u8005\u624b\u52bf\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u667a\u80fd\u6c7d\u8f66\u4e0a\u7684\u4e2d\u63a7\u5c4f\uff08\u4e0b\u56fe\u622a\u81ea\u5c0f\u9e4f\u6c7d\u8f66\u5b98\u7f51\uff09\uff0c\u5e26\u89e6\u6478\u80fd\u529b\u7684\u7b14\u8bb0\u672c\uff0c\u4ee5\u53ca\u53ef\u4ee5\u8fde\u63a5\u9f20\u6807\u7684\u7535\u89c6\u673a\u548c iPad \u7b49\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202112\/2021-12-13_230907.jpg\" width=\"300\" height=\"132\" alt=\"\u5c0f\u9e4f\u6c7d\u8f66\u4e2d\u63a7\u5c4f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5982\u4f55\u8ba9\u6211\u4eec\u7684\u4ea7\u54c1\u5177\u6709\u826f\u597d\u7684\u8de8\u7aef\u80fd\u529b\uff0c\u9762\u5bf9\u5404\u79cd\u8f93\u5165\u8bbe\u5907\u90fd\u6709\u826f\u597d\u7684\u4ea4\u4e92\u4f53\u9a8c\u80fd\u529b\uff0c\u5c31\u6210\u4e3a\u4e86\u65b0\u65f6\u4ee3\u7684\u6311\u6218\u3002<\/p>\n<p>\u7531\u4e8e\u8fd9\u6837\u7684\u80cc\u666f\uff0c\u51e0\u5e74\u524d\uff0c\u73b0\u4ee3\u6d4f\u89c8\u5668\u5747\u63d0\u4f9b\u4e86\u8bc6\u522b\u7528\u6237\u4ea4\u4e92\u72b6\u6001\u7684\u5a92\u4f53\u67e5\u8be2\u8bed\u6cd5\u3002<\/p>\n<h4>1. any-hover \u4e0e hover<\/h4>\n<p>\u8868\u793a\u8bbe\u5907\u662f\u5426\u2f40\u6301\u60ac\u505c\u6548\u679c\uff1f<\/p>\n<pre>@media (any-hover: hover) {\r\n  \/* \u2f40\u6301\u60ac\u505c *\/\r\n}\r\n@media (any-hover: none) {\r\n  \/* \u4e0d\u2f40\u6301\u60ac\u505c *\/\r\n}<\/pre>\n<pre>@media (hover: hover) {\r\n  \/* \u4e3b\u8f93\u2f0a\u88c5\u7f6e\u2f40\u6301\u60ac\u505c *\/\r\n}\r\n@media (hover: none) {\r\n  \/* \u4e3b\u8f93\u2f0a\u88c5\u7f6e\u4e0d\u2f40\u6301\u60ac\u505c *\/\r\n}<\/pre>\n<h4>2. any-pointer \u4e0e pointer<\/h4>\n<p>\u8868\u793a\u8bbe\u5907\u662f\u5426\u53ef\u4ee5\u7cbe\u786e\u70b9\u51fb\uff1f<\/p>\n<pre>@media (any-pointer: none) {\r\n  \/* \u4e0d\u2f40\u6301\u70b9\u51fb *\/\r\n}\r\n@media (any-pointer: coarse) {\r\n  \/* \u2f84\u5c11\u2f00\u4e2a\u88c5\u7f6e\u70b9\u51fb\u4e0d\u7cbe\u51c6 *\/\r\n}\r\n@media (any-pointer: fine) {\r\n  \/* \u6709\u88c5\u7f6e\u70b9\u51fb\u5f88\u7cbe\u51c6 *\/\r\n}<\/pre>\n<pre>@media (pointer: none) {\r\n  \/* \u4e3b\u8f93\u2f0a\u88c5\u7f6e\u70b9\u51fb\u4e0d\u53ef\u2f64 *\/\r\n}\r\n@media (pointer: coarse) {\r\n  \/* \u4e3b\u8f93\u2f0a\u88c5\u7f6e\u70b9\u51fb\u4e0d\u7cbe\u51c6 *\/\r\n}\r\n@media (pointer: fine) {\r\n  \/* \u4e3b\u8f93\u2f0a\u88c5\u7f6e\u70b9\u51fb\u7cbe\u51c6 *\/\r\n}<\/pre>\n<h4>\u4e00\u4e9b\u5e94\u7528\u573a\u666f<\/h4>\n<p>\u4f8b\u5982\uff0c\u7f51\u7ad9\u662f\u9488\u5bf9\u5927\u5c4f PC \u5f00\u53d1\u7684\uff0c\u4f46\u662f\u7528\u6237\u53ef\u80fd\u5728\u6c7d\u8f66\u5c4f\u5e55\u4e0a\u8bbf\u95ee\uff0c\u662f\u6ca1\u6709\u9f20\u6807\u7684\uff0c\u6b64\u65f6\u5982\u679c\u4f60\u7684\u4ea4\u4e92\u662f\u901a\u8fc7 hover \u60ac\u505c\u5b9e\u73b0\u7684\uff0c\u5219\u5c31\u9700\u8981\u7279\u6b8a\u5904\u7406\u4e0b\uff0c\u5426\u5219\uff0c\u5bf9\u5e94\u7684\u529f\u80fd\u6c38\u8fdc\u65e0\u6cd5\u4f7f\u7528\u3002<\/p>\n<p>\u5c31\u50cf\u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50\uff0c\u60ac\u505c\u4e0b\u62c9\u5bfc\u822a\u5728\u4e0d\u652f\u6301\u60ac\u505c\u7684\u8bbe\u5907\u4e0a\u76f4\u63a5\u663e\u793a\uff08\u5e03\u5c40\u8c03\u6574\u4ee3\u7801\u7565\uff09\uff1a<\/p>\n<pre>&lt;nav&gt;\r\n  &lt;a href&gt;\u4e3b\u5bfc\u822a&lt;\/a&gt;\r\n  &lt;div&gt;\r\n    &lt;a href&gt;\u4e0b\u62c9\u5bfc\u822az&lt;\/a&gt;\r\n    &lt;a href&gt;\u4e0b\u62c9\u5bfc\u822ax&lt;\/a&gt;\r\n    &lt;a href&gt;\u4e0b\u62c9\u5bfc\u822ax&lt;\/a&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/nav&gt;<\/pre>\n<pre>nav div {\r\n  display: none;\r\n}\r\nnav:hover div {\r\n  display: block;\r\n}\r\n\/* \u5982\u679c\u8bbe\u5907\u4e0d\u2f40\u6301hover\u60ac\u505c\uff0c\u4e0b\u62c9\u5217\u8868\u4fdd\u6301\u663e\u793a *\/\r\n@media (any-hover: none) {\r\n  nav div {\r\n    display: block;\r\n  }\r\n}<\/pre>\n<p>\u5982\u679c\u662f\u9762\u5411\u89e6\u5c4f\u8bbe\u5907\u7684\u5f00\u53d1\uff0c\u4e3a\u4e86\u517c\u5bb9\u8fde\u63a5\u4e86\u2fcf\u6807\u6216\u2f46\u7ebf\u2fcf\u6807\u7684\u573a\u666f\uff0c\u6211\u4eec\u53ef\u4ee5\u589e\u52a0 hover \u60ac\u505c\u53cd\u9988\uff1a<\/p>\n<pre>a[href]:active,\r\n  button:active {\r\n  background-image: linear-gradient(rgba(0, 0, 0, .05), rgba(0, 0, 0, .05));\r\n} \r\n@media (hover: hover) {\r\n  a[href]:hover,\r\n  button:hover {\r\n    background-image: linear-gradient(rgba(0, 0, 0, .05), rgba(0, 0, 0, .05));\r\n  }\r\n}<\/pre>\n<p>\u5982\u679c\u662f\u2faf\u5411\u684c\u2faf\u7aef\u5f00\u53d1\uff0c\u4f46\u5982\u679c\u662f\u89e6\u5c4f\u8bbe\u5907\u8bbf\u95ee\uff08\u5982 iPad\uff0c\u7269\u8054\u2f79\u5c4f\u5e55\uff09\uff0c\u53ea\u80fd\u901a\u8fc7\u624b\u6307\u64cd\u4f5c\uff0c\u6b64\u65f6\u4e3a\u4e86\u8ba9\u70b9\u51fb\u66f4\u65b9\u4fbf\uff0c\u6211\u4eec\u53ef\u4ee5\u6269\u5927\u90e8\u5206\u70b9\u51fb\u63a7\u4ef6\u7684\u9762\u79ef\u3002<\/p>\n<pre>input[type=\"checkbox\"] {\r\n  width: 20px;\r\n  height: 20px;\r\n}\r\n@media (pointer: coarse) {\r\n  input[type=\"checkbox\"] {\r\n    width: 40px;\r\n    height: 40px;\r\n  }\r\n}<\/pre>\n<p>\u4ee5\u53ca\u5176\u4ed6\u5f88\u591a\u4e0e\u4ea4\u4e92\u76f8\u5173\u7684\u573a\u666f\u3002<\/p>\n<p>\u5173\u4e8eany-hover any-pointer media\u67e5\u8be2\u5177\u4f53\u7684\u8bed\u6cd5\u3001\u517c\u5bb9\u6027\u7b49\u7ec6\u8282\u53ef\u4ee5\u53c2\u8003\u6211\u53bb\u5e74\u5e74\u521d\u5199\u7684<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2020\/01\/css-any-hover-media\/\">\u8fd9\u7bc7\u6587\u7ae0<\/a>\u3002<\/p>\n<p>\u8fd9\u91cc\u4e0d\u518d\u5c55\u5f00\u3002<\/p>\n<p><span class=\"hidden\">\/\/zxx: \u5982\u679c\u4f60\u770b\u5230\u8fd9\u6bb5\u6587\u5b57\uff0c\u8bf4\u660e\u4f60\u73b0\u5728\u8bbf\u95ee\u662f\u4e0d\u662f\u539f\u6587\u7ad9\u70b9\uff0c\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u5728\u8fd9\u91cc\uff1ahttps:\/\/www.zhangxinxu.com\/wordpress\/?p=10230\uff08\u4f5c\u8005\u5f20\u946b\u65ed\uff09<\/span><\/p>\n<h3>\u4e09\u3001\u6697\u2fca\u6a21\u5f0f\/\u6df1\u8272\u6a21\u5f0f<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202112\/2021-12-13_143055.png\" width=\"285\" height=\"278\" alt=\"\u6df1\u8272\u6a21\u5f0f\u8bbe\u7f6e\u622a\u56fe\"><\/p>\n<p>\u7528\u6765\u5224\u65ad\u7528\u6237\u662f\u5426\u5728\u7cfb\u7edf\u5c42\u9762\u8bbe\u7f6e\u4e86\u6df1\u8272\u6a21\u5f0f\uff0c\u5a92\u4f53\u67e5\u8be2\u5c5e\u6027\u662f <code>prefers-color-scheme<\/code>\uff0c\u7528\u6cd5\u793a\u610f\uff1a<\/p>\n<pre>\/* \u6df1\u2f8a\u6a21\u5f0f *\/\r\n@media (prefers-color-scheme: dark) {}\r\n\/* \u6d45\u2f8a\u6a21\u5f0f *\/\r\n@media (prefers-color-scheme: light) {}<\/pre>\n<p>\u76ee\u524d\u7528\u6237\u5728\u7cfb\u7edf\u5c42\u9762\u8bbe\u7f6e\u9ed1\u591c\u6a21\u5f0f\u7684\u6bd4\u4f8b\u5df2\u7ecf\u5f88\u9ad8\u4e86\uff0c\u5177\u4f53\u591a\u9ad8\uff0c\u8fd9\u4e2a\u6570\u636e\u4e0d\u65b9\u4fbf\u900f\u9732\uff0c\u5927\u5bb6\u53ef\u4ee5\u81ea\u884c\u5728\u81ea\u5bb6\u4ea7\u54c1\u4e2d\u57cb\u70b9\u5904\u7406\u3002<\/p>\n<h4>\u5e94\u7528\u573a\u666f<\/h4>\n<p>\u5f53\u7528\u6237\u5728\u7cfb\u7edf\u5c42\u9762\u8bbe\u7f6e\u4e86\u6697\u9ed1\u6a21\u5f0f\u540e\uff0c\u597d\u7684\u7528\u6237\u4f53\u9a8c\u5c31\u662f\u6211\u4eec\u7684 Web \u4ea7\u54c1\u81ea\u52a8\u8ffd\u968f\uff0c\u5bb9\u6613\u7ed9\u7528\u6237\u60ca\u559c\uff0c\u4e0b\u9762\u662f\u4e00\u79cd\u4f4e\u6210\u672c\u7684\u5b9e\u73b0\u65b9\u5f0f\uff1a<\/p>\n<pre>@media (prefers-color-scheme: dark) {\r\n  html, img { \r\n    filter: invert(1) hue-rotate(180deg);\r\n  }\r\n}<\/pre>\n<p>\u5177\u4f53\u5b9e\u73b0\u539f\u7406\u548c\u6548\u679c\u53ef\u4ee5\u53c2\u89c1\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2020\/11\/css-mix-blend-mode-filter-dark-theme\/\">\u51e0\u884cCSS\u8ba9\u6574\u7ad9\u652f\u6301\u6df1\u8272\u6a21\u5f0f\u7684\u63a2\u7d22\u4e0e\u62d3\u5c55<\/a>\u201d\u8fd9\u7bc7\u6587\u7ae0\u3002<\/p>\n<p>\u4e0a\u9762\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u504f\u5c55\u793a\uff0c\u4e0d\u592a\u590d\u6742\uff0c\u8fed\u4ee3\u6bd4\u8f83\u5c11\u7684\u9879\u76ee\u3002<\/p>\n<h4>\u5176\u4ed6\u788e\u788e\u5ff5<\/h4>\n<p>\u76ee\u524d\u5f88\u591a APP \u4e2d\u4f1a\u6709\u81ea\u5df1\u7684\u6df1\u8272\u6a21\u5f0f\uff0c\u8fd9\u79cd\u505a\u6cd5\u5462\uff0c\u6211\u4e0d\u4e88\u7f6e\u8bc4\u3002<\/p>\n<p>\u4ece\u6211\u4e2a\u4eba\u7684\u4ea7\u54c1\u7406\u5ff5\u6765\u770b\uff0c\u5c31\u5e94\u8be5\u8ddf\u7740\u7cfb\u7edf\u8d70\uff0c\u5426\u5219\u5f88\u5bb9\u6613\u51fa\u95ee\u9898\uff0c\u7cfb\u7edf\u4e00\u5957\uff0cAPP\u4e00\u5957\uff0cAPP\u7684\u5185\u5d4c\u9875\u8be5\u542c\u8c01\u7684\uff1f\u4e07\u4e00\u7cfb\u7edf\u624b\u4f38\u7684\u5f88\u957f\uff0c\u5c31\u5bb9\u6613\u51fa\u95ee\u9898\u3002<\/p>\n<p>\u4f46\u662f\u6709\u4e00\u70b9\u5f88\u80af\u5b9a\uff0c\u90a3\u5c31\u662f\u7eaf Web \u7684\u4ea7\u54c1\u652f\u6301\u6697\u9ed1\u6a21\u5f0f\u662f\u7edd\u5bf9\u6ca1\u6709\u95ee\u9898\u7684\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u652f\u6301\u4e86\u6df1\u8272\u6a21\u5f0f\u7684\u8bbe\u5907\u4e00\u5b9a\u652f\u6301\u6df1\u8272\u6a21\u5f0f\u7684\u67e5\u8be2\u5339\u914d\uff0c\u56e0\u6b64\uff0c\u517c\u5bb9\u6027\u8fd9\u5757\u65e0\u9700\u62c5\u5fc3\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202112\/2021-12-13_140912.png\" width=\"554\" height=\"229\" alt=\"prefers-color-scheme\u517c\u5bb9\u6027\"><\/p>\n<h3>\u56db\u3001\u2fbc\u5bf9\u2f50\u5ea6\u6a21\u5f0f<\/h3>\n<p>\u6b64\u5a92\u4f53\u67e5\u8be2\u5c5e\u6027\u540d\u79f0\u662f <code>prefers-contrast<\/code>\uff0c\u7528\u6cd5\u793a\u610f\uff1a<\/p>\n<pre>@media (prefers-contrast: more) {\r\n  \/* \u2f64\u6237\u559c\u6b22\u2fbc\u5bf9\u2f50\u5ea6 *\/\r\n}\r\n@media (prefers-contrast: less) {\r\n  \/* \u2f64\u6237\u559c\u6b22\u5bf9\u2f50\u5ea6 *\/\r\n}<\/pre>\n<p>IE \u6d4f\u89c8\u5668\u6709\u81ea\u5df1\u79c1\u6709\u7684\u67e5\u8be2\u8bed\u6cd5\uff1a<\/p>\n<pre>@media screen and (-ms-high-contrast: active) {\r\n  \/* \u2fbc\u5bf9\u2f50\u5ea6 *\/\r\n}<\/pre>\n<p>\u76ee\u524d\uff0c\u57fa\u672c\u4e0a\u6240\u6709\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u90fd\u4f1a\u6709\u8fd9\u6837\u4e00\u4e2a\u8bbe\u7f6e\uff0c\u4e3b\u8981\u662f\u65b9\u4fbf\u5f31\u89c6\uff0c\u6563\u5149\u7b49\u7fa4\u4f53\uff0c\u4ee5\u53ca\u5728\u5f3a\u5149\u573a\u666f\u4e0b\u65b9\u4fbf\u770b\u6e05\u5185\u5bb9\u3002<\/p>\n<p>\u4f8b\u5982\u5728 Windows 10 \u4e2d\u7684\u8bbe\u7f6e\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202112\/16382604557198.png\" width=\"636\" height=\"427\" alt=\"windows 10\u8bbe\u7f6e\u9ad8\u5bf9\u6bd4\u5ea6\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202112\/1638260474896.png\" width=\"583\" height=\"269\" alt=\"\u9ad8\u5bf9\u6bd4\u767d\u8272\u8bbe\u7f6e\"><\/p>\n<h4>\u4f7f\u7528\u573a\u666f<\/h4>\n<p>\u4e3a\u4e86\u8868\u73b0\u5c42\u6b21\u548c\u91cd\u8981\u7a0b\u5ea6\u7684\u533a\u5206\uff0c\u8bbe\u8ba1\u5e08\u5f80\u5f80\u4f1a\u8bbe\u8ba1\u5f88\u591a\u7070\u8272\u6587\u5b57\u3002<\/p>\n<p>\u4ee5\u53ca\uff0c\u4e3a\u4e86\u907f\u514d\u7ebf\u6761\u8fc7\u591a\u5f71\u54cd\u89c6\u89c9\u8868\u73b0\uff0c\u8bbe\u8ba1\u5e08\u4e60\u60ef\u4f7f\u7528\u975e\u5e38\u6de1\u7684\u5bbd\u5ea6\u53ea\u67090.5px\u7684\u7070\u8272\u8fb9\u6846\u3002<\/p>\n<p>\u4ee5\u53ca\u4e3a\u4e86\u8ba9\u89c6\u89c9\u8868\u73b0\u770b\u8d77\u6765\u6bd4\u8f83\u7cbe\u81f4\uff0c\u524d\u666f\u80cc\u666f\u8272\u53ef\u80fd\u662f\u540c\u4e00\u8272\u7cfb\uff0c\u5bf9\u6bd4\u5ea6\u5e76\u4e0d\u662f\u5f88\u9ad8\u3002<\/p>\n<p>\u8fd9\u4e9b\u90fd\u662f\u9ad8\u5bf9\u6bd4\u5ea6\u6a21\u5f0f\u9700\u8981\u5904\u7406\u7684\u573a\u666f\uff0c\u7070\u8272\u53d8\u9ed1\uff0c\u865a\u7ebf\u53d8\u89c6\u7ebf\uff0c\u534a\u900f\u660e\u53d8\u5b9e\u8272\uff0c\u9ed1\u767d\u5206\u660e\uff0c\u8868\u73b0\u51fa\u4f17\u3002<\/p>\n<pre>body {\r\n  --gray: #999;\r\n}\r\nhr {\r\n    border-top: 1px dashed #f0f0f0;\r\n}\r\n@media (prefers-contrast: more) {\r\n  body {\r\n    --gray: #333;\r\n  }\r\n  hr {\r\n    border-top: 1px solid gray;\r\n  }\r\n}<\/pre>\n<p>\u9ad8\u5bf9\u6bd4\u5ea6\u67e5\u8be2\u662f\u6211\u671f\u76fc\u5df2\u4e45\u7684\u67e5\u8be2\u7279\u6027\uff0c\u56e0\u4e3a\u6211\u65e9\u5c31\u5bf9\u8bbe\u8ba1\u5e08\u7684\u90a3\u79cd\u6027\u51b7\u6de1\u8bbe\u8ba1\u98ce\u683c\u4e0d\u723d\u5f88\u4e45\u4e86\uff0c\u4e0d\u8fc7\u76ee\u524d\u6d4f\u89c8\u5668\u521a\u652f\u6301\u4e0d\u4e45\uff0c\u4e1a\u52a1\u4ef7\u503c\u653e\u5927\u5230\u8db3\u591f\u5927\uff0c\u8fd8\u9700\u8981\u4e00\u4e24\u5e74\uff0c\u4f46\u662f\u8fd9\u5e76\u4e0d\u5f71\u54cd\u6211\u4eec\u73b0\u5728\u5728\u4ea7\u54c1\u4e2d\u8fdb\u884c\u8fd9\u6837\u7684\u4f53\u9a8c\u4f18\u5316\u3002<\/p>\n<p>\u5982\u679c\u4f60\u7684\u4ea7\u54c1\u4e2d\u7684\u989c\u8272\u90fd\u662f\u8d70\u7684 <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2016\/11\/css-css3-variables-var\/\">CSS \u53d8\u91cf<\/a>\u5b9e\u73b0\u7684\uff0c\u90a3\u652f\u6301\u9ad8\u5bf9\u6bd4\u5ea6\u6a21\u5f0f\u7684\u6210\u672c\u5c31\u5f88\u4f4e\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202112\/2021-12-13_144857.png\" width=\"705\" height=\"232\" alt=\"\u9ad8\u5bf9\u6bd4\u5ea6\u6a21\u5f0f\u517c\u5bb9\u6027\"><\/p>\n<h3>\u4e94\u3001\u51cf\u5f31\u52a8\u753b\u652f\u6301<\/h3>\n<p>\u51cf\u5f31\u52a8\u753b\u7684\u67e5\u8be2\u5c5e\u6027\u662f <code>prefers-reduced-motion<\/code>\uff0c\u5177\u4f53\u7528\u6cd5\u793a\u610f\u5982\u4e0b\uff1a<\/p>\n<pre>@media (prefers-reduced-motion: reduce) {\r\n  \/* \u2f64\u6237\u5e0c\u671b\u51cf\u5f31\u52a8\u753b *\/\r\n}<\/pre>\n<p>\u5728\u6240\u6709\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u5747\u6709\u5bf9\u5e94\u7684\u8bbe\u7f6e\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202112\/reduce-motion2.png\" width=\"704\" height=\"416\" alt=\"\u51cf\u5f31\u52a8\u753b\u8bbe\u7f6e\"><\/p>\n<h4>\u5e94\u7528\u573a\u666f<\/h4>\n<p>\u4e3a\u4ec0\u4e48\u9700\u8981\u51cf\u5f31\u52a8\u753b\uff0c\u6216\u8005\u8bf4\u4ec0\u4e48\u65f6\u5019\u4f1a\u89e6\u53d1\u51cf\u5f31\u52a8\u753b\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u6709\u4e9b\u4eba\u9762\u5bf9\u95ea\u70c1\u7684\u52a8\u753b\u53ef\u80fd\u4f1a\u8bf1\u53d1\u766b\u75eb\uff1b<\/li>\n<li>\u666e\u901a\u4eba\u89c9\u5f97\u5f88\u81ea\u7136\u6d41\u7545\u7684\u8fc7\u6e21\u52a8\u753b\u4f1a\u4ea7\u751f\u7c7b\u4f3c\u6655\u8f66\u7684\u53cd\u5e94\uff1b<\/li>\n<li>\u5728\u7701\u7535\u6a21\u5f0f\u4e0b\uff0c\u52a8\u753b\u4f1a\u5360\u7528\u4e0d\u5fc5\u8981\u7684\u7535\u91cf\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u51cf\u5f31\u52a8\u753b\uff1b<\/li>\n<li>\u6709\u90e8\u5206\u7528\u6237\uff0c\u7eaf\u7cb9\u5c31\u559c\u6b22\u76f4\u6765\u76f4\u5f80\u7684\u4ea4\u4e92\u6548\u679c\uff1b<\/li>\n<\/ul>\n<p>\u6240\u4ee5\uff0c\u4e3a\u4e86\u8fd9\u4e9b\u7528\u6237\uff0c\u6216\u8005\u8fd9\u7c7b\u573a\u666f\u4e0b\u6709\u66f4\u597d\u7684\u4f53\u9a8c\uff0c\u6211\u4eec\u5e94\u8be5\u5728\u51cf\u5f31\u52a8\u753b\u6a21\u5f0f\u4e0b\u5173\u95ed\u4e0d\u5fc5\u8981\u7684\u8fc7\u6e21\u548c\u52a8\u753b\u6548\u679c\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>@media (prefers-reduced-motion: reduce) {\r\n  .popup {\r\n    transition: none;\r\n  }\r\n  .overlay {\r\n    animation: none;\r\n  }\r\n}<\/pre>\n<p>\u6839\u636e\u5b9e\u9645\u7684\u57cb\u70b9\u6570\u636e\u6d4b\u8bd5\uff0c\u5728\u79fb\u52a8\u7aef\uff0c\u5339\u914d\u51cf\u5f31\u52a8\u753b\u7684\u6bd4\u4f8b\u8fdc\u8d85\u9884\u671f\uff0c\u5df2\u7ecf\u662f\u4e0d\u5f97\u4e0d\u91cd\u89c6\u7684\u7a0b\u5ea6\uff0c\u5173\u4e8e\u8fd9\u65b9\u9762\u7684\u5b9e\u8df5\uff0c\u4ee5\u540e\u4f1a\u6709\u76f8\u5173\u7684\u5185\u5bb9\u8f93\u51fa\u3002<\/p>\n<p><code>prefers-reduced-motion<\/code> \u7684\u517c\u5bb9\u6027\u8fd8\u662f\u5f88\u4e0d\u9519\u7684\uff0c2018\u5e74\u5c31\u5f00\u59cb\u652f\u6301\u4e86\uff0c\u90a3\u65f6\u5019\u8fd8\u6ca1\u6709\u75ab\u60c5\uff0c\u6211\u4eec\u60f3\u53bb\u54ea\u91cc\u5c31\u53bb\u54ea\u91cc\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202112\/2021-12-13_151147.png\" width=\"552\" height=\"233\" alt=\"prefers-reduced-motion\u517c\u5bb9\u6027\"><\/p>\n<h3>\u516d\u3001\u7ed3\u8bed<\/h3>\n<p>\u4ee5\u4e0a\u5c31\u662f\u603b\u7ed3\u7684 4 \u79cd\u4e0e\u7528\u6237\u4f53\u9a8c\u5bc6\u5207\u76f8\u5173\u7684\u5a92\u4f53\u67e5\u8be2\u4f7f\u7528\u573a\u666f\uff0c\u5728 \u300aCSS\u65b0\u4e16\u754c\u300b \u8fd9\u672c\u4e66\u4e2d\u4e5f\u6709\u8be6\u7ec6\u7684\u4ecb\u7ecd\u3002<\/p>\n<p>\u5728\u6b63\u5e38\u573a\u666f\u3001\u7406\u60f3\u72b6\u6001\u4e0b\u7684\u8dd1\u901a\u6574\u4e2a\u529f\u80fd\uff0c\u90a3\u53eb\u505a\u529f\u80fd\u5b9e\u73b0\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u539f\u578b\u3002<\/p>\n<p>\u800c\u771f\u6b63\u7684\u4ea7\u54c1\uff0c\u4e00\u5b9a\u662f\u4f1a\u987e\u53ca\u8fb9\u754c\u573a\u666f\u3001\u5f02\u5e38\u72b6\u6001\u4ee5\u53ca\u7279\u6b8a\u4eba\u7fa4\u7684\uff0c\u53ea\u6709\u628a\u65b9\u65b9\u9762\u9762\u90fd\u8003\u8651\u5230\uff0c\u5404\u4e2a\u7ec6\u8282\u90fd\u505a\u5230\u4f4d\uff0c\u624d\u7b97\u662f\u597d\u7684\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u7528\u6237\u4f53\u9a8c\u662f\u4e00\u4ef6\u975e\u5e38\u8d39\u65f6\u8d39\u529b\u7684\u4e8b\u60c5\uff0c\u5e76\u4e14\u5e76\u4e0d\u662f\u6709\u610f\u8bc6\u5c31\u80fd\u505a\u597d\u7684\uff08\u5f53\u7136\uff0c\u610f\u8bc6\u4e5f\u5f88\u91cd\u8981\uff09\uff0c\u5b83\u662f\u9700\u8981\u6709\u8db3\u591f\u7684\u524d\u7aef\u57fa\u7840\u6280\u672f\u50a8\u5907\u624d\u80fd\u5b8c\u6210\u7684\u975e\u5e38\u597d\u7684\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5185\u5bb9\uff0c\u5927\u5bb6\u5176\u5b9e\u53ef\u4ee5\u5728\u81ea\u5df1\u7684\u9879\u76ee\u4e2d\u63a8\u52a8\u4e0a\u9762\u7684\u4e00\u4e9b\u7528\u6237\u4f53\u9a8c\u7ec6\u8282\u7684\u652f\u6301\uff0c\u6210\u672c\u4e0d\u9ad8\uff0c\u6548\u679c\u5374\u633a\u597d\uff0c\u5f88\u5bb9\u6613\u51fa\u7ee9\u6548\uff0c\u5f97\u5230\u9886\u5bfc\u7684\u8ba4\u53ef\u7684\uff0c\u503c\u5f97\u4e00\u8bd5\u3002<\/p>\n<p>\u5c31\u8fd9\u4e9b\uff0c\u884c\u6587\u4ed3\u4fc3\uff0c\u5982\u679c\u8868\u8ff0\u4e0d\u5bf9\u7684\u5730\u65b9\uff0c\u6b22\u8fce\u6307\u6b63\uff0c\u4e5f\u6b22\u8fce <button onclick=\"shareWeixin.click();\">\u5206\u4eab<\/button>\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/2764.svg\" width=\"20\" height=\"20\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u6b22\u8fce\u5206\u4eab\uff0c\u52ff\u5168\u6587\u8f6c\u8f7d\uff0c\u5982\u679c\u5b9e\u5728\u559c\u6b22\uff0c\u53ef\u6536\u85cf\uff0c\u6c38\u4e0d\u8fc7\u671f\uff0c\u4e14\u4f1a\u53ca\u65f6\u66f4\u65b0\u77e5\u8bc6\u70b9\u53ca\u4fee\u6b63\u9519\u8bef\uff0c\u9605\u8bfb\u4f53\u9a8c\u4e5f\u66f4\u597d\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10230\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10230<\/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\/202112\/media-ue.jpg\" width=\"160\" height=\"100\" alt=\"media\u4e0e\u7528\u6237\u4f53\u9a8c\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>\u672c\u6587\u4ecb\u7ecd 4 \u4e2a\u5f88\u591a\u524d\u7aef\u5f00\u53d1\u4e0d\u77e5\u9053\u7684\u53ef\u4ee5\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u7684 media \u5a92\u4f53\u67e5\u8be2\u8bed\u53e5\uff0c\u5e0c\u671b\u53ef\u4ee5\u5e2e\u5230\u5927\u5bb6\u7684\u5b66\u4e60\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":[1015,1540,1541,1721,498,1560,1803,1804],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10230"}],"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=10230"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10230\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=10230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=10230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=10230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}