Need dynamic rows inside bootstrap 4 - html

I am having a hard time understanding how to set up my bootstrap rows /columns to align like the picture shown. I have tried columns nested in rows and vise versa with no luck.
The yellow and green parts in the photo are added dynamically. There could be 1 or 10 but I want the formatting to be consistent. (using Django) bootstrap formatting example
<div class="container">
<div class="col-2">
<div class="card card-body">
<br>
<!--{% for object in business %}-->
<div style="text-align:center"><img src="{{ object.logo.url }}" alt="Card image cap" width="90" height="90"></div>
<br>
<h5 style="text-align:center;">{{ object.name }}</h5>
<!--{% endfor %}-->
<!--{% if user.is_authenticated %}-->
<h6 style="text-align:center;">{{ user.username }}</h6>
<!--{% endif %}-->
<p style="text-align:center;">Ratings go here</p>
<br>
</div>
</div>
<div class="col-10">
<div class="row">
<!--{% if service %}-->
<!--{% for services in service %}-->
<div class="col-4">
<div class="card" style="width: 18rem;" href="">
<img class="card-img-top" src="{{ services.cover_image.url }}" alt="{% static 'images\default_cover.jpg' %}" >
<div class="card-body">
<p class="card-text">{{ services.description }}</p>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">(Rating goes here)</li>
<li class="list-group-item">Starting at: ${{ services.price }} </li>
</ul>
</div>
</div>
<!--{% endfor %}-->
<!--{% endif %}-->
</div>
</div>

Something like this should work:
<div class="container">
<div class="col-2">left column</div>
<div class="col-10">
<div class="row">
<div class="col-4">three elements per row</div>
<div class="col-4">three elements per row</div>
<div class="col-4">three elements per row</div>
</div>
<div class="row">
<div class="col-12">one element per row</div>
<div class="col-12">one element per row</div>
<div class="col-12">one element per row</div>
</div>
</div>
</div>

Related

How to add padding downwards in a bootstrap card?

I want to add padding on all four sides of a bootstrap card, and so used the attribute style='padding:25px', but padding is only being applied on the other three sides except downwards, i.e there are no padding between rows. How do I fix this? I am using django and htm
<div class="row" style='padding:25px'>
{% for player in players %}
<div class="col-auto col-md-3">
<div class="column">
<div class="card" style="width: 18rem;">
<img class="card-img-top" width="20" height="300" src="{{ player.image_url }}">
<div class="card-body">
<h5 class="card-title">{{ player.name }}</h5>
<p class="card-text">{{ player.position }}</p>
Know More!
</div>
</div>
</div>
</div>
{% endfor %}
</div>
Add this :
<div class="row" style='padding:25px'>
{% for player in players %}
<div class="col-auto col-md-3">
<div class="column" style='padding:25px'>
<div class="card" style="width: 18rem;">
<img class="card-img-top" width="20" height="300" src="{{ player.image_url }}">
<div class="card-body">
<h5 class="card-title">{{ player.name }}</h5>
<p class="card-text">{{ player.position }}</p>

How do I add a new column to a Bootstrap grid?

