0

我希望我的主要内容和 Sidewidget 在同一行。凭借我对引导网格的了解,我尝试完成这项工作,但侧边小部件堆叠在内容下方而不是侧面。这是所需的片段。

正文.html

<!-- Navigation -->
{% include 'nav.html' %}
<!-- Page Content -->
<div class="container">
  <div class="row">
    <div class="col-lg-8 ">
      {% block content %}
      {% endblock %}
    </div>
    <div class="col-lg-4">
       {% block sidewidget %}
       {% endblock %}
    </div>
  </div>
</div>

<!-- Bootstrap core JavaScript -->
<script src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/bootstrap.bundle.min.js' %}"></script>
<script src="{% static 'js/tinymce/tinymce.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/tinymce/custom.js' %}" ></script>

导航.html

<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
  <div class="container">
    <a class="navbar-brand" href="#">Start Bootstrap</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <ul class="navbar-nav ml-auto">
        <li class="nav-item active">
          <a class="nav-link" href="#">Home
            <span class="sr-only">(current)</span>
          </a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">About</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Services</a>
        </li>
        {% if user.is_authenticated %}
          <li class="nav-item">
            <a class="nav-link" href="{% url 'add' %}">Add Article</a>
          </li>  
        {% endif %}
      </ul>
    </div>
  </div>

我的 {% 块内容 %}

{% for post in posts %}
      <h2 class="mt-4">{{post.title}}</h2>
      <!-- Author -->
      <p class="lead">
        by
        <a href="/author/{{post.author}}">{{post.author}}</a>
      </p>
      <hr>
      <!-- Date/Time -->
      <p class="lead">Published on <b>{{post.published_date}}</b></p>
      <hr>
      <!-- Preview Image -->
      <img class="img-fluid" src="{{post.image.url}}" alt="Img Placeholder">
      <p>{{post.images}}</p>

      {% for tag in post.tags.all %}
      <p>{{tag.name}}</p>
      {% endfor %}
      <hr>
      <!-- Post Content -->
      <p class="lead">{{post.content|safe|truncatewords:"60"|linebreaks}}</p>
      <footer class="entry-footer">
        <a href="{{post.slug}}" class="btn-readmore"><button class="btn btn-primary">Read More</button></a>
      </footer>
      <hr>
{% empty %}
       <h1> Nothing to display</h1>
{% endfor %}  
{% endblock %}

我的 {% Sidewidget %} 块

  <!-- Search Widget -->
  <div class="card my-4">
    <h5 class="card-header">Search</h5>
    <div class="card-body">
      <div class="input-group">
        <input type="text" class="form-control" placeholder="Search for...">
        <span class="input-group-btn">
          <button class="btn btn-secondary" type="button">Go!</button>
        </span>
      </div>
    </div>
  </div>

  <!-- Categories Widget -->
  <div class="card my-4">
    <h5 class="card-header">Categories</h5>
    <div class="card-body">
      <div class="row">
        <div class="col-lg-6">
          <ul class="list-unstyled mb-0">
            <li>
              <a href="#">Web Design</a>
            </li>
            <li>
              <a href="#">HTML</a>
            </li>
            <li>  
              <a href="#">Freebies</a>
            </li>
          </ul>
        </div>
        <div class="col-lg-6">
          <ul class="list-unstyled mb-0">
            <li>
              <a href="#">JavaScript</a>
            </li>
            <li>
              <a href="#">CSS</a>
            </li>
            <li>
              <a href="#">Tutorials</a>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>

  <!-- Side Widget -->
  <div class="card my-4">
    <h5 class="card-header">Side Widget</h5>
    <div class="card-body">
      You can put anything you want inside of these side widgets. They are easy to use, and feature the new Bootstrap 4 card containers!
    </div>
  </div>
{% endblock %}

我尝试过调整,但似乎没有任何效果

我想要这样的页面:

|*****************************|  
|navigationbar                | 
|*****************************|
|Post1(Col1-Col8)  |SIDEWIDGET| 
|*****             |          |
|Post2(Col1-Col8)  |          |
|*****             |          |
|PostN(Col1-Col8)  |          |
|*****************************|
|Footer                       |
4

3 回答 3

0

在“导航”部分中,“导航”标签未关闭</nav>。关闭它并重试。
我认为这将解决您的问题。

<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
  <div class="container">
    <a class="navbar-brand" href="#">Start Bootstrap</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <ul class="navbar-nav ml-auto">
        <li class="nav-item active">
          <a class="nav-link" href="#">Home
            <span class="sr-only">(current)</span>
          </a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">About</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Services</a>
        </li>
        {% if user.is_authenticated %}
          <li class="nav-item">
            <a class="nav-link" href="{% url 'add' %}">Add Article</a>
          </li>  
        {% endif %}
      </ul>
    </div>
  </div>
</nav>
于 2018-05-28T06:51:09.490 回答
0

你不能使用 bootstarp 网格系统,因为 sidewidget 将占据整个三行的列。你必须使用弹性框。通过使用网格系统,列可以单独用于不同的行,但您不能让整个列跨越不同的行。

于 2018-05-26T09:11:19.217 回答
0

您的代码应该可以工作。根据引导程序的文档,该col-lg-*修饰符仅适用于宽度超过 1200 像素的屏幕。也许您使用的是较小的屏幕,并且您还需要添加col-smandcol-md修饰符。请尝试这些,让我知道它是否有效。

<div class="container">
  <div class="row">
    <div class="col-sm-8 col-lg-8 ">
      {% block content %}
      {% endblock %}
    </div>
    <div class="col-sm-4 col-lg-4">
       {% block sidewidget %}
       {% endblock %}
    </div>
  </div>
</div>
于 2018-05-26T08:54:40.550 回答