【发布时间】:2021-07-10 00:37:17
【问题描述】:
我有一个 Django 循环模板,它循环数据库中的前三张卡片。但他们并没有保持在同一条线上。只有两张是,但我想要三张卡在同一行。
<div class="row">
{% for jax in u_jaxes|slice:"0:3" %}
<div class="col-5 m-2">
<div id="card2" class="card">
<div class="card-body">
<a href="{% url 'edit_jax' jax.title %}">{{ jax.title|truncatechars:21 }}</a><br><br>
<img src="https://cdn1.iconfinder.com/data/icons/logotypes/32/badge-html-5-128.png" alt="Badge, html, html5, achievement, award, reward, trophy"/ height="17" width="17"> HTML, CSS, JS
<small><span style="float:right">
{{ jax.date_created|timesince }} ago
</span></small>
<a href="{% url 'edit_jax' jax.title %}" class="stretched-link"></a>
</div>
</div>
</div>
{% endfor %}
</div>
css
<style>
body {
background-color: #f5f5f5;
}
#plus {
border: none;
background: none;
color: blue;
border: 1px solid #E6E6FA;
background: #E6E6FA;
border-radius: 5px;
text-decoration: none;
padding: 5px;
}
#plus:hover {
border: none;
background: none;
color: white;
border: 1px solid #E6E6FA;
background: #1974D2;
border-radius: 5px;
transform: 4s;
}
#card {
width: 214px;
}
#card2 {
width: 309px;
margin-left: -8px;
}
#card2 a {
text-decoration: none;
font-size: 17px;
}
#see {
text-decoration: none;
font-weight: bold;
display: block;
margin-top: 10px;
}
#img {
width: 20px;
height: 20px;
border-radius: 50%;
object-fit: cover;
margin-bottom: 2px;
}
.row {
width: 730px;
}
#sp {
margin-top: 5px;
}
</style>
请注意,卡片之间存在特定间距。我也希望间距相同,同时三张卡片在同一行。
对于 css,我认为您需要关心的只是 card2 的东西,包括悬停和所有内容。我也认为row。而已。你可以忽略其余的。但只是为了确保,您可以根据需要检查所有 css。
【问题讨论】:
标签: python html css django bootstrap-5