I have the following html for a website page built with Bootstrap:
{{ define "main" }}
{{ $pageurl := .Permalink }}
<div class="col-xs-12 col-sm-8 col-md-9 content-column white-background">
{{ partial "mobile_nav_toggle.html" . }}
<div class="row">
<div class="col-lg-8">
<div class="jumbotron">
<h1 class="display-4">{{ .Title }}</h1>
<p class="lead">
<h3 style="font-weight:100;"> — was made by <i>{{ .Params.author }}</i></h3>
</p>
<hr class="my-4">
<p style="font-size:20px;">Who is a student of <strong>{{ .Params.major }}</strong>, when they were in their year <strong>{{ .Params.year }}.</strong></p>
</div>
<div class="content-column-content">
<br>
<h4>Project Abstract:</h4>
<hr>
<p>{{ .Params.description }}</p>
<hr>
<div class="row" style="padding-top:100px;">
<div class="col-sm-6">
<div class="card">
<div class="card-body">
<h5 class="card-title">Reach out to them</h5>
<p>Copy a link to this page to save or reach out to them to learn more:</p>
<button type="button" onclick="copyStringToClipboard({{ $pageurl }});
" style="border-radius:2px;padding:10px;" class="btn btn-primary ">Copy Link</button>
Contact Them
</div>
</div>
</div>
<div class="col-sm-6" style="background:#f2f2f2;">
<div class="card">
<div class="card-body">
<h5 class="card-title">Browse More By:</h5>
<ul class="list-group">
<li class="list-group-item d-flex justify-content-between align-items-center">
{{ .Params.major }} <span class="badge badge-primary badge-pill">14</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
Year {{ .Params.year }} Students <span class="badge badge-primary badge-pill">2</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
{{ .Params.tools }} <span class="badge badge-primary badge-pill">1</span>
</li>
</ul>
</div>
</div>
</div>
</div>
<br>
</div>
</div>
</div>
{{ end }}
I don't know how to add a new column to this. I've tried copying <div class="col-xs-12 col-sm-8 col-md-9 content-column white-background"> and adding things inside it, but it just adds it below the existing content. Essentially, I want to have a new sticky column where the 'Browse more` box appears next to the jumbotron.
try this
{{ define "main" }}
{{ $pageurl := .Permalink }}
<div class="col-xs-12 col-sm-8 col-md-9 content-column white-background">
{{ partial "mobile_nav_toggle.html" . }}
<div class="row">
<div class="col-lg-8">
<div class="jumbotron">
<h1 class="display-4">{{ .Title }}</h1>
<p class="lead">
<h3 style="font-weight:100;"> — was made by <i>{{ .Params.author }}</i></h3>
</p>
<hr class="my-4">
<p style="font-size:20px;">Who is a student of <strong>{{ .Params.major }}</strong>, when they were
in their year <strong>{{ .Params.year }}.</strong></p>
</div>
<div class="content-column-content">
<br>
<h4>Project Abstract:</h4>
<hr>
<p>{{ .Params.description }}</p>
<hr>
<div class="row" style="padding-top:100px;">
<div class="col-sm-6">
<div class="card">
<div class="card-body">
<h5 class="card-title">Reach out to them</h5>
<p>Copy a link to this page to save or reach out to them to learn more:</p>
<button type="button" onclick="copyStringToClipboard({{ $pageurl }});
" style="border-radius:2px;padding:10px;" class="btn btn-primary ">Copy Link</button>
<a href="#" class="btn btn-primary"
style="background:#353535;border-color:#353535;border-radius:2px;padding:10px;">Contact
Them</a>
</div>
</div>
</div>
<div class="col-sm-6" style="background:#f2f2f2;">
</div>
</div>
<br>
</div>
</div>
<div class="col-lg-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Browse More By:</h5>
<ul class="list-group">
<li class="list-group-item d-flex justify-content-between align-items-center">
{{ .Params.major }} <span class="badge badge-primary badge-pill">14</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
Year {{ .Params.year }} Students <span
class="badge badge-primary badge-pill">2</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
{{ .Params.tools }} <span class="badge badge-primary badge-pill">1</span>
</li>
</ul>
</div>
</div>
</div>
</div>
{{ end }}
for more info about bootstrap layout grids refer here
You need to manage 12 columns per row. You added this div for the first column
<div class="col-xs-12 col-sm-8 col-md-9 content-column white-background"></div>
Now you need to use this div.
<div class="col-xs-12 col-sm-4 col-md-3 content-column white-background"></div>
If I use "col-md-7" then I will add "col-md-5" for the second column.

Bootstrap cards under each other

