简体   繁体   English

修复了定位重叠问题

[英]Fixed positioning overlap issue

I am in a corner with this one. 我在这个角落。 I have a layout with 2 containers. 我有2个容器的布局。 One of the containers represents a map (#main) and needs to stay in user view at all times, the other one (#sub) serves as a scroll-able content. 其中一个容器代表一张地图(#main),需要始终保持在用户视图中,另一个容器(#sub)充当可滚动的内容。 Everything looks fine if content fits horizontally. 如果内容水平放置,一切看起来都很好。 However as soon as the horizontal bar appears (resize the window to replicate), the scroll-able content overlaps the fixed content and I am out of ideas how to fix it. 但是,一旦出现水平条(调整窗口大小以进行复制),可滚动内容就会与固定内容重叠,并且我不知道如何解决它。 I know of one way to fix it by positioning the fixed content absolutely instead and useing javascript to adjust its position from the top. 我知道一种修复它的方法,方法是绝对定位固定内容,然后使用javascript从顶部调整其位置。 Is there any way to fix it? 有什么办法可以解决?

Sample code is below: 示例代码如下:

Html: HTML:

<div id="content">
    <div id="main">main</div>
    <div id="sub">
        <strong>Sub</strong><br />
        sub<br />
        sub<br />
        sub
    </div>
</div>

Css: CSS:

#content {
    width: 1200px;
    margin: 0 auto;
}
#main {
    position: fixed;
    width: 849px;
    height: 500px;
    background: red;
}
#sub {
    position: relative;
    float: right;
    width: 350px;
    height: 3500px;
    background: green;
}

JSFiddle link JSFiddle链接

Based on your comments it sounds like not allowing the user to scroll will solve the issue: 根据您的评论,听起来好像不允许用户滚动将解决此问题:

body {
  padding: 0;
  margin: 0;
  overflow-x:hidden;
 }

If you want them both to scroll you have to remove the fixed positioning: 如果要它们都滚动,则必须删除固定位置:

#main {
position: relative;
width: 849px;
height: 300px;
background: red;
font-size: 50px;
text-align: center;
padding-top: 200px;
    float:left;
}

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

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