2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[bootstrap5] modalが画面からはみ出すサイズなのにスクロールしない場合

Posted at

原因

modalの中でformタグなど既定のdisplay属性がblockであるタグを使ったり指定したりしていませんか?

対策

1: formは.modalの外に設置する

<div class="modal" ... >
    <div class="moda-dialog modal-dialog-scrollable" ... >
        <div class="modal-content">
            <form> ←こういう場所に設置するのはあまり良くない
                <div class="modal-body"></div>
            </form>

↓↓↓↓

<form> ←ここの方が良い
    <div class="modal" ... >
        <div class="moda-dialog modal-dialog-scrollable" ... >
            <div class="modal-content">
                <div class="modal-body"> 
                :

</form>

2: modal内部のformはdisplayをcontentsに変更

今更formの場所を動かせないならこの方法で。
display:contentsはタグ自身でボックスを作らず子要素にまかせるというもの。こうするとmodal側で正常にスクロール出来るようになります。
あまりおすすめしませんが、cssで.moda-dialog内のformに呼応するようにすれば最小限の修正で対応可能。

.modal-dialog form {
	display: contents;
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?