Py学习  »  Django

Bootstrap 4模式出现在后台(django应用程序)

George B • 4 年前 • 261 次点击  

我已经彻底地研究过这个问题,但是所有的解决方案都来自于旧版本的bootstrap,它们没有帮助。

我的问题是当我按下按钮时,模式会出现在背景后面。我找到的所有解决方案都说父容器/模态不能有固定或相对的位置。但是,我的模态没有父容器,也没有为模态编写任何自定义css。

我认为问题可能在于我对这个html文件使用django。这是密码-

示例.html

{% extends 'main/base.html' %}
{% load static %}

{% block title %}Example Title{% endblock %}

{% block fullscreen_content %}
  <div id="map-canvas" style="height: calc(100% - 50px); width: 100%;"></div>
  
	<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
  Launch demo modal
  </button>

  <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          ...
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          <button type="button" class="btn btn-primary">Save changes</button>
        </div>
      </div>
    </div>
  </div>
{% endblock %}

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script> 

基.html

{% load static %}
<!doctype html>
<html>
  <head>
    <title>{% block title %}{% endblock %}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="shortcut icon" href="{% static 'images/favicon.ico' %}">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
    <!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootswatch/4.0.0-beta.2/flatly/bootstrap.min.css"> -->
    <link href="//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">
    <link href="{% static 'style.css' %}" rel="stylesheet" type="text/css">
    <script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript"></script>
    {% block header %}{% endblock %}
  </head>
  <body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
      <a class="navbar-brand" href="{% url 'shelter:index' %}">Example</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>

      <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
          {% with 'example example example' as tabs %}
          {% for tab in tabs.split %}
            <li class="nav-item {% if page == tab %}active{% endif %}">
              <a href="{% url 'shelter:'|add:tab %}" class="nav-link">{{ tab|title }}</a>
            </li>
          {% endfor %}
          {% endwith %}
        </ul>
        {% if request.user.is_authenticated %}
        <ul class="navbar-nav">
          <li class="nav-item">
            <a href="{% url 'shelter:logout' %}" class="nav-link">Log out</a>
          </li>
        </ul>
        {% endif %}
      </div>
    </nav>
    {% block fullscreen_content %}{% endblock %}

    <div class="container">
      <div class="page">{% block content %}{% endblock %}</div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
    {% block footer %}{% endblock %}
  </body>
</html>

我删除/编辑了代码中的敏感部分或不需要的部分,因此希望有足够的内容可以继续。谢谢!

编辑-这是一张截图 enter image description here

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/46544
 
261 次点击  
文章 [ 2 ]  |  最新文章 4 年前
oweskeez
Reply   •   1 楼
oweskeez    5 年前

如果您愿意在sass中引导,以下变量将起作用:

$zindex-modal:              100001;
$zindex-modal-backdrop:     100000;

我这样做是为了让我的模式/背景出现在我的粘性导航条上方。

Cesar Correchel
Reply   •   2 楼
Cesar Correchel    5 年前

在主css文件中,尝试将背景的z-index设置为1,下面的css可能会有帮助:

.modal-backdrop{
  z-index: 1;
}