jquery - 为每个评论创建单独的边框 Django Css
问题描述
我很难找到一种方法来为类似于下面的每个评论创建一个单独的边框框。
但是,当我添加新评论时,边框会翻倍,如下所示
我目前正在使用 Django/python 这是我的 html 文件
<div class="comments--section ">
{% for comment in comments %}
<div class="comments--border">
<p class="comments--user">{{comment.user }}</p>
<p class="comments--date">{{comment.date_added|date:'M d, Y' }}</p>
<p class="comments--entry">{{ comment }}</p>
{% if request.user.is_superuser %}
<p>
<a href="{% url 'blogging_logs:delete_comment' comment.id %}">Delete comment</a>
</p>
{% else %}
{% if comment.user == request.user %}
<p>
<a href="{% url 'blogging_logs:delete_comment' comment.id %}" class="comments--delete">Delete comment</a>
</p>
</div>
{% else %}
{% endif %}
{% endif %}
{% empty %}
<p>no comments entered yet.</p>
{% endfor %}
</div>
css 文件:
&--section {
width: 600px;
margin-left: auto;
margin-right: auto;
margin-top: 2rem;
margin-bottom: 2
}
&--border {
border-style: solid;
border-width: 1px;
margin-bottom: 2rem;
}
&--user {
font-size: 1.125rem;
font-weight: 500;
margin-bottom: 0;
}
&--date {
font-size: .7rem;
font-weight: 300;
}
&--entry {
font-weight: 300;
font-size: 1rem;
}
我知道我的边界加倍的原因,但我不知道如何绕过它。如果我将 div 类移到循环之外,它会为每个评论创建一个大框,而不是单独的框。有什么建议么?
谢谢!
解决方案
<div class="comments--section ">
{% for comment in comments %}
<div class="comments--border">
<p class="comments--user">{{comment.user }}</p>
<p class="comments--date">{{comment.date_added|date:'M d, Y' }}</p>
<p class="comments--entry">{{ comment }}</p>
{% if request.user.is_superuser %}
<p>
<a href="{% url 'blogging_logs:delete_comment' comment.id %}">Delete comment</a>
</p>
{% elif comment.user == request.user %}
<p>
<a href="{% url 'blogging_logs:delete_comment' comment.id %}" class="comments--delete">Delete comment</a>
</p>
{% else %}
<p> ** You can add any message if you wish**
</p>
{% endif %}
</div>
{% empty %}
<div class='comments--border'>
<p>no comments entered yet.</p>
</div>
{% endfor %}
</div>
在这里,我更改了一些您的 HTML。django 中还有一个 elif 标签。因此,您可以使用它而不是在嵌套中编写 if。
推荐阅读
- swift - Firebase Analytics - 记录 screen_view 在 SwiftUI 中不起作用
- sql - SQL Server 中带有 JOIN 的 UPDATE 语句未按预期工作
- r - 如何计算 r 中每组的平均变化?
- laravel - 如何验证来自 Laravel 中父控制器的相关对象请求数据?
- xml - 如何处理 XPath 和 XSL 中的层次关系和比较?
- weblogic12c - Weblogic 缓慢的服务器启动和发布
- scala - 如何在 Scala 中使用模式匹配与函数值
- html - 如何检索与在Django中单击的链接对应的数据
- reactjs - 如何在 react js 中检查材质 ui 主题的类型?(亮或暗)
- android - 如何使用 Glide/Picasso 等库从 Web 加载 Vector Drawable 资源?