简体   繁体   English

Bootstrap——相互替换的“sticky-top”元素

[英]Bootstrap--"sticky-top" elements that replace each other

on the Bootstrap Cheatsheet page , two things are happening:Bootstrap Cheatsheet 页面上,发生了两件事:

(1) the elements on the left of the page are respecting the header as the top, and sticking to the bottom of the header, and (1) 页面左侧的元素以页眉为上,紧贴页眉底部,

(2) the elements on the left-hand side of the page are replacing each other, and "bumping each other off the top," as sticky-top elements. (2) 页面左侧的元素相互替换,并且“从顶部相互碰撞”,作为置顶元素。

How are they doing this?他们是怎么做到的? I have been picking apart the html of that page to try to figure it out, but think that I must just be missing something.我一直在挑选该页面的 html 以试图弄清楚,但认为我一定是遗漏了一些东西。 When I try to have multiple "sticky-top" elements, the multiple sticky-top elements stack on top of each other, all piled together at the top of the page, without "bumping" the previous sticky-top element upward.当我尝试拥有多个“置顶”元素时,多个置顶元素相互堆叠,全部堆放在页面顶部,而不会向上“撞”上一个置顶元素。

Also, each h2 has children divs, and the children divs are bumping each other off as sticky-top elements, while each h2 bumps the previous h2 off as the previous sticky-top element, if you could let me know why that is happening.此外,每个 h2 都有子 div,并且子 div 作为置顶元素相互碰撞,而每个 h2 将前一个 h2 作为前一个置顶元素碰撞,如果你能告诉我为什么会这样的话。 I would really appreciate any help anyone can give.我非常感谢任何人可以提供的任何帮助。 Thanks谢谢

Look at the outermost container around each section.查看每个部分周围的最外层容器。 It's an article element, and it constrains the position of the sidebar headings inside.它是一个article元素,它限制了侧边栏标题的位置。 Those headings are allowed to be at any position, top to bottom, within those containers.这些标题可以位于这些容器内的任何位置,从上到下。 It actually has nothing to do with the header.它实际上与标题无关。

Picture a kitchen cabinet drawer in your mind.在您的脑海中想象一个厨柜抽屉。 Open it and place a tall glass at the back corner.打开它并在后角放置一个高玻璃杯。 Now close the drawer.现在关上抽屉。 The glass can slide along the drawer's floor, constrained by the counter top, until the bottom of the drawer makes contact.玻璃可以沿着抽屉的地板滑动,受台面的限制,直到抽屉的底部接触。 At that point the glass gets forcefully pulled under the countertop.那时,玻璃被强行拉到台面下方。 That's essentially what's happening with this layout.这基本上就是这种布局所发生的事情。

As far as everything respecting the header, inspect the primary layout.至于关于标题的所有内容,请检查主要布局。 It uses CSS grid (via Bootstrap classes), and there's a 4rem top padding applied, which corresponds to the header height.它使用 CSS 网格(通过 Bootstrap 类),并且应用了 4rem 顶部填充,对应于标题高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM