2016-11-23 4 views
3

overflow-y: auto;のおかげで、divにスクロールバーが表示されるときに問題が発生しました。スクロールバーがdivを上書きする

右のdiv #bbは(それが起こる見て、その中に多くの行を追加します)スクロールバーを持っている場合は、スクロールバーが#help div要素の上にあります。 これを行う方法#help divはスクロールバーによって上書きされないように左に移動しますか?

html, 
 
body { 
 
    overflow: hidden; 
 
    height: 100%; 
 
} 
 
* { 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
#aa { 
 
    position: fixed; 
 
    top: 0; 
 
    left: 0; 
 
    width: 50%; 
 
    height: 100%; 
 
    overflow-x: hidden; 
 
    overflow-y: auto; 
 
} 
 
#bb { 
 
    position: fixed; 
 
    top: 0; 
 
    left: 50%; 
 
    width: 50%; 
 
    height: 100%; 
 
    background-color: blue; 
 
    overflow-x: hidden; 
 
    overflow-y: auto; 
 
} 
 
#help { 
 
    position: fixed; 
 
    top: 0; 
 
    right: 0; 
 
    background-color: green; 
 
}
<div id="aa" contenteditable>a 
 
    <br>few 
 
    <br>lines 
 
</div> 
 
<div id="bb" contenteditable>please add more 
 
    <br>lines here to make 
 
    <br>the scrollbar appear!</div> 
 
<div id="help">?</div>

答えて

3

にBB divの幅を設定することで、Iフレックスボックスを使って両者を隣り合わせにしました。私は両者の相対的な位置関係を作りました。そして私は?#bbの中に置き、絶対位置に設定しました。

html, 
 
body { 
 
    overflow: hidden; 
 
    height: 100%; 
 
} 
 
* { 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
.flex-container { 
 
    display: flex; 
 
    width: 100vw; 
 
    height: 100vh 
 
} 
 
#aa { 
 
    position: relative; 
 
    flex: 1; 
 
    height: 100%; 
 
    overflow-x: hidden; 
 
    overflow-y: auto; 
 
} 
 
#bb { 
 
    position: relative; 
 
    flex: 1; 
 
    height: 100%; 
 
    background-color: blue; 
 
    overflow-x: hidden; 
 
    overflow-y: scroll;/* Just so the bar is there */ 
 
} 
 
#help { 
 
    position: absolute; 
 
    top: 0; 
 
    right: 0; 
 
    background-color: green; 
 
}
<div class="flex-container"> 
 
    <div id="aa" contenteditable>a 
 
    <br>few 
 
    <br>lines 
 
    </div> 
 
    <div id="bb" contenteditable> 
 
    I've made it always 
 
    <br>so the scrollbar is 
 
    <br>there but you can 
 
    <br>change it back to auto 
 
    <div id="help">?</div> 
 
    </div> 
 
</div>

希望はこれが便利です。私はそれをいくつかの考えを与えてくれた

EDIT

。私はこれがこれを行う良い方法かもしれないと思う。

html, 
 
body { 
 
    min-height: 100vh; 
 
} 
 
* { 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
#aa { 
 
    position: fixed; 
 
    top: 0; 
 
    left: 0; 
 
    width: 50%; 
 
    height: 100vh; 
 
} 
 
#bb { 
 
    margin-left: 50%; 
 
    min-height: 100vh; 
 
    background-color: blue; 
 
} 
 
#help { 
 
    position: fixed; 
 
    top: 0; 
 
    right: 0; 
 
    background-color: green; 
 
}
<div id="aa" contenteditable>a 
 
    <br>few 
 
    <br>lines 
 
</div> 
 
<div id="bb" contenteditable>please add more 
 
    <br>lines here to make 
 
    <br>lines here to make 
 
    <br>lines here to make 
 
    <br>lines here to make 
 
    <br>lines here to make 
 
    <br>lines here to make 
 
    <br>lines here to make 
 
    <br>lines here to make 
 
    <br>lines here to make 
 
    <br>lines here to make 
 
    <br>lines here to make 
 
    <br>lines here to make 
 
    <br>lines here to make 
 
    <br>lines here to make 
 
    <br>lines here to make 
 
    <br>the scrollbar appear! 
 
</div> 
 
<div id="help">?</div>

これは、右側の列(左列が所定の位置に固定されている)をスクロールするために身体のスクロールを使用します。つまり、right:0;はスクロールバーを考慮に入れます。

+0

スクロールバー*を常に持っていて、必要がない場合は無効にしておいて、適切な場所に '?'を置くことができます。しかし、残念ながら、私はスクロールバーが必要でないときに存在することを望んでいません... – Basj

+0

@Basjは私が書いたものを読んだか? "私はいつもスクロールバーがありますが、あなたはそれをオートに戻すことができます"バーはちょうどそれが働いていることを示しています、それを自動で持っていて、それはまだ動作します:-) –

+0

はい@AndrewBoneそうして ?#bb(少なくともFF47 Windows 7の場合)に新しい行を追加すると完全に消えます – Basj

0

簡単な方法は、私は物事のカップルを変更した48%

html, 
 
body { 
 
    overflow: hidden; 
 
    height: 100%; 
 
} 
 
* { 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
#aa { 
 
    position: fixed; 
 
    top: 0; 
 
    left: 0; 
 
    width: 50%; 
 
    height: 100%; 
 
    overflow-x: hidden; 
 
    overflow-y: auto; 
 
} 
 
#bb2 { 
 
    position: fixed; 
 
    top: 0; 
 
    left: 50%; 
 
    width: 50%; 
 
    height: 100%; 
 
    background-color: blue; 
 
} 
 
#bb { 
 
    position: fixed; 
 
    top: 0; 
 
    left: 50%; 
 
    width: 48%; 
 
    height: 100%; 
 
    background-color: blue; 
 
    overflow-x: hidden; 
 
    overflow-y: auto; 
 
} 
 
#help { 
 
    position: fixed; 
 
    top: 0; 
 
    right: 0; 
 
    background-color: green; 
 
}
<div id="aa" contenteditable>a 
 
    <br>few 
 
    <br>lines 
 
</div> 
 
<div id="bb2"></div> 
 
<div id="bb" contenteditable>please add more 
 
    <br>lines here to make 
 
    <br>the scrollbar appear!</div> 
 
<div id="help">?</div>

+0

ありがとうございますが、画面の右端にスクロールバーが触れるという通常のユーザーエクスペリエンスが少し壊れてしまいます。 – Basj

+0

この記事ではjavascriptの機能が見つかりました - > http://stackoverflow.com/questions/9333379/javascript-css-check-if-overflow これをチェックしてください。 – linearSpin

+0

または私は約トリック、「bb」の下に2番目の空のdivを設定しますが、幅が50%で青い背景もあれば、仕事にすべきです。 – linearSpin

関連する問題