2016-12-28 74 views
0

我有一个非常简单的问题,但我无法解决它。不需要的水平滚动

另一个div内有一个div。内部div完全脱离外部div(左侧:100%)。而且,外部div应该垂直滚动。但是,我无法找到如何不水平滚动,以及如何使内部div在外部div之外同时可见。

的代码如下:

HTML:

<div id="out"> 
    <div id="in"> 
    </div> 
</div> 

CSS:

#out{ 
    height:100px; 
    width:100px; 
    background-color: green; 
    position: relative; 
    overflow-y: scroll; 
    overflow-x: visible; 
} 

#in{ 
    position: absolute; 
    left: 100%; 
    height:50px; 
    width:50px; 
    background-color: red; 
} 

提前感谢!

回答

1

.main_outer{ 
 
    overflow-y:scroll; 
 
    border:thin black solid; 
 
overflow-x:hidden; 
 
} 
 

 
#out{ 
 
    height:100px; 
 
    width:100px; 
 
    background-color: green; 
 
    position: relative; 
 
} 
 

 
#in{ 
 
    position: absolute; 
 
    left:100%; 
 
    width:70px; 
 
    height:auto; 
 
    background-color: red; 
 
    right:0; 
 
}
<div class="main_outer"> 
 
<div id="out"> 
 
<div id="in"> 
 
    Your Inner Contents 
 
    Your Inner Contents 
 
    Your Inner Contents 
 
    
 
    </div> 
 
    </div> 
 
</div>

这里是JSFiddle

PS:改变你的红格大小以适合你的内容。

希望这会有所帮助。

+0

谢谢你的回答!但是,红色的div应该在绿色div的右侧。换句话说,红色的div应该显示在绿色div之外。 – themis93

+0

在你的问题中,你提到在另一个div内有一个div。这就是为什么我已经把这个解决方案。你能更具体地知道你所期望的输出吗? –

+0

我说那是因为html中的层次结构。很抱歉对于这个误会。输出应该是这样的:https://postimg.org/image/n2fl7ceen/ – themis93

1

固定的滚动与移除overflow-x:hidden;

================最新变化================= =====

如果这是需要的,但在标记中稍作调整,请参阅最新更改。

#outer-div { 
 
    overflow-y: scroll; 
 
    width: 165px;  
 
} 
 
#out{ 
 
    height:100px; 
 
    width:100px; 
 
    background-color: green; 
 
    position: relative; 
 
} 
 

 
#in{ 
 
    position: absolute; 
 
    left: 100%; 
 
    height:50px; 
 
    width:50px; 
 
    background-color: red; 
 
}
<div id="outer-div"> 
 
    <div id="out"> 
 
    <div id="in"> 
 
    </div> 
 
    </div> 
 
</div>

+0

正如你在描述中看到的那样,外部的div必须进行垂直滚动。 – themis93

+0

现在修复了水平滚动条。 – aavrug

+0

我看到了,但红色的div不可见 – themis93