I am currently working on a django blog. However, I am experiencing some difficulties with the size of the post thumbnails. Here's a picture:
What I marked in yellow is how the image should be filling the space. The width is fine, but the heigh isn't working well as you can see.
Here's the code:
{% extends 'base.html' %}
{% load static %}
{% block content %}
<style>
img {
height: 100%;
width: 100%;
}
</style>
<!-- Post-->
{% for obj in object_list %}
<div class="row d-flex align-items-stretch">
{% if not forloop.first and not forloop.last %}
<div class="image col-lg-5"><img src="{{ obj.thumbnail.url }}" alt="..."></div> #Here's the image
{% endif %}
<div class="text col-lg-7">
<div class="text-inner d-flex align-items-center">
<div class="content">
<header class="post-header">
<div class="category">
{% for cat in obj.categories.all %}
{{ cat }}
{% endfor %}
</div>
<a href="{{ obj.get_absolute_url }}">
<h2 class="h4">{{ obj.title }}</h2>
</a>
</header>
<p>{{ obj.overview|linebreaks|truncatechars:200 }}</p>
<footer class="post-footer d-flex align-items-center"><a href="#" class="author d-flex align-items-center flex-wrap">
<div class="avatar"><img src="{{ obj.author.profile_picture.url }}" alt="..." class="img-fluid"></div>
<div class="title"><span>{{ obj.author }}</span></div></a>
<div class="date"><i class="icon-clock"></i> {{ obj.timestamp|timesince }} ago</div>
<div class="comments"><i class="icon-comment"></i>{{ obj.comment_count }}</div>
</footer>
</div>
</div>
</div>
{% if forloop.first or forloop.last %}
<div class="image col-lg-5"><img src="{{ obj.thumbnail.url }}" alt="..."></div> #Here's the image
{% endif %}
</div>
{% endfor %}
</div>
</section>
It is <img>'s default behaivor to fill the whole width and height, often losing its aspect ratio.
The fact that it did not happen in your case, most likely is because you set object-fit: contain somewhere in your css.
You either remove object-fit: contain setting, or you can use
img {
height: 100%;
width: 100%;
object-fit: fill !important; # fill is the default value.
}
I have a parent div where children div are added. I use pagination set to five.
On large screen everything is fine but on smaller device (14.00-inch display that has a resolution of 1920x1080 pixels) the children divs are overlaying the parent div at the bottom.
The whole height of the children div can differ depending on how many children div are displayed (1,2,3,4 or 5)
This is the CSS of my parent div:
header.nav_masthead {
padding-top: 6.5rem;
background-color: #345a61;
background-size: cover;
background-position: center;
background-image:;...;
}
The div where the children div are added:
<div id='fav_list' class="w-75 mx-auto" style='background-color: transparent; height: auto;'>
This is my page HTML:
{% block content %}
<header class="masthead" >
<div class="col-lg-12">
<h2 class="intro-text text-center" style="color: beige;">Bienvenue sur ton compte {{ user }}</h2>
<hr class="divider1 my-4" />
<div class='w-75 mx-auto row d-flex justify-content-around mb-3'>
<h3 class="intro-text text-center account_items" style="color: beige;">Produit recherché</h3>
<h3 class="intro-text text-center account_items" style="color: beige;">Produit de substitut</h3>
</div>
</div>
<div id='fav_list' class="w-75 mx-auto" style='background-color: transparent; height: auto;'>
{% for saved in saved_list %}
<div class='row d-flex justify-content-between'>
<div class="card mb-3" style="width: 49%;">
<div class="row no-gutters">
<div class="col-md-2 my-auto">
<img class="mx-auto d-block" style="width:auto; height:auto; max-width:100px; max-height:100px; "
src="{{ saved.original_product.picture }}">
</div>
<div class="col-md-10">
<div class="card-body">
<h5 class="card-title"><a href="{% url 'finder:detail' saved.original_product.id %}"
class="aaccount">{{ saved.original_product.real_name }}/ {{ saved.original_product.real_brand }}</a>
</h5>
<img src="/static/finder/img/nutriscore-{{ saved.original_product.nutrition_grade}}.svg"
style="width:70px;"><br>
</div>
</div>
</div>
</div>
<div class="card mb-3" style="width: 49%;">
<div class="row no-gutters">
<div class="col-md-2 my-auto">
<img class="mx-auto d-block " style="width:auto; height:auto; max-width:100px; max-height:100px; "
src="{{ saved.sub_product.picture }}">
</div>
<div class="col-md-9">
<div class="card-body">
<h5 class="card-title"><a href="{% url 'finder:detail' saved.sub_product.id %}"
class="aaccount">{{ saved.sub_product.real_name}}/ {{ saved.sub_product.real_brand }}</a>
</h5>
<img src="/static/finder/img/nutriscore-{{ saved.sub_product.nutrition_grade}}.svg"
style="width:70px;"><br>
</div>
</div>
<div class="col-md-1 my-auto mx-auto">
<button type ='button' class=' btn substitut' value='{{ saved.id }}'>{% csrf_token %}<i class='fas fa-trash-alt'></i></button>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</header>
<div id='navigation'>
{% if paginate %}
<div style="background-color: #E8A75D; overflow: auto; ">
<div class="clearfix"></div>
{% for i in page_range %}
{% if i == 1%}
<span><button class='btn nav_button first ' value='{{ i }}'>{{i}}</button></span>
{% else %}
<span><button class='btn nav_button ' value='{{ i }}'>{{i}}</button></span>
{% endif %}
{% endfor %}
{% endif %}
</div>
{% endblock %}
What should I do to make my div 'fav_list' not overlapping my div '.nav_masthead'?
I am developing a blog and it is almost done. I want page numbers on each page, I already have arrows for next page and previous page.
It is a custom coded blog developed in Hubspot hence the use of HUBL, a templating language and HTML.
Can anyone tell me what line of code I need to add in order to get page numbers on there too?
I have separated it into to documents: BlogList.html and Blogpost.html and will show you what I have so far.
Any advice will be welcomed.
Thank you.
BlogList.html:
<!DOCTYPE html>
<html lang="en">
<head>
{% set page_domain = "https://hello.com" %}
{% set images_domain = "https://login.hello.com" %}
{% import '/2019 Theme/MacroMeta.html' %}
{{ scm_meta(page_meta.html_title) }}
</head>
<body>
{% import '/2019 Theme/MacroHeader.html' %}
{{ scm_header() }}
{{ standard_header_includes }}
<div class="content_container">
<div class="banner internal_banner" style="background-image: url('{{images_domain}}/blog-images/banner_blog.jpg')">
<div class="content text-center">
<img src="{{images_domain}}/blog-images/banner_icon_blog.png"
srcset="{{images_domain}}/blog-images/banner_icon_blog#2x.png 2x" alt="" class="mb-4">
<h1 class="mb-3"><strong>Blog</strong></h1>
</div>
</div>
<div class="section section_grey">
<div class="content">
<div class="row blog_posts_list_ctn">
{% for content in contents %}
<div class="col-12 col-sm-6 col-md-4 py-3">
<div class="blog_post_list">
<div class="blog_list_img_holder">
{% if content.post_list_summary_featured_image %}
<a href="{{content.absolute_url}}"><img src="{{ content.post_list_summary_featured_image }}" alt=""
class="img-fluid"></a>
{% endif %}
</div>
<div class="blog_list_text text-center">
<div class="blog_list_date text-uppercase">
{{ content.updated|datetimeformat('%A, %B %e, %Y') }}
</div>
<div class="blog-list-title">
<h3><strong>{{ content.name }}</strong></h3>
</div>
<div class="blog-list-text">
{{ content.post_list_content|safe }}
</div>
<div class="blog-list-btn">
Read more
</div>
<!--
{% if content.topic_list %}
<div class="acticle_tags">
{% for topic in content.topic_list %}
#{{ topic.name }}{% if not loop.last %},{% endif %}
{% endfor %}
</div>
{% endif %}
-->
</div>
</div>
</div>
{% endfor %}
</div>
<div class="blog_paginate d-flex">
{% if last_page_num %}
<a href="{{ blog_page_link(last_page_num) }}" class="paginate_prev"><i class="fa fa-long-arrow-left"
aria-hidden="true"></i> Prev</a>
{% endif %}
{% if next_page_num %}
<a href="{{ blog_page_link(next_page_num) }}" class="paginate_next">Next <i class="fa fa-long-arrow-right"
aria-hidden="true"></i></a>
{% endif %}
</div>
</div>
</div>
</div>
{% import '/2019 Theme/MacroFooter.html' %}
{{ scm_footer() }}
{{ standard_footer_includes }}
</body>
</html>
BlogPost.html:
<!DOCTYPE html>
<html lang="en">
<head>
{% set page_domain = "https://hello.com" %}
{% set images_domain = "https://login.hello.com" %}
{% import '/2019 Theme/MacroMeta.html' %}
{{ scm_meta(page_meta.html_title + ' | Hello Blog') }}
{% import '/2019 Theme/MacroBlogCanonicalUrl.html' %}
</head>
<body>
{% import '/2019 Theme/MacroHeader.html' %}
{{ scm_header() }}
{{ standard_header_includes }}
<div class="section">
<div class="content">
<div class="back-to-blog-link">
<a class="back-link" href="https://blog.scanmarket.com">Back to the Hello Blog</a>
</div>
<div class="article_title_ctn">
<h2 class="text-center"><strong>{{ content.name }}</strong></h2>
</div>
<div class="row blog_post_details py-5 my-3 my-lg-5">
<div class="col-12 col-md-6">
<div class="section_grey p-4 p-lg-5 blog-post-intro">
<h3><strong>{{ content.post_list_content|safe }}</strong></h3>
</div>
</div>
<div class="col-12 col-md-5 offset-md-1 mt-5 mt-md-0">
<div class="article_details">
<table class="table_details border-0 align-middle w-100">
<tbody>
<tr>
<td><strong>Author</strong></td>
<td>
<div class="article_authors">
<a class="author-link"
href="{{ group.absolute_url }}/author/{{ content.blog_post_author.slug }}">{{ content.blog_post_author.display_name }}</a>
</div>
</td>
</tr>
<tr>
<td><strong>Date</strong></td>
<td>
<p class="small_text text_grey mb-0 text-uppercase">
<strong>{{ content.updated|datetimeformat('%A, %B %e, %Y') }}</strong></p>
</td>
</tr>
<tr class="separator">
<td colspan="2"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="content_small article_content content py-0">
{{ content.post_body }}
</div>
</div>
</div>
{% import '/2019 Theme/MacroFooter.html' %}
{{ scm_footer() }}
{{ standard_footer_includes }}
</body>
</html>
HTML/HubL Code:-
<div class="blog-pagination">
{% set page_list = [-2, -1, 0, 1, 2] %}
{% if contents.total_page_count - current_page_num == 1 %}{% set offset = -1 %}
{% elif contents.total_page_count - current_page_num == 0 %}{% set offset = -2 %}
{% elif current_page_num == 2 %}{% set offset = 1 %}
{% elif current_page_num == 1 %}{% set offset = 2 %}
{% else %}{% set offset = 0 %}{% endif %}
<a class="blog-pagination__link blog-pagination__prev-link {{ "blog-pagination__prev-link--disabled" if !last_page_num }}" href="{{ blog_page_link(last_page_num) }}">
{% icon name="chevron-left" style="SOLID", width="13", no_wrapper=True %}
Prev
</a>
{% for page in page_list %}
{% set this_page = current_page_num + page + offset %}
{% if this_page > 0 and this_page <= contents.total_page_count %}
<a class="blog-pagination__link blog-pagination__number-link {{ "blog-pagination__link--active" if this_page == current_page_num }}" href="{{ blog_page_link(this_page) }}">{{ this_page }}</a>
{% endif %}
{% endfor %}
<a class="blog-pagination__link blog-pagination__next-link {{ "blog-pagination__next-link--disabled" if !next_page_num }}" href="{{ blog_page_link(current_page_num + 1) }}">
Next
{% icon name="chevron-right" style="SOLID", width="13", no_wrapper=True %}
</a>
</div>
CSS Code
.blog-pagination {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
font-family: Lato,sans-serif;
margin-bottom: 3.3rem;
}
.blog-pagination__link {
color: #494a52;
}
.blog-pagination__prev-link--disabled, .blog-pagination__next-link--disabled {
color: #b0c1d4;
pointer-events: none;
cursor: default;
}
.blog-pagination__prev-link {
text-align: right;
margin-right: .25rem;
}
.blog-pagination__prev-link, .blog-pagination__next-link {
display: inline-flex;
align-items: center;
}
.blog-pagination__link {
display: block;
transition: color 0.1s ease-in-out;
line-height: 1.25;
color: #77838f;
background-color: #fff;
border: 0 solid #77838f;
padding: 0.5rem 0.75rem;
border-radius: 5px;
font-weight: 600;
margin-left:5px;
}
.blog-pagination__link:hover {
text-decoration: none;
color: #3e416d;
background-color: rgba(9, 27, 18, 0.1);
border-color: rgba(9, 27, 18, 0.1);
}
.blog-pagination__link--active {
border: 2px solid #b0c1d4;
}
Himanshu's answer is good.
Just adding for anyone who stumbles on this, the HubSpot Theme boilerplate has a pagination module included. This includes the HTML, HubL, and CSS.
https://github.com/HubSpot/cms-theme-boilerplate/tree/main/src/modules/blog-pagination.module
I'm new to foundation and i am building a blog based off the Simple Blog template. The images are currently appearing like this however I would like them to appear in the middle. How would I do this?
This is the current code I have for my posts:
<div id="posts" class="row medium-8 large-7 columns">
{% for i in object_list %}
<a href="{{i.get_absolute_url }}" style="color:dimgrey; text-decoration:none">
<div class="blog-post">
<h3 style="color: black;">{{ i.post_title }}<small> {{ i.post_date }}</small></h3>
<hr> {% if i.post_image %}
<img class="thumbnail" src="{{ i.post_image.url }}"> {% endif %}
<p>{{ i.post_content|linebreaks }}</p>
{% if instance.post_author.get_full_name %}
<div class="callout">
<ul class="menu simple">
<li>Written By: {{ i.post_author.get_full_name }}</li>
</ul>
</div>
{% endif %}
</a>
<br>
{% endfor %}
</div>
Thanks,
-Will
You can use the below code to align the image at the center with respect to the main class of id posts:
div.row medium-8 large-7 columns
{
position: relative;
}
div.row medium-8 large-7 columns img
{
position: absolute;
top: 50%;
left: 50%;
margin-left: [-50% of your image's width];
margin-top: [-50% of your image's height];
}
You could wrap the image in a div and use the text-center class (docs):
<div class="text-center">
<img class="thumbnail" src="{{ i.post_image.url }}">
</div>
{%if collection.title == "Meat"%}
{% if collection.image %}<div class="collection-image" style="background-image: url('{{ collection.image | img_url: '1024x1024' }}'); max-height:400px; "> {% endif %}
<div class="collection-title text-center" style="padding: 50px 0;">
<h1 class="collection-text--headline title text-center" style="margin-top:30px;">{{ collection.title }}</h1>
{% if collection.description.size > 0 %}
<div class="collection-text--body text-center rte large--three-fifths push--large--one-fifth">
<h4>{{ collection.description }}</h4>
</div>
{% endif %}
</div>
<div class="text-center" style="margin-top: -40px;
padding-bottom: 100px;">
<a href="http://www.greensburymarket.com/collections/all" class="btn btn--large btn--splash uppercase sec-col-button" >Learn More</a>
</div>
{% if collection.image %}<div class="collection-image-overlay"></div>
</div>
{% endif %}
know this is a stupid question but I am stumped. tried moving things around. No idea why this doesnt work