物化CSS valign-wrapper在模态中不起作用

时间:2018-10-10 21:25:09

标签: modal-dialog materialize

我想创建一个模态,可以用来显示不确定的加载栏。加载栏是模态中的唯一元素。我希望加载栏垂直居中,但valign-wrapper在这种情况下不起作用。如何使valign-wrapper正常工作?

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">


 </head>
 <body>

   <div
      class="modal valign-wrapper"
      id="loading-modal"
      style="width: 50% !important ; height: 50% !important ;"
   >
     <div class="progress valign">
       <div class="indeterminate" style="width: 50%"></div>
     </div>
   </div>


   <!-- Compiled and minified JavaScript -->
   <script
     src="https://code.jquery.com/jquery-3.3.1.js"
     integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
     crossorigin="anonymous">
   </script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
   <script>
       $(document).ready(function(){
         $('.modal').modal();
         $('.modal').modal('open');
       });
   </script>
 </body>
</html>

JS Bin: https://jsbin.com/yuzonipexu/edit?html,output

1 个答案:

答案 0 :(得分:1)

您可以将进度放置在wrapper标签中,并将其垂直居中:

html:

<div class="progress-wrapper">
  <div class="progress valign">
    <div class="indeterminate" style="width: 50%"></div>
  </div>
</div> 

css:

.progress-wrapper {
  position: relative;
  top: 50%;
}

.progress-wrapper .progress {
  margin: 0;
}