Now i have this:
<div class="row row-cols-1 row-cols-md-2 g-4">
{{#each stories}}
<div class="col">
<div class="card shadow-sm">
<img class="card-img-top" src="{{ image }}">
<div class="card-body">
<p class="card-text">{{ description }}</p>
<div class="d-flex justify-content-between align-items-center">
Читать
<small class="text-muted">author</small>
</div>
</div>
</div>
</div>
{{/each}}
</div>
And it looks like:
Now
I want the cards to be under each other: Reference
if you wanna put every card under each other you should put w-100 to each of cards or change your code like this :
<div class="row g-4">
{{#each stories}}
<div class="col-lg-12 mx-auto">
<div class="card shadow-sm">
<img class="card-img-top" src="{{ image }}">
<div class="card-body">
<p class="card-text">{{ description }}</p>
<div class="d-flex justify-content-between align-items-center">
Читать
<small class="text-muted">author</small>
</div>
</div>
</div>
</div>
{{/each}}
</div>

Print all posts inside a 3x3 grid with Bootstrap and Jekyll

I’m trying to create a grid with Bootstrap 4 that contains my posts in a 3x3 grid.
My code now is:
<div class="col-sm-8" id="main-content">
<div class="row">
{% for post in site.posts%}
<div class="col-sm-4">
<div class="card" style="width: 20rem;">
<img class="card-img-top" src="../media/logo-prueba.jpg">
<div class="card-block">
<h4 class="card-title">{{ post.title }}</h4>
<p class="card-text">{{ post.category }}</p>
</div>
</div>
</div>
{% endfor %}
</div>
The first div with col-sm-8 is just there because I’m also using a sidebar.
How can I approach this? Like printing in a row 3, then in the next one 3, and the last on 3?
The output is this one with 3 posts:
<div class="row">
<div class="col-sm-4">
<div class="card" style="width: 20rem;">
<img class="card-img-top" src="../media/logo-prueba.jpg">
<div class="card-block">
<h4 class="card-title">test1</h4>
<p class="card-text"></p>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="card" style="width: 20rem;">
<img class="card-img-top" src="../media/logo-prueba.jpg">
<div class="card-block">
<h4 class="card-title">Otro post!</h4>
<p class="card-text"></p>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="card" style="width: 20rem;">
<img class="card-img-top" src="../media/logo-prueba.jpg">
<div class="card-block">
<h4 class="card-title">Calzón chino</h4>
<p class="card-text"></p>
</div>
</div>
</div>
</div>
</div>
Any help? Thanks in advance!
Setting a fixed inline width to a bootstrap element who's parent has a percentage width is not the way to go, as it will break the responsive behaviour. By default, the card element takes up all available space in your column. If you want it to be smaller, use a margin on the card and not a fixed with (rem equals an amount of pixels). Make sure the image width is (still) 100%.
{% for post in site.posts limit:9 %}
<div class="col-sm-4">
<div class="card" style="width: 20rem;">
<img class="card-img-top" src="../media/logo-prueba.jpg">
<div class="card-block">
<h4 class="card-title">{{ post.title }}</h4>
<p class="card-text">{{ post.category }}</p>
</div>
</div>
</div>
{% endfor %}
Finally, as suggested in the comments, use modulo to prevent strange stacking behaviour when the first or the second item is higher than the third:
{% for post in site.posts limit:9 %}
{% assign indexmod3 = forloop.index | modulo: 3 %}
{% if indexmod3 == 0 %}<div style="clear: both;"></div>{% endif %}
<div class="col-sm-4">
...
</div>
</div>
{% endfor %}

V-for on rendering multiple elements

Just trying to pick up Vue.js so please be gentle :smiley:
The issue I’m facing is that when i’m binding elements separately on two different columns it everything works, but it messes up my layout. All images load on first row and articles are rendered below.
the code =>
```<div class="row no-gutters"> <!-- remove horizontal paddings between columns 4 this row -->
<div class="col-md-2" v-for="(post, img) in posts">
<div class="article-image">
<img :src="post.img" />
</div>
</div>
<div class="col-md-6" v-for="(post, title) in posts" v-bind="post.id">
<div class="article">
<div class="card">
<div class="card-body">
<h3 class="card-title">{{ post.title }}</h3>
<h6 class="card-subtitle text-muted">21st Dec 17</h6>
<p class="card-text">{{ post.content }}</p>
</div>
</div>
</div>
</div>```
So, I decided to put the v-for on the row class instead and have it loop through image and article one after another, rather than loading all images first and then all the articles.
the code =>
```<div class="row no-gutters" v-for="(post, img, title) in posts" v-bind="post.id">
<div class="col-md-2" v-for="(post, img) in posts">
<div class="article-image">
<img :src="post.img">
</div>
</div>
<div class="col-md-6" >
<div class="article">
<div class="card">
<div class="card-body">
<h3 class="card-title">{{ post.title }}</h3>
<h6 class="card-subtitle text-muted">21st Dec 17</h6>
<p class="card-text">{{ post.content }}</p>
</div>
</div>
</div>
</div>```
I’m not sure if I’m failing at declaring it properly, but I’m getting the following error =>
(source: vuejs.org)
Any help would be much appreciated.
Wrap your template in a div
<div>
<div class="col-md-2" v-for="(post, img) in posts">
<div class="article-image">
<img :src="post.img" />
</div>
</div>
<div class="col-md-6" v-for="(post, title) in posts" v-bind="post.id">
<div class="article">
<div class="card">
<div class="card-body">
<h3 class="card-title">{{ post.title }}</h3>
<h6 class="card-subtitle text-muted">21st Dec 17</h6>
<p class="card-text">{{ post.content }}</p>
</div>
</div>
</div>
</div>
</div>
Why?
You can only have one root element in your template; v-for makes multiple.
Thats the final template that worked for me...
<div>
<div class="row no-gutters" v-for="(post, img, title) in posts" v-bind="post.id"> <!-- remove horizontal paddings between columns 4 this row -->
<div class="col-md-2">
<div class="article-image">
<img :src="post.img" />
</div>
</div>
<div class="col-md-6">
<div class="article">
<div class="card">
<div class="card-body">
<h3 class="card-title">{{ post.title }}</h3>
<h6 class="card-subtitle text-muted">21st Dec 17</h6>
<p class="card-text">{{ post.content }}</p>
</div>
</div>
</div>
</div>
</div>