2017-03-01 11 views
0

当我添加位置:绝对值为.divwidth时,溢出-y滚动条无法工作。当我向innerdiv添加绝对位置时滚动条不工作

JsFiddle

.overflow { 
    width:80%; 
    margin-left:10%; 
    height: 300px; 
    overflow-y: auto; 
    background: #333; 
    color: #fff; 
} 
.divwidth { 
    width:100px; 
    height: 30px; 
    background: #666; 
    position: absolute; 
    margin-left: -25px; 
} 
+1

加“的位置是:相对的;”到外部div – Toxide82

+0

@ Toxide82:https://jsfiddle.net/zd9mxa5r/3/ – Karuppiah

+1

这是因为'段落'之一是'divwidth'下的。但是如果你不断添加更多的内容,那么垂直滚动条会再次出现。 – Hewlett

回答

0

试试这个:你可以从.overflow类文件添加position: absolute;

.overflow { 
    width:80%; 
    margin-left:10%; 
    height: 300px; 
    overflow-y: auto; 
    background: #333; 
    color: #fff; 
    position: absolute; 
} 
.divwidth { 
    width:100px; 
    height: 30px; 
    background: #666; 
    position: relative; 

} 

DEMO HERE

OR

.overflow { 
    width:80%; 
    margin-left:10%; 
    height: 300px; 
    overflow-y: auto; 
    background: #333; 
    color: #fff; 
    position: relative; 
} 
.divwidth { 
    width:100px; 
    height: 30px; 
    background: #666; 
    position: absolute; 
    margin-left: -25px; 
} 

DEMO

+0

但内部.divwidth应该是infront的.overflow div – Karuppiah

0

所以如果你把它添加到溢出一个

.overflow { 
position: relative; 
width:80%; 
margin-left:10%; 
height: 300px; 
overflow-y: auto; 
background: #333; 
color: #fff; 
} 

这样内部的div绝对尺寸将被限制在这个div

+0

在这里检查https://jsfiddle.net/zd9mxa5r/3/。滚动条不起作用innerdiv .divwidth应该是.overflow div的盈方 – Karuppiah