r/csshelp • u/The_reCAPTCHA • Mar 10 '20
Resolved Really struggling with something basic. Centering a row.
Trying to get the row of cards (bootstrap) to be centered as compared to being held on the left like it is currently. Here is what is looks like now: https://imgur.com/a/Ez6ihM1 and heres html/bootstrap:
<div class="row m-3">
{% for each_project in all_projects %}
<div class="card m-3" style="width: 18rem; height: 18rem;">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">{{each_project.proj_title}}</h5>
<p class="card-text">{{each_project.proj_disc}}</p>
<a href="/{{each_project.id}}/" class="btn btn-primary">View Project</a>
</div>
</div>
{% endfor %}
</div>I also have some External CSS here and there but not enough to matter. Thank you!
10
Upvotes
2
u/permagrinfalcon Mar 10 '20 edited Mar 10 '20
Go with Zmodem's answer. (I'm not versed in bootstrap 4, we only use 3 sparingly)
As long as the cards are side by side using inline-block and not float, text-align: center should do the trick.
.row.m-3 {
text-align: center;
}
.card.m-3 {
display: inline-block;
text-align: left;
}
2
u/Zmodem Moderator Mar 10 '20
Wrap your
<div class="card...></div>elements all in a single<div class="card-deck mx-auto"></div>container. Using your above code:The
card-deckis a great way to let BS know how you plan on spacing the cards within the container. Themx-autois a BS class for spacing. Here are all of the Bootstrap spacing classes.