マウスが#inner
を超えると、通常の方法(スペースバー、矢印キー、トラックパッド、ホイール)を使用して#outer
を上下にスクロールすることはできません。
あなたが持っているものをすべて保持する必要がある場合は、内側の要素にpointer-events: none
を追加して回避してください。 (これはあなたがそれと全くやりとりすることができないことを意味することに注意してください。内側の要素のリンクはクリック可能ではありません。あなたが質問に与えた例を考えれば、それは問題にならないでしょう)
あなたは離れてあなたの
html
のスタイルを変更することで得ることができる場合
html,
body {
height: 100%;
margin: 0;
}
html {
overflow: hidden;
}
#inner {
position: fixed;
background: red;
width: 200px;
height: 200px;
pointer-events: none; /* this is your fix. note it doesn't work in IE < 9 */
}
#outer {
overflow-y: auto; /* I changed this from "scroll". that may have been an inappropriate change, but it seems like it's probably desirable - you don't want the scrollbar to show even if the window is tall enough that you can't scroll */
background: blue;
height: 100%;
}
#push {
height: 2000px;
}
<div id="outer">
<p>top of #outer</p>
<div id="inner">
#inner
</div>
<div id="push" />
</div>
、あなたはhtml {height: 100%; overflow: hidden}
をドロップすることによってこの問題を回避することができます。この解決策ではpointer-events: none
を使用しないので、内部要素とやりとりすることができます!
html {
margin: 0; /* dropped html {height: 100%; overflow: hidden} */
}
body {
height: 100%;
margin: 0;
}
#inner {
position: fixed;
background: red;
width: 200px;
height: 200px;
}
#outer {
overflow-y: auto; /* I changed this from "scroll". that may have been an inappropriate change, but it seems like it's probably desirable - you don't want the scrollbar to show even if the window is tall enough that you can't scroll */
background: blue;
height: 100%;
}
#push {
height: 2000px;
}
<div id="outer">
<p>top of #outer</p>
<div id="inner">
#inner
</div>
<div id="push"></div>
</div>
あなたが最初の例では第二の例からCSSを使用することができない特別な理由はありますか? – shariqkhan
http://jsbin.com/dinenumaqe/edit?html,css,output、そこに – pol
'#app {overflow:scroll}'と 'html {overflow:hidden} 'を組み合わせると、ウィンドウの長さが'#push'を押すと、スクロールバーを画面から出すことができます。それは本当に目標ですか? – henry