{"id":27962,"date":"2024-11-24T14:00:22","date_gmt":"2024-11-24T06:00:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27962\/"},"modified":"2024-11-24T14:00:22","modified_gmt":"2024-11-24T06:00:22","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-css-%e5%92%8c%e5%b0%91%e9%87%8f-javascript-%e5%ae%9e%e7%8e%b0%e4%b8%a4%e8%a1%8c%e6%96%87%e5%ad%97%e7%9c%81%e7%95%a5%e4%bb%a5%e5%8f%8a%e5%8a%a8%e6%80%81%e5%9d%97","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27962\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 CSS \u548c\u5c11\u91cf JavaScript \u5b9e\u73b0\u4e24\u884c\u6587\u5b57\u7701\u7565\u4ee5\u53ca\u52a8\u6001\u5757\u72b6\u5185\u5bb9\u8ddf\u968f\u5c55\u793a\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173137159833604.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 CSS \u548c\u5c11\u91cf JavaScript \u5b9e\u73b0\u4e24\u884c\u6587\u5b57\u7701\u7565\u4ee5\u53ca\u52a8\u6001\u5757\u72b6\u5185\u5bb9\u8ddf\u968f\u5c55\u793a\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 CSS \u548c\u5c11\u91cf JavaScript \u5b9e\u73b0\u4e24\u884c\u6587\u5b57\u7701\u7565\u4ee5\u53ca\u52a8\u6001\u5757\u72b6\u5185\u5bb9\u8ddf\u968f\u5c55\u793a\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728\u7f51\u9875\u4e0a\u5b9e\u73b0\u4e24\u884c\u6587\u5b57\u7701\u7565\u5e76\u8ddf\u968f\u52a8\u6001\u5757\u72b6\u5185\u5bb9<\/strong><\/p>\n<p>\u5982\u4f55\u4f7f\u7528  \u6216\u5c11\u91cf javascript \u6765\u5b9e\u73b0\u5982\u56fe\u6240\u793a\u7684\u6548\u679c\uff0c\u5373\u5728\u4e0d\u786e\u5b9a\u6587\u6848\u957f\u5ea6\u7684\u60c5\u51b5\u4e0b\uff0c\u5bf9\u4e24\u884c\u6587\u5b57\u8fdb\u884c\u7701\u7565\uff0c\u5e76\u4f7f\u52a8\u6001\u5757\u72b6\u5185\u5bb9\u8ddf\u968f\u6587\u5b57\u5c55\u793a\uff1f<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p><strong>\u4f7f\u7528 css<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>.ellipsis {\n  display: -webkit-box;\n  -webkit-line-clamp: 2;\n  -webkit-box-orient: vertical;\n  overflow: hidden;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u5c11\u91cf javascript<\/strong><\/p>\n<pre>const ellipsisElements = document.querySelectorAll('.ellipsis');\nfor (const element of ellipsisElements) {\n  if (element.scrollHeight &gt; element.offsetHeight) {\n    element.classList.add('overflow');\n  }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6f14\u793a<\/strong><\/p>\n<p>https:\/\/codepen.io\/xboxyan\/pen\/popwvnx<\/p>\n<p><strong>\u53c2\u8003<\/strong><\/p>\n<ul>\n<li>https:\/\/segmentfault.com\/a\/1190000040172089<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 CSS \u548c\u5c11\u91cf JavaScript \u5b9e\u73b0\u4e24\u884c\u6587\u5b57\u7701\u7565\u4ee5\u53ca\u52a8\u6001\u5757\u72b6\u5185\u5bb9\u8ddf\u968f\u5c55\u793a\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>\u5728\u7f51\u9875\u4e0a\u5b9e\u73b0\u4e24\u884c\u6587\u5b57\u7701\u7565\u5e76\u8ddf\u968f\u52a8\u6001\u5757\u72b6\u5185\u5bb9 \u5982\u4f55\u4f7f\u7528 \u6216\u5c11\u91cf javascript \u6765\u5b9e\u73b0\u5982\u56fe\u6240\u793a\u7684\u6548\u679c\uff0c\u5373\u5728\u4e0d\u786e\u5b9a\u6587\u6848\u957f\u5ea6\u7684\u60c5\u51b5\u4e0b\uff0c\u5bf9\u4e24\u884c\u6587\u5b57\u8fdb\u884c\u7701\u7565\uff0c\u5e76\u4f7f\u52a8\u6001\u5757\u72b6\u5185\u5bb9\u8ddf\u968f\u6587\u5b57\u5c55\u793a\uff1f \u89e3\u51b3\u65b9\u6848 \u4f7f\u7528 css \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b .ellipsis { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; } \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u5c11\u91cf javascript const ellipsisElements = document.querySelectorAll(&#8216;.ellipsis&#8217;); for (const element of ellipsisElements) { if (element.scrollHeight &gt; element.offsetHeight) { element.classList.add(&#8216;overflow&#8217;); } } \u767b\u5f55\u540e\u590d\u5236 \u6f14\u793a https:\/\/codepen.io\/xboxyan\/pen\/popwvnx \u53c2\u8003 https:\/\/segmentfault.com\/a\/1190000040172089 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 CSS \u548c\u5c11\u91cf JavaScript \u5b9e\u73b0\u4e24\u884c\u6587\u5b57\u7701\u7565\u4ee5\u53ca\u52a8\u6001\u5757\u72b6\u5185\u5bb9\u8ddf\u968f\u5c55\u793a\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-27962","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27962","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=27962"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27962\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27962"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}