{"id":780,"date":"2025-12-14T14:32:20","date_gmt":"2025-12-14T06:32:20","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=780"},"modified":"2025-12-14T14:32:20","modified_gmt":"2025-12-14T06:32:20","slug":"css%e4%b8%ad%e7%9a%84static%e3%80%81relative%e3%80%81absolute%e3%80%81fixed%e3%80%81sticky%e7%9a%84%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/14\/css%e4%b8%ad%e7%9a%84static%e3%80%81relative%e3%80%81absolute%e3%80%81fixed%e3%80%81sticky%e7%9a%84%e5%ba%94%e7%94%a8\/","title":{"rendered":"CSS\u4e2d\u7684Static\u3001Relative\u3001Absolute\u3001Fixed\u3001Sticky\u7684\u5e94\u7528"},"content":{"rendered":"\n<p>\u4e0b\u9762\u662f\u4e00\u7bc7<strong>\u7ed3\u6784\u6e05\u6670\u3001\u793a\u4f8b\u5b8c\u6574\u3001\u9002\u5408\u6559\u7a0b\/\u535a\u5ba2\u53d1\u5e03\u7684\u6587\u7ae0<\/strong>\uff0c\u7cfb\u7edf\u8bb2\u89e3 <strong>CSS \u4e2d\u7684 Static\u3001Relative\u3001Absolute\u3001Fixed\u3001Sticky \u5b9a\u4f4d\u7684\u5e94\u7528\u4e0e\u533a\u522b<\/strong>\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">CSS \u4e2d\u7684 Static\u3001Relative\u3001Absolute\u3001Fixed\u3001Sticky \u7684\u5e94\u7528\u8be6\u89e3<\/h1>\n\n\n\n<p>\u5728 CSS \u5e03\u5c40\u4e2d\uff0c<code>position<\/code> \u5c5e\u6027\u51b3\u5b9a\u4e86\u5143\u7d20\u5728\u9875\u9762\u4e2d\u7684\u5b9a\u4f4d\u65b9\u5f0f\u3002\u7406\u89e3\u5e76\u719f\u7ec3\u4f7f\u7528\u4e0d\u540c\u7684\u5b9a\u4f4d\u7c7b\u578b\uff0c\u662f\u5199\u597d\u9875\u9762\u5e03\u5c40\u7684\u57fa\u7840\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001position \u5c5e\u6027\u6982\u89c8<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nposition: static | relative | absolute | fixed | sticky;\n\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u5b9a\u4f4d\u65b9\u5f0f<\/th><th>\u662f\u5426\u8131\u79bb\u6587\u6863\u6d41<\/th><th>\u5e38\u89c1\u7528\u9014<\/th><\/tr><\/thead><tbody><tr><td>static<\/td><td>\u5426<\/td><td>\u9ed8\u8ba4\u5e03\u5c40<\/td><\/tr><tr><td>relative<\/td><td>\u5426<\/td><td>\u5fae\u8c03\u4f4d\u7f6e\u3001\u4f5c\u4e3a\u5b9a\u4f4d\u53c2\u7167<\/td><\/tr><tr><td>absolute<\/td><td>\u662f<\/td><td>\u5f39\u7a97\u3001\u89d2\u6807\u3001\u8986\u76d6\u5143\u7d20<\/td><\/tr><tr><td>fixed<\/td><td>\u662f<\/td><td>\u56fa\u5b9a\u5bfc\u822a\u680f\u3001\u60ac\u6d6e\u6309\u94ae<\/td><\/tr><tr><td>sticky<\/td><td>\u5426\uff08\u6eda\u52a8\u540e\u7c7b\u4f3c fixed\uff09<\/td><td>\u5438\u9876\u6548\u679c<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001Static\uff08\u9ed8\u8ba4\u5b9a\u4f4d\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u7279\u70b9<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6240\u6709\u5143\u7d20\u7684\u9ed8\u8ba4\u503c<\/strong><\/li>\n\n\n\n<li>\u4e0d\u652f\u6301 <code>top \/ left \/ right \/ bottom<\/code><\/li>\n\n\n\n<li>\u6309\u6b63\u5e38\u6587\u6863\u6d41\u6392\u5217<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndiv {\n  position: static;\n}\n\n<\/pre><\/div>\n\n\n<p>\ud83d\udccc <strong>\u4f7f\u7528\u573a\u666f<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u666e\u901a\u6587\u672c\u3001\u6bb5\u843d\u3001\u5217\u8868<\/li>\n\n\n\n<li>\u4e0d\u9700\u8981\u7279\u6b8a\u5e03\u5c40\u7684\u5143\u7d20<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001Relative\uff08\u76f8\u5bf9\u5b9a\u4f4d\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u7279\u70b9<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u76f8\u5bf9\u4e8e\u5143\u7d20\u539f\u672c\u7684\u4f4d\u7f6e\u504f\u79fb<\/strong><\/li>\n\n\n\n<li>\u4e0d\u8131\u79bb\u6587\u6863\u6d41<\/li>\n\n\n\n<li>\u5e38\u4f5c\u4e3a <code>absolute<\/code> \u7684\u53c2\u8003\u7236\u5143\u7d20<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.box {\n  position: relative;\n  top: 10px;\n  left: 20px;\n}\n\n<\/pre><\/div>\n\n\n<p>\ud83d\udccc <strong>\u4f7f\u7528\u573a\u666f<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8f7b\u5fae\u8c03\u6574\u5143\u7d20\u4f4d\u7f6e<\/li>\n\n\n\n<li>\u4e3a\u5b50\u5143\u7d20\u63d0\u4f9b\u5b9a\u4f4d\u57fa\u51c6<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001Absolute\uff08\u7edd\u5bf9\u5b9a\u4f4d\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u7279\u70b9<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8131\u79bb\u6587\u6863\u6d41<\/strong><\/li>\n\n\n\n<li>\u76f8\u5bf9\u4e8e\u6700\u8fd1\u7684 <strong>\u975e static \u7236\u5143\u7d20<\/strong><\/li>\n\n\n\n<li>\u82e5\u65e0\uff0c\u5219\u76f8\u5bf9\u4e8e <code>body<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.parent {\n  position: relative;\n}\n\n.child {\n  position: absolute;\n  top: 0;\n  right: 0;\n}\n\n<\/pre><\/div>\n\n\n<p>\ud83d\udccc <strong>\u4f7f\u7528\u573a\u666f<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f39\u7a97\u3001\u63d0\u793a\u6846<\/li>\n\n\n\n<li>\u89d2\u6807\uff08\u53f3\u4e0a\u89d2\u7ea2\u70b9\uff09<\/li>\n\n\n\n<li>\u8986\u76d6\u5728\u56fe\u7247\u4e0a\u7684\u6587\u5b57<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001Fixed\uff08\u56fa\u5b9a\u5b9a\u4f4d\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u7279\u70b9<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8131\u79bb\u6587\u6863\u6d41<\/strong><\/li>\n\n\n\n<li>\u76f8\u5bf9\u4e8e <strong>\u6d4f\u89c8\u5668\u7a97\u53e3<\/strong><\/li>\n\n\n\n<li>\u9875\u9762\u6eda\u52a8\u65f6\u4f4d\u7f6e\u4e0d\u53d8<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.nav {\n  position: fixed;\n  top: 0;\n  width: 100%;\n}\n\n<\/pre><\/div>\n\n\n<p>\ud83d\udccc <strong>\u4f7f\u7528\u573a\u666f<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9876\u90e8\u5bfc\u822a\u680f<\/li>\n\n\n\n<li>\u8fd4\u56de\u9876\u90e8\u6309\u94ae<\/li>\n\n\n\n<li>\u60ac\u6d6e\u5ba2\u670d\u6309\u94ae<\/li>\n<\/ul>\n\n\n\n<p>\u26a0\ufe0f \u6ce8\u610f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u79fb\u52a8\u7aef\u9700\u7559\u610f\u906e\u6321\u5185\u5bb9<\/li>\n\n\n\n<li>\u5e38\u914d\u5408 <code>z-index<\/code><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001Sticky\uff08\u7c98\u6027\u5b9a\u4f4d\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u7279\u70b9<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u76f8\u5bf9\u5b9a\u4f4d + \u56fa\u5b9a\u5b9a\u4f4d\u7684\u7ed3\u5408<\/strong><\/li>\n\n\n\n<li>\u5728\u6307\u5b9a\u8303\u56f4\u5185\u6eda\u52a8\u65f6\u56fa\u5b9a<\/li>\n\n\n\n<li>\u4e0d\u8131\u79bb\u6587\u6863\u6d41<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.header {\n  position: sticky;\n  top: 0;\n}\n\n<\/pre><\/div>\n\n\n<p>\ud83d\udccc <strong>\u4f7f\u7528\u573a\u666f<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5438\u9876\u5bfc\u822a<\/li>\n\n\n\n<li>\u8868\u683c\u8868\u5934\u56fa\u5b9a<\/li>\n\n\n\n<li>\u76ee\u5f55\u8ddf\u968f\u6eda\u52a8<\/li>\n<\/ul>\n\n\n\n<p>\u26a0\ufe0f \u6ce8\u610f\u4e8b\u9879\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7236\u5143\u7d20\u4e0d\u80fd\u8bbe\u7f6e <code>overflow: hidden<\/code><\/li>\n\n\n\n<li>\u5fc5\u987b\u6307\u5b9a <code>top \/ left<\/code> \u7b49\u503c<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e03\u3001\u4e94\u79cd\u5b9a\u4f4d\u65b9\u5f0f\u5bf9\u6bd4\u603b\u7ed3<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u5c5e\u6027<\/th><th>\u8131\u79bb\u6587\u6863\u6d41<\/th><th>\u53c2\u8003\u5bf9\u8c61<\/th><th>\u662f\u5426\u968f\u6eda\u52a8<\/th><\/tr><\/thead><tbody><tr><td>static<\/td><td>\u274c<\/td><td>\u6587\u6863\u6d41<\/td><td>\u2705<\/td><\/tr><tr><td>relative<\/td><td>\u274c<\/td><td>\u81ea\u8eab<\/td><td>\u2705<\/td><\/tr><tr><td>absolute<\/td><td>\u2705<\/td><td>\u6700\u8fd1\u5b9a\u4f4d\u7236\u7ea7<\/td><td>\u274c<\/td><\/tr><tr><td>fixed<\/td><td>\u2705<\/td><td>\u6d4f\u89c8\u5668\u7a97\u53e3<\/td><td>\u274c<\/td><\/tr><tr><td>sticky<\/td><td>\u274c<\/td><td>\u7236\u5bb9\u5668<\/td><td>\u90e8\u5206\u56fa\u5b9a<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u516b\u3001\u5e38\u89c1\u7ec4\u5408\u7528\u6cd5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1\ufe0f\u20e3 \u7236 Relative + \u5b50 Absolute\uff08\u6700\u7ecf\u5178\uff09<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.card {\n  position: relative;\n}\n.badge {\n  position: absolute;\n  top: 0;\n  right: 0;\n}\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">2\ufe0f\u20e3 Fixed + z-index<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.float-btn {\n  position: fixed;\n  bottom: 20px;\n  right: 20px;\n  z-index: 999;\n}\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">3\ufe0f\u20e3 Sticky \u5438\u9876\u5bfc\u822a<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.nav {\n  position: sticky;\n  top: 0;\n  background: #fff;\n}\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e5d\u3001\u65b0\u624b\u5e38\u89c1\u9519\u8bef<\/h2>\n\n\n\n<p>\u274c \u5fd8\u8bb0\u7ed9\u7236\u5143\u7d20\u8bbe\u7f6e <code>position: relative<\/code><br>\u274c Sticky \u7236\u5bb9\u5668\u8bbe\u7f6e\u4e86 <code>overflow: hidden<\/code><br>\u274c Fixed \u5143\u7d20\u906e\u6321\u5185\u5bb9\u4f46\u672a\u9884\u7559\u7a7a\u95f4<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5341\u3001\u603b\u7ed3\u4e00\u53e5\u8bdd\u8bb0\u5fc6\u6cd5<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>Static \u6b63\u5e38\u8d70\uff0cRelative \u5fae\u8c03\u4f4d\uff1b<br>Absolute \u627e\u7239\u8d70\uff0cFixed \u8ddf\u7a97\u53e3\uff1b<br>Sticky \u6eda\u5230\u70b9\uff0c\u5c31\u7c98\u4f4f\u3002<\/strong><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u662f\u4e00\u7bc7\u7ed3\u6784\u6e05\u6670\u3001\u793a\u4f8b\u5b8c\u6574\u3001\u9002\u5408\u6559\u7a0b\/\u535a\u5ba2\u53d1\u5e03\u7684\u6587\u7ae0\uff0c\u7cfb\u7edf\u8bb2\u89e3 CSS \u4e2d\u7684 &#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/14\/css%e4%b8%ad%e7%9a%84static%e3%80%81relative%e3%80%81absolute%e3%80%81fixed%e3%80%81sticky%e7%9a%84%e5%ba%94%e7%94%a8\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-780","post","type-post","status-publish","format-standard","hentry","category-css"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=780"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/780\/revisions"}],"predecessor-version":[{"id":781,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/780\/revisions\/781"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}