如何在bootstrap中使背景更暗

时间:2017-10-12 20:22:30

标签: css html5 popup

如何使用引导程序使背景更暗?我找到了这段代码,但不知道我在哪里可以调整背景或者我必须在我的风格中加入哪种css代码。

在这里找到代码: https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_modal&stacked=h

 <!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Modal Example</h2>
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>Some text in the modal.</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

</div>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

控制背景颜色的CSS在modals.less文件中,并由下面的代码控制

.modal-backdrop {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1040;
    background-color: #333;
}

要使背景更暗,只需覆盖自己样式表中的类.modal-backdrop并添加不同的背景颜色。

在同一个较少的文件中有一个名为.modal-backdrop .in的类。此类控制背景的不透明度。

.modal-backdrop.in {
    filter: alpha(opacity=50);
    opacity: .5;
}

如果不透明度不是你以后的,那么你可以覆盖它。