固定位置和浮子无法正常工作

用户081608

我正在尝试在我的网站中创建一个部分,该部分是我网站上的滚动部分,旁边是不动的部分。这是我的代码:

<div class="wrapper">
        <div id="feed">
        </div>
        <div class="right_wrapper">
          <div class = "top_right_wrapper";>
            <div class = "top_right_title_wrapper">
              <div class="top_right_title">
              Title
              </div>
            </div>
          </div>
          <div class = "mid_right_wrapper";>
          </div>
      </div>

CSS:

div.wrapper{
width: 1110px;
margin: auto;
}

 div.right_wrapper{
height: 100%;
width: 300px;
float:right;
position:fixed;
}

div.top_right_wrapper{
height: 150px;
width: 300px;
background-color: white;
box-shadow: 0px 1px 2px #888888;
float:right;
}

div.mid_right_wrapper{
height: 300px;
width: 300px;
margin-top: 3px;
background-color: white;
box-shadow: 0px 1px 2px #888888;
float:right;
}

div.top_right_title_wrapper{
height: 40px;
width: 150px;
padding:0;
}

div.top_right_title{
font-family: "Open Sans";
font-weight: bold;
padding: 8px;
color: #2F4F4F;
}

我有一个ID feed,它从ajax调用中获取不同的div。它是无限滚动类型的供稿。我还有一个top_right_wrapper应该在其右上方的旁边。它看起来应该像这样:

------------- ****
------------- ****
------------- ****
-------------
-------------
-------------

滚动条是,--而top_right_wrapper是**当我当前的代码使用固定位置执行此操作时:

****--------- 
****--------- 
****--------- 
------------- 
------------- 
------------- 

如果我拿走固定位置,则在所有数据之后,它都将到达页面的最底部。它在正确的位置闪烁,然后消失到底部:

-------------
------------- 
------------- 
------------- ****
------------- ****
------------- ****

有人知道如何解决这个问题吗?

海因斯

问题是你的声明float: right;和一position:fixed;div.right_wrapper您要描述的布局问题完全有道理。

首先,介绍一些CSS绝对位置和固定位置的背景信息:

实际上,在一个堆叠上下文中最多可以包含七个层,并且这些层中可以包含任意数量的元素,但是请不要担心-您不太可能必须在一个堆叠上下文中处理七个层。一个堆叠上下文中的元素(所有元素,不仅是定位的元素)从后到前的呈现顺序如下:

  1. 构成堆叠上下文的元素的背景和边框
  2. 堆栈等级为负的后代
  3. 正常流程中的块级后代
  4. 浮动后代
  5. 正常流程中的内联级别后代
  6. 堆栈级别设置为auto或(零)的定位后代
  7. 堆叠后位为正的后代

高亮显示的条目是我们可以使用z-index属性更改其堆栈级别的元素。

