--- title: overflow-anchor slug: Web/CSS/overflow-anchor tags: - CSS - CSS Scroll Anchoring translation_of: Web/CSS/overflow-anchor --- <div>{{CSSRef}}</div> <p><strong><code>overflow-anchor</code></strong> <a href="/en-US/docs/Web/CSS">CSS</a> 属性提供一种退出浏览器滚动锚定行为的方法,该行为会调整滚动位置以最大程度地减少内容偏移。</p> <p>默认情况下,在任何支持滚动锚定行为的浏览器中都将其启用。因此,仅当您在文档或文档的一部分中遇到滚动锚定问题并且需要关闭行为时,才通常需要更改此属性的值。</p> <h2 id="语法">语法</h2> <pre class="brush:css no-line-numbers">/* Keyword values */ overflow-anchor: auto; overflow-anchor: none; /* Global values */ overflow-anchor: inherit; overflow-anchor: initial; overflow-anchor: unset; </pre> <h3 id="Values">Values</h3> <dl> <dt><code>auto</code></dt> <dd>The element becomes a potential anchor when adjusting scroll position.</dd> <dt><code>none</code></dt> <dd>The element won't be selected as a potential anchor.</dd> </dl> <h3 id="Formal_syntax">Formal syntax</h3> {{csssyntax}} <h2 id="范例">范例</h2> <p>To prevent scroll anchoring in a document, use the <code>overflow-anchor</code> property.</p> <pre class="brush: css">body { overflow-anchor: none; } </pre> <ul> </ul> <h2 id="规范">规范</h2> <table class="standard-table"> <thead> <tr> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('CSS Scroll Anchoring', '#propdef-overflow-anchor', 'overflow-anchor')}}</td> <td>{{Spec2('CSS Scroll Anchoring')}}</td> <td>Initial definition.</td> </tr> </tbody> </table> <p>{{cssinfo}}</p> <h2 id="浏览器兼容性">浏览器兼容性</h2> <p>{{Compat("css.properties.overflow-anchor")}}</p> <h2 id="See_also">See also</h2> <ul> <li><a href="/en-US/docs/Web/CSS/overflow-anchor/Guide_to_scroll_anchoring">Guide to scroll anchoring</a></li> </ul> <div id="gtx-trans" style="position: absolute; left: 385px; top: 1589px;"> <div class="gtx-trans-icon"></div> </div>