【问题标题】:Bootstrap 4 columns not aligning as expectedBootstrap 4列未按预期对齐
【发布时间】:2018-12-23 11:44:28
【问题描述】:

我是 Bootstrap 4 的新手,但我已经阅读了 this 文档,它看起来很简单,但是我无法让这些列正常工作。我基本上只是想让所有的广告都显示在页面的左侧,col-8 占据了大部分,而在右侧我只是想设置一个带有创建帖子按钮的小框.它只会占用页面的col-4。

这是我的 HTML(注意:我使用的是 Django):

{% extends 'base.html' %}

This is the create a post page

{% block head %}
<!-- {% load static %}
<link rel="stylesheet" href="{% static 'accounts/login.css' %}" type="text/css"> -->
<title>Zaneroo - Latest Ads</title>
{% endblock %}

{% block body %}

<div class="container"><br>

<a href="{% url 'classifieds:create_post' %}">Post an Ad</a><br><br>

<section id="latest-ads">

  <div class="ads">
    <div class="row">
      <div class="col-8">
        Ads
      </div>
    </div>
  </div>

  <aside class="create-post">
    <div class="row">
      <div class="col-4">
        Sidebar
      </div>
    </div>
  </aside>

</section>



  {% if messages %}
  {% for message in messages %}
  <br>{{ message }}<br>
  {% endfor %}
  {% endif %}

  {% for post in posts %}

  {% endfor %}
</div>
{% endblock %}

我知道引导程序正在被选中,因为导航栏仍然有效,字体不是默认的,链接也不是,但由于某种原因,列不是并排的。只是直接在彼此之上。

在我继承导航的 base.html 文件中,我在引导程序上使用此版本:

href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"

Here是浏览器中HTML页面的图片。

非常感谢任何帮助。

【问题讨论】:

  • 您的列嵌套在 div 中。可能是问题所在。
  • 我删除了外部 div,不幸的是这并没有解决它。不过还是谢谢。
  • 让我发布一个答案给你试试

标签: html twitter-bootstrap alignment


【解决方案1】:

您需要将它包装在一个容器(或容器流体)中,然后是一行,然后是您的 col。例如

<section class="container" id="latest-ads">
  <div class="row">
    <div class="col-8 ads">
       Ads
    </div>
    <aside class="col-4 create-post">
     Sidebar
    </aside>
  </div>
</section>

【讨论】:

  • 修复了它,您的代码也让我意识到最初的错误是我有两行,这就是元素显示在彼此之上的原因。谢谢你。被选为最佳。
猜你喜欢
  • 2018-02-15
  • 2022-01-21
  • 2018-01-21
  • 1970-01-01
  • 2020-06-22
  • 1970-01-01
  • 2020-03-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多