Bootstrapのモーダルでセンタリング@IE11

Bootstrap4からモーダルDialogのセンタリングが可能になった。
Firefoxで試してみる。

素晴らしい!
ChromeでもOK。
IE11では…

知ってた…。

こんなにシンプルにセンタリングできるのに、とても残念。
しばしググっているとBootstrapが4.1.3にVersion UPされている。
うまくいかない版は4.00だ。

試してみる。

IE11でも出来た。
改善してくれたのですね。
有り難うございます。

Dialogのセンタリングはclass属性に「modal-dialog-centered」を追加するだけ。
完成版のソースは以下です。

<!DOCTYPE html>
<html>
  <head>
    <meta charset="Shift_JIS">
    <title>bootstrap modal test</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
  </head>
  <body>
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#centerModal">
      中央に配置されるポップアップ画面を表示する。
    </button>
    <div class="modal fade" data-backdrop="static" id="centerModal" tabindex="-1" role="dialog" aria-labelledby="modal" aria-hidden="true">
      <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="mdtitle">タイトル</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </div>
          <div class="modal-body">
            中央に配置されるはず...
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">閉じる</button>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>

以下のサイトを参考にさせて頂きました。
Bootstrapでモーダルダイアログを超簡単に実装する方法

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です