使用 Bootstrap 的 Modal 元件時,如果頁面 Header 設為 position: fixed,會發現開啟 Modal 時捲軸與版面發生變動。
當時使用以下 CSS 修正:
body,
body.swal2-shown,
body.modal-open {
overflow: inherit;
padding-right: inherit !important;
}
2026 年後記
這段覆蓋規則會取消套件原本的捲動鎖定與捲軸寬度補償,只適合當時的版面情境。新專案若不依賴 Bootstrap Modal,也可以考慮瀏覽器原生的 dialog 元素。