html - Foundation 6 粘性布局在移动设备中损坏

标签 html css mobile sticky zurb-foundation-6

我在 Foundation 6.4.3 上使用 Sticky 时发现了一个棘手的问题。粘性容器会下降到页面下方,并在它和 anchor 容器之间形成一个很大的间隙。有人也有这个问题吗?

屏幕截图 Foundation 6 Sticky layout broken in mobile

$(document).foundation();
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.4.3/css/foundation.min.css"/>
    
    <div class="grid-container">
      <div class="grid-x grid-margin-x">
        <div class="small-12 large-9 cell" id="sidebar-anchor">
          <div style="height: 900px; background-color: purple; ">
            main column
          </div>
        </div>
        <div class="small-12 large-3 cell">
          <div data-sticky-container>
            <div class="sticky" data-sticky data-margin-top="1" data-sticky-on="large" data-anchor="sidebar-anchor">
              <div style="height: 500px; background-color: yellow; ">
                sidebar
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/what-input/5.0.5/what-input.min.js"></script>
    <!-- Compressed JavaScript -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.4.3/js/foundation.min.js"></script>
    

最佳答案

你应该在黄色背景 div 上尝试 position:sticky

$(document).foundation();
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.4.3/css/foundation.min.css"/>
    
    <div class="grid-container">
      <div class="grid-x grid-margin-x">
        <div class="small-12 large-9 cell" id="sidebar-anchor">
          <div style="height: 900px; background-color: purple; ">
            main column
          </div>
        </div>
        <div class="small-12 large-3 cell">
          <div data-sticky-container>
            <div class="sticky" data-sticky data-margin-top="1" data-sticky-on="large" data-anchor="sidebar-anchor" style="position:sticky">
              <div style="height: 500px; background-color: yellow; ">
                sidebar
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/what-input/5.0.5/what-input.min.js"></script>
    <!-- Compressed JavaScript -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.4.3/js/foundation.min.js"></script>

关于html - Foundation 6 粘性布局在移动设备中损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49728620/

相关文章:

html - 添加多个类 html

javascript - 是否可以用 Javascript 编写纯文本?

html - Div 不随内容增长

jquery - 移动设备上的下拉导航

java - 为 Windows Mobile 6.1 选项编写应用程序?

javascript - 根据内容改变父div的宽度

css - 无法摆脱一些填充

jquery - 与 css :active 结合使用时不会触发点击事件

css - 浏览器处于兼容模式时如何使伪元素工作?

Java ME : How to wipe all information from a device