pythonDjango项目将div类的页脚移到body中

2024-09-28 20:50:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用python和django创建一个博客。在我尝试创建页脚之前,大部分都很好。页脚在主页上的显示很好,但是当您单击博客文章时,页脚会受到content容器和row div类的约束。 当您在firefoxdevinspector和DOM中看到这一点时,您会发现我的footer div位于内容容器和行中,而不是正文中。大多数事情我通常都能找到答案,但这让我发疯。我想我不是遗漏了什么,就是问的问题不对。你知道吗

  1. 我不明白为什么仅仅是footer div被放在content container/row div中,而其他任何东西都不会以同样的方式受到影响。你知道吗
  2. 在不使用jquery/jscript和更改parentElement节点的情况下,是否还有其他方法可以修改这一点?你知道吗
  3. 如果我必须用jscript修改它,我到底要在哪里修改它,用什么修改它?你知道吗

谢谢

.footer { height: 50px; background-color: #000000; color: #ffffff; padding: 10px; text-align: center; clear: both; }
  <div class="content container">
    <div class="row">
        <div class="col-md-8">
        {% block content %}
        {% endblock %}
        </div>
    </div>
</div>

  <footer>
    <div class="footer">
        Copyright &copy 2017
    </div>
  </footer>

firefox dev inspector image - sat in row div

firefox dev inspector image - moved to body


Tags: djangodevimagedivinspectorcontainercontentfirefox
2条回答

这是博客文章的详细页面

{% extends 'blog/base.html' %} {% block content %} {% if post.published_date %} {{ post.published_date }} by Matt Cheetham {% else %} <a class="btn btn-default" href="{% url 'blog.views.post_publish' pk=post.pk %}">Publish</a> {% endif %} {% if user.is_authenticated %} <a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}"><span class="glyphicon glyphicon-pencil"></span></a> <a class="btn btn-default" href="{% url 'post_remove' pk=post.pk %}"><span class="glyphicon glyphicon-remove"></span></a> {% endif %} <div class="postview"> {{ post.title }} </div> <p>{{ post.text|safe }}</p> <div class="comment"> <div class="date"> <h3>Comments</h3> <br> <a class="btn btn-default" href="{% url 'add_comment_to_post' pk=post.pk %}">Add comment</a> <br> <br> {% for comment in post.comments.all %} {% if user.is_authenticated or comment.approved_comment %} {{ comment.created_date }} {% if not comment.approved_comment %} <a class="btn btn-default" href="{% url 'comment_remove' pk=comment.pk %}"><span class="glyphicon glyphicon-remove"></span></a> <a class="btn btn-default" href="{% url 'comment_approve' pk=comment.pk %}"><span class="glyphicon glyphicon-ok"></span></a> {% endif %} </div> <strong>{{ comment.author }}</strong> <p>{{ comment.text|safe }}</p> </div> {% endif %} {% empty %} <p>No comments here yet...</p> {% endfor %} {% endblock %}

如果存在没有结束标记的开始标记,则可能发生这种情况。例如,如果你的博客是这样的

{% block content %}

  <div id="open_tag_1">
      <div id="open_tag_2">

{% endblock %}

您希望关闭<div class="content container"><div class="row">的标记实际上将用于关闭<div id="open_tag_1"><div id="open_tag_2">。你知道吗

<footer>将在<div class="row">内。你知道吗

相关问题 更多 >