{"id":604,"date":"2024-12-28T18:01:23","date_gmt":"2024-12-28T10:01:23","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=604"},"modified":"2024-12-28T18:01:23","modified_gmt":"2024-12-28T10:01:23","slug":"%e4%b8%8d%e4%bf%ae%e6%94%b9-html-%e4%bb%a3%e7%a0%81-%e7%9a%84%e6%83%85%e5%86%b5%e4%b8%8b%e9%9a%90%e8%97%8f-html-%e4%b8%ad%e6%9c%aa%e6%a0%87%e8%ae%b0%e7%9a%84%e6%96%87%e6%9c%ac%ef%bc%8c%e9%80%9a","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2024\/12\/28\/%e4%b8%8d%e4%bf%ae%e6%94%b9-html-%e4%bb%a3%e7%a0%81-%e7%9a%84%e6%83%85%e5%86%b5%e4%b8%8b%e9%9a%90%e8%97%8f-html-%e4%b8%ad%e6%9c%aa%e6%a0%87%e8%ae%b0%e7%9a%84%e6%96%87%e6%9c%ac%ef%bc%8c%e9%80%9a\/","title":{"rendered":"\u4e0d\u4fee\u6539 HTML \u4ee3\u7801\u00a0\u7684\u60c5\u51b5\u4e0b\u9690\u85cf HTML \u4e2d\u672a\u6807\u8bb0\u7684\u6587\u672c\uff0c\u901a\u8fc7\u00a0CSS\u00a0\u548c\u00a0\u4f2a\u5143\u7d20\u600e\u6837\u5b9e\u73b0\uff1f"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u8981\u5728 <strong>\u4e0d\u4fee\u6539 HTML \u4ee3\u7801<\/strong> \u7684\u60c5\u51b5\u4e0b\u9690\u85cf HTML \u4e2d\u672a\u6807\u8bb0\u7684\u6587\u672c\uff0c\u53ef\u4ee5\u901a\u8fc7 <strong>CSS<\/strong> \u548c <strong>\u4f2a\u5143\u7d20<\/strong> \u6765\u5b9e\u73b0\u3002\u5177\u4f53\u65b9\u6cd5\u53d6\u51b3\u4e8e\u4f60\u60f3\u9690\u85cf\u54ea\u4e9b\u6587\u672c\uff0c\u5982\u4f55\u5b9a\u4f4d\u8fd9\u4e9b\u6587\u672c\u3002\u4ee5\u4e0b\u662f\u51e0\u79cd\u53ef\u80fd\u7684\u5b9e\u73b0\u65b9\u5f0f\uff1a<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u4f7f\u7528 <code>::before<\/code> \u6216 <code>::after<\/code> \u4f2a\u5143\u7d20<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u5e0c\u671b\u9690\u85cf\u5bb9\u5668\u4e2d\u6ca1\u6709\u88ab\u6807\u8bb0\u7684\u7eaf\u6587\u672c\uff08\u4f8b\u5982\uff0c\u67d0\u4e9b\u6587\u672c\u6ca1\u6709\u88ab\u5305\u88f9\u5728\u6807\u7b7e\u4e2d\uff09\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u7528\u4f2a\u5143\u7d20\u6765\u8986\u76d6\u6587\u672c\u5185\u5bb9\u6216\u9690\u85cf\u5b83\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u4f7f\u7528 <code>::before<\/code> \u8986\u76d6\u5185\u5bb9<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u6ca1\u6709\u4efb\u4f55\u6807\u7b7e\u5305\u88f9\u7684\u6587\u672c\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u4e00\u4e2a\u4f2a\u5143\u7d20\u5e76\u8ba9\u5b83\u8986\u76d6\u539f\u59cb\u6587\u672c\uff0c\u4ece\u800c\u201c\u9690\u85cf\u201d\u5b83\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* \u5bf9\u6ca1\u6709\u5b50\u5143\u7d20\u7684\u7236\u5143\u7d20\u5e94\u7528\u6837\u5f0f *\/\ndiv:not(:has(*)) {\n  position: relative;\n}\n\ndiv:not(:has(*))::before {\n  content: \"\";\n  position: absolute;\n  top: 0;\n  left: 0;\n  right: 0;\n  bottom: 0;\n  background-color: white; \/* \u8986\u76d6\u6587\u672c\u7684\u80cc\u666f\u8272 *\/\n  z-index: 1;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<strong><code>div:not(:has(*))<\/code><\/strong> \u4f1a\u9009\u4e2d\u6ca1\u6709\u5b50\u5143\u7d20\u7684 <code>div<\/code>\uff0c\u7136\u540e\u901a\u8fc7 <code>::before<\/code> \u4f2a\u5143\u7d20\u4f7f\u7528 <code>background-color<\/code> \u5c06\u6587\u672c\u906e\u76d6\u6389\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>:has()<\/code> \u4f2a\u7c7b\u9009\u62e9\u5668\u662f\u65b0\u7684 CSS \u9009\u62e9\u5668\uff0c\u5b83\u53ef\u4ee5\u5339\u914d\u5305\u542b\u7279\u5b9a\u5b50\u5143\u7d20\u7684\u7236\u5143\u7d20\u3002\u4e0d\u8fc7\uff0c\u5b83\u5e76\u4e0d\u662f\u6240\u6709\u6d4f\u89c8\u5668\u90fd\u652f\u6301\u7684\uff08\u76ee\u524d\u4e3b\u8981\u5728\u8f83\u65b0\u7684\u6d4f\u89c8\u5668\u4e2d\u652f\u6301\uff09\uff0c\u5982\u679c\u4f60\u4f7f\u7528\u7684\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u91c7\u7528\u5176\u4ed6\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u4f7f\u7528 <code>visibility: hidden<\/code> \u6216 <code>display: none<\/code> \u9690\u85cf\u6587\u672c<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u77e5\u9053\u67d0\u4e9b\u6587\u672c\u4f4d\u4e8e\u7279\u5b9a\u7684\u6807\u7b7e\u6216\u5bb9\u5668\u5185\uff08\u4f8b\u5982\uff0c\u6240\u6709\u672a\u6807\u8bb0\u7684\u6587\u672c\u90fd\u4f4d\u4e8e\u67d0\u4e2a\u7279\u5b9a\u7c7b\u7684 <code>div<\/code> \u4e2d\uff09\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>visibility: hidden<\/code> \u6216 <code>display: none<\/code> \u6765\u9690\u85cf\u5b83\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  visibility: hidden;\n}\n\ndiv &gt; * {\n  visibility: visible;\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>visibility: hidden<\/code> \u4f1a\u9690\u85cf\u5143\u7d20\uff0c\u4f46\u4ecd\u7136\u5360\u636e\u7a7a\u95f4\u3002<\/li>\n\n\n\n<li><code>div > *<\/code> \u9009\u62e9\u6240\u6709 <code>div<\/code> \u4e2d\u7684\u76f4\u63a5\u5b50\u5143\u7d20\uff0c\u901a\u8fc7\u8bbe\u7f6e <code>visibility: visible<\/code> \u4f7f\u5b83\u4eec\u4fdd\u6301\u53ef\u89c1\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u5229\u7528 <code>text-indent<\/code> \u6216 <code>position<\/code> \u5c06\u6587\u672c\u79fb\u51fa\u89c6\u53e3<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u60f3\u9690\u85cf\u6587\u672c\uff0c\u4f46\u4ecd\u4fdd\u7559\u5176\u5360\u636e\u7684\u7a7a\u95f4\uff0c\u53ef\u4ee5\u901a\u8fc7\u5c06\u6587\u672c\u79fb\u51fa\u89c6\u53e3\u6765\u5b9e\u73b0\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  text-indent: -9999px; \/* \u5c06\u6587\u672c\u79fb\u51fa\u89c6\u53e3 *\/\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>text-indent: -9999px<\/code> \u4f1a\u5c06\u5bb9\u5668\u5185\u7684\u6240\u6709\u6587\u672c\u79fb\u51fa\u89c6\u53e3\u4e4b\u5916\uff0c\u4f7f\u5176\u4e0d\u53ef\u89c1\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u6216\u8005\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528 <code>position<\/code> \u5c06\u6587\u672c\u79fb\u51fa\u89c6\u53e3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  position: absolute;\n  left: -9999px;\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>position: absolute<\/code> \u5c06\u6587\u672c\u4ece\u6b63\u5e38\u7684\u6587\u6863\u6d41\u4e2d\u79fb\u9664\uff0c\u5e76\u4f7f\u7528 <code>left: -9999px<\/code> \u5c06\u5176\u79fb\u5230\u5c4f\u5e55\u5916\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u4f7f\u7528 CSS \u5185\u5bb9\u9690\u85cf\u7279\u5b9a\u7c7b\u7684\u6587\u672c<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u6709\u4e00\u90e8\u5206\u672a\u6807\u8bb0\u7684\u6587\u672c\u4f4d\u4e8e\u67d0\u4e2a\u7279\u5b9a\u7684\u7c7b\u6216\u5143\u7d20\u5185\uff08\u4f8b\u5982 <code>.hidden-text<\/code>\uff09\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7 <code>::before<\/code> \u6216 <code>::after<\/code> \u4f2a\u5143\u7d20\u6765\u8986\u76d6\u6216\u66ff\u4ee3\u5b83\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>.hidden-text {\n  color: transparent;  \/* \u5c06\u6587\u672c\u989c\u8272\u8bbe\u4e3a\u900f\u660e *\/\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>color: transparent<\/code> \u4f1a\u4f7f\u6587\u672c\u53d8\u4e3a\u900f\u660e\uff0c\u4ece\u800c\u8ba9\u5b83\u201c\u6d88\u5931\u201d\uff0c\u4f46\u5b83\u4ecd\u7136\u5360\u636e\u9875\u9762\u4e0a\u7684\u7a7a\u95f4\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>\u4f7f\u7528 JavaScript \u52a8\u6001\u9690\u85cf\u6587\u672c\uff08\u5982\u679c\u5141\u8bb8\u4f7f\u7528 JavaScript\uff09<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u53ef\u4ee5\u4f7f\u7528 JavaScript\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee DOM \u5143\u7d20\u6765\u9690\u85cf\u672a\u6807\u8bb0\u7684\u6587\u672c\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>document.querySelectorAll('div').forEach(function(div) {\n  \/\/ \u5982\u679c div \u4e2d\u6ca1\u6709\u4efb\u4f55\u5b50\u5143\u7d20\uff08\u5373\u7eaf\u6587\u672c\uff09\uff0c\u5219\u9690\u85cf\u5b83\n  if (div.children.length === 0) {\n    div.style.display = 'none';\n  }\n});<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>::before<\/code> \u548c <code>::after<\/code><\/strong> \u4f2a\u5143\u7d20\u53ef\u4ee5\u8986\u76d6\u672a\u6807\u8bb0\u7684\u6587\u672c\u5185\u5bb9\u3002<\/li>\n\n\n\n<li><strong><code>visibility: hidden<\/code> \u6216 <code>display: none<\/code><\/strong> \u53ef\u7528\u4e8e\u9690\u85cf\u7279\u5b9a\u5143\u7d20\u4e2d\u7684\u6587\u672c\u3002<\/li>\n\n\n\n<li><strong><code>text-indent<\/code> \u6216 <code>position<\/code><\/strong> \u53ef\u4ee5\u5c06\u6587\u672c\u79fb\u51fa\u89c6\u53e3\uff0c\u4f7f\u5176\u4e0d\u53ef\u89c1\u3002<\/li>\n\n\n\n<li><strong><code>color: transparent<\/code><\/strong> \u53ef\u4ee5\u5c06\u6587\u672c\u989c\u8272\u53d8\u4e3a\u900f\u660e\uff0c\u8fbe\u6210\u201c\u9690\u85cf\u201d\u7684\u6548\u679c\u3002<\/li>\n\n\n\n<li><strong>JavaScript<\/strong> \u662f\u6700\u540e\u7684\u624b\u6bb5\uff0c\u5982\u679c\u53ef\u4ee5\u4f7f\u7528\uff0c\u53ef\u4ee5\u52a8\u6001\u5730\u5220\u9664\u6216\u9690\u85cf\u672a\u6807\u8bb0\u7684\u6587\u672c\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u4f60\u7684\u9700\u6c42\u548c\u662f\u5426\u53ef\u4ee5\u4f7f\u7528 JavaScript\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8981\u5728 \u4e0d\u4fee\u6539 HTML \u4ee3\u7801 \u7684\u60c5\u51b5\u4e0b\u9690\u85cf HTML \u4e2d\u672a\u6807\u8bb0\u7684\u6587\u672c\uff0c\u53ef\u4ee5\u901a\u8fc7 CSS \u548c \u4f2a\u5143\u7d20 \u6765\u5b9e\u73b0\u3002\u5177 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[],"class_list":["post-604","post","type-post","status-publish","format-standard","hentry","category-css"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=604"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/604\/revisions"}],"predecessor-version":[{"id":605,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/604\/revisions\/605"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}