How to render django blog posts in a row? - html

Why my post going under? How to fix this
post_detail_html
<div class="container">
<div class="section-fluid ">
<br />
<div class="row">
<div class="col-md-4">
<div class="card-deck">
<div class="card card card-blog">
<div class="card-image">
<a href="#pablo">
<img class="img rounded img-raised" src="{{ post.thumbnail.url }}" />
</a>
</div>
<div class="card-body">
<a class="badge badge-success" href="{% url "blog:post_list_by_tag" tag.slug %}">
</a>
<h4 class="card-title">
{{ post.title }}
</h4>
<p class="card-description">
{{ post.body|truncatewords:30|linebreaks }}
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
check this image;
How to make like this, in a row (3 cards);

You are displaying each blog post inside a div with class="row" which is causing each blog post to get its own row.
I am assuming your blog posts are being rendered with for loop somewhere in the template.
Try putting two blog posts in each row div by replacing your forloop with something like this:
{% for post in blog_posts %}
{% if forloop.counter0|divisibleby:2 %}
<div class="row">
<div class="col-md-4">
<div class="card-deck">
<div class="card card card-blog">
<div class="card-image">
<a href="#pablo">
<img class="img rounded img-raised" src="{{ post.thumbnail.url }}" />
</a>
</div>
<div class="card-body">
<a class="badge badge-success" href="{% url "blog:post_list_by_tag" tag.slug %}">
</a>
<h4 class="card-title">
{{ post.title }}
</h4>
<p class="card-description">
{{ post.body|truncatewords:30|linebreaks }}
</p>
</div>
</div>
</div>
</div>
{% with next_post=list|next:forloop.counter0 %}
{% if next_post %}
<div class="col-md-4">
<div class="card-deck">
<div class="card card card-blog">
<div class="card-image">
<a href="#pablo">
<img class="img rounded img-raised" src="{{ next_post.thumbnail.url }}" />
</a>
</div>
<div class="card-body">
<a class="badge badge-success" href="{% url "blog:post_list_by_tag" tag.slug %}">
</a>
<h4 class="card-title">
{{ next_post.title }}
</h4>
<p class="card-description">
{{ next_post.body|truncatewords:30|linebreaks }}
</p>
</div>
</div>
</div>
</div>
{% endif %}
</div>
{% endif %}
{% endfor %}

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>

Why are my bootstrap cards aligned on top of each other and not aligned side by side?

My bootstrap cards are not aligning side by side and I can't seem to find my mistake. I am using django and html.
{% extends 'base.html' %}
<div>
{% block content %}
<h1>Players<h1>
{% for player in players %}
<div class="row">
<div class="column">
<div class="card" style="width: 18rem;">
<img class="card-img-top" 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 %}
{% endblock %}
</div>
try this
use bootstrap grid https://getbootstrap.com/docs/4.0/layout/grid/
{% extends 'base.html' %}
<div>
{% block content %}
<h1>
Players
<h1>
<div class="row">
{% 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" 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>
{% endblock %}
</div>

Need dynamic rows inside bootstrap 4

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>

How can I bring down the featured image a little?

How can I bring down the featured image a little so that it aligns with the title ?
This is web page AnyGeeks
This is the code that sets the image.
<div class="container">
<div class="jumbotron jumbotron-fluid mb-3 pl-0 pt-0 pb-0 bg-white position-relative">
<div class="h-100 tofront">
<div class="row justify-content-between">
<div class="col-md-6 pt-6 pb-6 pr-6 align-self-center">
<p class="text-uppercase font-weight-bold">
<a class="text-danger" href="./category.html">{% block category %}{% endblock %}</a>
</p>
<h1 class="display-4 secondfont mb-3 font-weight-bold">{% block ptitle %} {% endblock %}</h1>
<p class="mb-3">
{% block desc %} {% endblock %}
</p>
<div class="d-flex align-items-center">
<img class="rounded-circle" src="{{url_for('static',filename='img/avatar.jpeg')}}" width="70">
<small class="ml-2">RahulVk<span class="text-muted d-block">{% block dtt %}{% endblock %}read</span>
</small>
</div>
</div>
<div class="col-md-6 pr-0">
<img src="{% block featuredImage %}{% endblock %}">
</div>
</div>
</div>
</div>
I am using flask as backend. That is why the tags are there.
I would suggest you to add display flex in your div, and align-items center:
<div class="col-md-6 pr-0 d-flex align-items-center">
<img src="{% block featuredImage %}{% endblock %}">
</div>
Or you can add some padding top:
<div class="col-md-6 pr-0 pt-4">
<img src="{% block featuredImage %}{% endblock %}">
</div>
I would like to suggest you add align-items-center class in your .row class. Like #flpfar suggests, you can add in col-md-6 class and it will work 100% but it's not straightway.
<div class="row justify-content-between align-items-center"></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 %}