如何在侧边栏旁边放置内容?

How to position content beside sidebar?

我不太精通HTML和CSS。我目前正在使用 Django 构建一个 Web 应用程序,我使用 Bootstrap 将侧边栏集成到我的 Web 应用程序中,但它弄乱了我的布局,我似乎无法弄清楚如何将块中的内容移动到我侧边栏的左侧。

如上图所示,我的侧边栏位于顶部,我的内容位于底部。下面是我的侧边栏和基本模板的代码。

sidebar_template.html

<div class="d-flex flex-column vh-100 flex-shrink-0 p-3 text-white bg-dark sidebar-height" style="width: 250px;"> <a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-white text-decoration-none"> <svg class="bi me-2" width="40" height="32"> </svg> <span class="fs-4">CPRS Admin</span> </a>
    <hr>
    <ul class="nav nav-pills flex-column mb-auto">
        <li class="nav-item"> <a href="#" class="nav-link active" aria-current="page"> <i class="fa fa-home"></i><span class="ms-2">Home</span> </a> </li>
        <li> <a href="{% url 'coordinator_dashboard' %}" class="nav-link text-white"> <i class="fa fa-dashboard"></i><span class="ms-2">Dashboard</span> </a> </li>
        <li> <a href="{% url 'coordinator_view_students' %}" class="nav-link text-white"> <i class="fa fa-first-order"></i><span class="ms-2">Students</span> </a> </li>
        <li> <a href="#" class="nav-link text-white"> <i class="fa fa-cog"></i><span class="ms-2">Settings</span> </a> </li>
        <li> <a href="#" class="nav-link text-white"> <i class="fa fa-bookmark"></i><span class="ms-2">Bookmarks</span> </a> </li>
    </ul>
    <hr>
    <div class="dropdown"> <a href="#" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false"> <img src="https://github.com/mdo.png" alt="" width="32" height="32" class="rounded-circle me-2"> <strong> John W </strong> </a>
        <ul class="dropdown-menu dropdown-menu-dark text-small shadow" aria-labelledby="dropdownUser1">
            <li><a class="dropdown-item" href="#">New project</a></li>
            <li><a class="dropdown-item" href="#">Settings</a></li>
            <li><a class="dropdown-item" href="#">Profile</a></li>
            <li>
                <hr class="dropdown-divider">
            </li>
            <li><a class="dropdown-item" href="#">Sign out</a></li>
        </ul>
    </div>
</div>

base.html

{% load static %}

<!DOCTYPE html>
<html>
<head>
    <title>Capstone Project</title>
    <link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">  
    <script src="{% static 'js/bootstrap.min.js' %}"></script>  
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>  

    <link href="{% static 'css/main.css' %}" rel="stylesheet">  
    <link href="{% static 'css/profile.css' %}" rel="stylesheet">  
    <link href="{% static 'css/sidebar.css' %}" rel="stylesheet">  
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">  

</head>

<body>

    <div class="page-container">
        <div class="content-wrap">
            <div class="">
                {% if user.is_authenticated and user.is_superuser %}
                        {% include 'HOD/sidebar_template.html' %}
                {% endif %}
            </div> 
            <div class="col">
                {% block content %}
                {% endblock content %}
            </div> 
        </div>
    </div>
    <!-- Optional Javascript -->  
    {% block custom_js %}
    {% endblock custom_js %}

</body>
 <!-- Site footer -->
    <footer class="footer">
        <div class="container text-center">
            <small>Copyright &copy; Your Website</small>
        </div> 
    </footer>
</html>

有人可以帮我修改布局吗?谢谢

这是一个 bootstrap 问题,而不是 django 问题。 您必须了解 bootstrap grid 的工作原理。

您必须先创建一个可以包含一列或多列的行元素。当您创建列时,您可以根据屏幕尺寸决定它们的行为,或者让它们自己确定尺寸。

这将创建两个大小相同的列,它们将占据可用的任何宽度 space。

<div class="row">
    <div class="col">
        content
    </div>
    <div class="col">
        content
    </div>
</div>

如果您想定义每列相对于页面总宽度的宽度,您可以在创建列时进行定义。您可以在此处为不同的屏幕尺寸指定不同的行为,以使您的网站响应迅速。

 <div class="row">
        <div class="col-3 col-lg-2">
           This column will be 3/12 of the screen on small and medium screens. Or 2/12 of the screen on large screens and up.
        </div>
        <div class="col-9 col-lg-10">
            This column will be 9/12 of the screen on small and medium screens. Or 10/12 of the screen on large screens and up.
        </div>
    </div>

在你的具体情况下,我会建议这样的事情:

<div class="page-container">
    <div class="content-wrap">
        <div class="row">
            <div class="col-3">
                {% if user.is_authenticated and user.is_superuser %}
                        {% include 'HOD/sidebar_template.html' %}
                {% endif %}
            </div> 
            <div class="col-9">
                {% block content %}
                {% endblock content %}
            </div> 
        </div>
    </div>
</div>