简体   繁体   English

绝对排名第二次不起作用

[英]Position Absolute doesn't work a second time

I got 3 divs, and I want them to be scrollable to one each other when clicking on an arrow in the bottom of each div. 我有3个div,当我单击每个div底部的箭头时,我希望它们彼此可滚动。 Every divs takes the full browser height thanks to height: 100vh 由于height: 100vh每个div都会占用全部浏览器height: 100vh

Each arrows are sticked to the bottom of the current div (so, sticked to the bottom of the browser page), thanks to style="position: absolute; bottom: 0; right: 0; left: 0; margin: auto;" 由于style="position: absolute; bottom: 0; right: 0; left: 0; margin: auto;"每个箭头都贴在当前div的底部(因此,贴在浏览器页面的底部) style="position: absolute; bottom: 0; right: 0; left: 0; margin: auto;"

The problem is that only the first arrow is sticked to the bottom of the first div, the second arrow on the second div isn't displayed, even though the strcutres of those divs are nearly identical. 问题在于,即使第一个div的结构几乎相同,第一个div的底部也只有第一个箭头,而第二个div上的第二个箭头却没有显示。 Therefore, the first arrow scrolls to the last div, instead of the second div. 因此,第一个箭头滚动到最后一个div,而不是第二个div。

Last but not least, my vertical align doesn't seem to be working (below each span12 ), and I'd like to set an arrow to scroll to the first div in the top of my second div 最后但并非最不重要的一点是,我的垂直对齐方式似乎不起作用(在每个span12下方),我想设置一个箭头以滚动到第二个div顶部的第一个div

Here is the FIDDLE 这是 FIDDLE

Code: 码:

<!-- FIRST DIV -->
<div id="explanation" class="row-fluid" style="height: 100vh;">
  <div class="span12" style="height:100%; display:table !important;">
    <!-- Vertical Align center -->
    <div style="display:table-cell; vertical-align:top;">
      <h1 class="visible-phone" style="text-align:center;margin: 10px 0;">
        Title - Explanation
      </h1>
      <hr style="width: 50%; margin-left: 25%;" />
      <div class='container' style="padding-top: 10%;">
        <div class="span3">
          <h2>Sub-Title:</h2>
        </div>
        <div class="span9">
          <h4>
            <p>
              This is my subtitle
            </p>
          </h4>
        </div>
      </div>
    </div>
  </div>
  <div style="position: absolute; bottom: 0; right: 0; left: 0; margin: auto;">
    <div class="circle-box-blue show_link_css">
      <a href="#form1"><h1 class="icon-chevron-down icon-large"></h1></a>
    </div>
  </div>
</div>


<!-- SECOND DIV -->
<div id="form1" class="row-fluid" style="height: 100vh;">
  <div class="span12" style="height:100%; display:table !important;">
    <!-- Vertical Align center -->
    <div style="display:table-cell; vertical-align:top;">
      <h1 class="visible-phone" style="text-align:center;margin: 10px 0;">
        Title - Form1
      </h1>
      <hr style="width: 50%; margin-left: 25%;" />
      <div class='container' style="padding-top: 10%;">
        <div class="span3">
          <h2>Sub-Title:</h2>
        </div>
        <div class="span9">
          <h4>
            <p>
              This is my subtitle, for my form1
            </p>
          </h4>
        </div>
      </div>
    </div>
  </div>
  <!-- THIS ARROW ISNT EVEN BEING DISPLAYED! -->
  <div style="position: absolute; bottom: 0; right: 0; left: 0; margin: auto;">
    <div class="circle-box-blue show_link_css">
      <a href="#button"><h1 class="icon-chevron-down icon-large"></h1></a>
    </div>
  </div>
</div>

<!-- LAST DIV -->
<div id="button" class="row-fluid" style="height: 100vh;">
  <div class="span2">Last Div</div>
</div>

Any help would be greatly appreciated, thanks. 任何帮助将不胜感激,谢谢。

position: absolute; positions the elements absolutely relative to the closest positioned ancestor . 将元素绝对相对于最接近的祖先进行定位 In your case, because your wrapper div s aren't positioned, that means the arrows are positioned in relation to the page, and so both of them are in the same place. 在您的情况下,由于未定位包装div ,这意味着箭头相对于页面定位,因此它们都位于同一位置。

Try adding position: relative to your wrapping divs. 尝试添加position: relative对于您的环绕div。

If you use position: absolute; 如果使用位置:绝对; the position is absolute and the object will be placed on the exact same location. 该位置是绝对的,并且对象将放置在完全相同的位置。 You can make the first div and the second div absolute and you will get the result you want. 您可以将第一个div和第二个div设为绝对,然后将获得所需的结果。 The arrows will be absolute to the div. 箭头对div是绝对的。

As you are adding the element on the same location After checking the DOM you will see that problem with your css check editted fiddle it will give you an idea where the problem is and what you want to achieve.You should look into <hr style="width: 50%; margin-left: 25%;" /> 当您将元素添加到同一位置时,检查DOM后,您会发现用css check编辑的小提琴出现了问题,它将使您知道问题出在哪里以及要实现的目标。您应该查看<hr style="width: 50%; margin-left: 25%;" /> <hr style="width: 50%; margin-left: 25%;" />

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

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