(摘自http://www.w3.org/wiki/CSS_absolute_and_fixed_positioning

您遇到这些问题的原因是因为您要为对象分配固定位置。这使它脱离了正常的对象流。删除固定位置时,仅保留float: right声明,并将其放在主列的右侧。

而是float: right使用诸如的声明来放置项目right: 0;


为了帮助说明我在说什么,下面是一个示例。

#wrapper {
  position: relative;
  width: 90% margin: 1em auto;
  /* Background color to help illustrate areas*/
  background-color: red;
}
#content {
  position: relative;
  width: 70%;
  padding: 1em;
  background-color: white;
}
#menu {
  position: fixed;
  padding: 10px;
  top: 30px;
  left: calc(70% + 30px);
  background-color: white;
}
<div id="wrapper">
  <div id="content">
    <h1><span class="mw-headline" id="The_third_dimension.E2.80.94z-index">The third dimension—z-index</span></h1>
    <p>It’s natural to regard a web page as two-dimensional. Technology hasn’t evolved far enough that 3D displays are commonplace, so we have to be content with width and height and fake 3D effects. But CSS rendering actually happens in three dimensions!
      That doesn’t mean you can make an element hover in front of the monitor—yet—but you can do some other useful things with positioned elements.
    </p>
    <p>The two main axes in a web page are the horizontal X axis and the vertical Y axis. The origin of this co-ordinate system is in the upper left-hand corner of the viewport, ie where both the X and Y values are 0. But there is also a Z axis, which we
      can imagine as running perpendicular to the monitor’s surface (or to the paper, when printing). Higher Z values indicate a position “in front of” lower Z values. Z values can also be negative, which indicate a position “behind” some point of reference
      (I’ll explain this point of reference in a minute).
    </p>
    <p>Before we continue, I should warn you that this is one of the most complicated topics within CSS, so don’t get disheartened if you don't understand it on your first read.
    </p>
    <p>Positioned elements (including relatively positioned elements) are rendered within something known as a stacking context. Elements within a stacking context have the same point of reference along the Z axis. I’ll explain more about this below. You
      can change the Z position (also called the stack level) of a positioned element using the <code>z-index</code> property. The value can be an integer number (which may be negative) or one of the keywords <code>auto</code> or <code>inherit</code>. The
      default value is <code>auto</code>, which means the element has the same stack level as its parent.
    </p>
    <p>You should note that you can only specify an <i>index</i> position along the Z axis. You can’t make one element appear 19 pixels behind or 5 centimetres in front of another. Think of it like a deck of cards: you can stack the cards and decide that the
      ace of spades should be on top of the three of diamonds—each card has its stack level, or Z index.
    </p>
    <p>If you specify the <code>z-index</code> as a positive integer, you assign it a stack level “in front of” other elements within the same stacking context that have a lower stack level. A <code>z-index</code> of 0 (zero) means the same as <code>auto</code>,
      but there is a difference to which I will come back in a minute. A negative integer value for <code>z-index</code> assigns a stack level “behind” the parent’s stack level.
    </p>
    <p>When two elements in the same stacking context have the same stack level, the one that occurs later in the source code will appear on top of its preceding siblings.
    </p>
    <p>There can in fact be no less than seven layers in one stacking context, and any number of elements in those layers, but don't worry—you are unlikely to have to deal with seven layers in a stacking context. The order in which the elements (all elements,
      not only the positioned ones) within one stacking context are rendered, from back to front is as follows:
    </p>
    <ol>
      <li>The background and borders of the elements that form the stacking context
      </li>
      <li> <b>Positioned descendants with negative stack levels</b>
      </li>
      <li>Block-level descendants in the normal flow
      </li>
      <li>Floated descendants
      </li>
      <li>Inline-level descendants in the normal flow
      </li>
      <li> <b>Positioned descendants with the stack level set as <code>auto</code> or  (zero)</b>
      </li>
      <li> <b>Positioned descendants with positive stack levels</b>
      </li>
    </ol>
    <p>The highlighted entries are the elements whose stack level we can change using the <code>z-index</code> property.
    </p>
  </div>
  <div id="menu">
    <h3>This is a fixed menu.</h3>
    <ul>
      <li><a href="#">Link 1</a>
      </li>
      <li><a href="#">Link 2</a>
      </li>
      <li><a href="#">Link 3</a>
      </li>
      <li><a href="#">Link 4</a>
      </li>
      <li><a href="#">Link 5</a>
      </li>
    </ul>

  </div>
</div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

固定位置无法正常工作

来自分类Dev

CSS背景图片位置固定无法正常工作

来自分类Dev

位置:固定;无法正常运作

来自分类Dev

CSS - Calc 无法使用固定位置

来自分类Dev

固定位置菜单和内部链接?

来自分类Dev

在固定位置打印和更新多行

来自分类Dev

固定位置菜单和内部链接?

来自分类Dev

Xcode位置无法正常工作

来自分类Dev

Xcode位置无法正常工作

来自分类Dev

相对定位无法正常工作CSS

来自分类Dev

相对定位无法正常工作CSS

来自分类Dev

定位标记onclick无法正常工作

来自分类Dev

无法弄清楚如何使用浮点数和固定位置

来自分类Dev

我的固定导航栏无法正常工作

来自分类Dev

WooCommerce产品固定链接无法正常工作

来自分类Dev

AFNetworking SSL 固定无法正常工作

来自分类Dev

固定动作按钮无法正常工作?

来自分类Dev

元素的固定位置?

来自分类Dev

无法在移动Safari中点击固定位置元素

来自分类Dev

无法将文本置于固定位置的列中

来自分类Dev

无法将div水平居中,涉及固定位置

来自分类Dev

Android ViewPager位置无法正常工作

来自分类Dev

Foreach循环位置无法正常工作

来自分类Dev

Android ViewPager位置无法正常工作

来自分类Dev

位置管理器无法正常工作

来自分类Dev

句子中单词的位置无法正常工作

来自分类Dev

地理位置API无法正常工作

来自分类Dev

保持背景图片固定位置和居中

来自分类Dev

将相机移动到固定位置和轴