I'm trying to implement card bootstrapping in my .html but I cannot get it to be centered. Please see the code below and help
<h1> 10 Games Recommended Based on {{ selected }} </h1>
<div class = "container">
<div class="recommendations">
{% for name in names_list %}
<div class="card-group">
<div class="card text-center" style="Max-width: 30%;">
<!-- <img src="..." class="card-img-top" alt="..."> -->
<div class="card-body">
<h5 class="card-title"> {{ name }}</h5>
<div class = 'card-body'>
<p1 class = "card-text">Overall Reviews: {{games[name]['rating'] }}</p1>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
I apologize for the mess but the way my app is giving results is pushed to the left like this.
My style is below
<style>
p {font-size: 30px;}
p1 {font-size: 13px;}
a {color:navy;
font-size: 20px;}
body {text-align: center;}
body {background-color: lightblue;}
</style>
Is there anyway I can center these or align them side by side when using loop?
You're missing .row and .col classes. Add them to make it.
<h1>10 Games Recommended Based on {{ selected }}</h1>
<div class="container">
<div class="row">
<div class="recommendations">
{% for name in names_list %}
<div class="col-3">
<div class="card-group">
<div class="card text-center" style="max-width: 30%">
<!-- <img src="..." class="card-img-top" alt="..."> -->
<div class="card-body">
<h5 class="card-title">
{{ name }}
</h5>
<div class="card-body">
<p1 class="card-text"
>Overall Reviews: {{games[name]['rating'] }}</p1
>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
Just note that .col-3 is supposed to be repeated and .row should be parent.
Related
I'm developing an e-commerce with Django. My backend is fine, my problem is with the template. Currently, I want to display 4 products per row, and if there are 7 products, the other 3 must be aligned with the top one. I'm using bootstrap to do this, however, for some reason I don't know, it doesn't have 4 products on the same line, even with space. I'm using a container with 1200px.
home.html
<div class="container">
<div class="row">
<div class="col-lg-8">
<div class="row">
{% for product in products %}
<div class="card mb-4 border rounded" style="width: 13.5rem;">
<a href="{{ product.get_absolute_url }}">
{%if product.image %}
<img class="img-produto" src='/media/{{product.image}}' class="card-img-top hover_img ">
{% else%}
<img class="img-produto" src="{% static '/img/not-found-product.jpg' %}" class="card-img-top hover_img">
{%endif%}
</a>
<div class="card-body">
<p class="card-title">{{product.name}}</p>
<p class="card-text"><i class='fas fa-dollar-sign' style="margin-right:2px"></i>{{product.price}}</p>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
Just remove width: 13.5rem; and add class col-4 in the div. Like,
<div class="col-4 card mb-4 border rounded">
<!-- your content goes here -->
</div>
I am extending base.html in Django and want to change the <header> tag background-image. I {% extends 'blog/base.html' %} but the background-image does not appear on child template. I wonder what seems to be error? I am inheriting base template using {% block header %} tag to insert a new <header> tag into the child template. The base template header I want to change the header background-image is the following.
<header class="masthead" style="background-image: url('static/assets/img/home-bg.jpg');margin-bottom: 0;padding-top: 21%;padding-bottom: 10%;">
<div class="container position-relative px-4 px-lg-5" style="padding-top: 0;">
<div class="row gx-2 gx-lg-5 justify-content-center">
<div class="col-md-10 col-lg-8 col-xl-7">
<div class="site-heading">
<span class="subheading"> Novel life hacks, tricks, skills and methods in all walks of life.</span>
</div>
</div>
</div>
</div>
</header>
I got it to work through block template tag.
in base.html:
{% block header %}
<header class="masthead" style="background-image: url('static/assets/img/home-bg.jpg');margin-bottom: 0;padding-top: 21%;padding-bottom: 10%;">
<div class="container position-relative px-4 px-lg-5" style="padding-top: 0;">
<div class="row gx-2 gx-lg-5 justify-content-center">
<div class="col-md-10 col-lg-8 col-xl-7">
<div class="site-heading">
<span class="subheading"> Novel life hacks, tricks, skills and methods in all walks of life.</span>
</div>
</div>
</div>
</div>
</header>
{% endblock %}
and in postdetail.html:
{% block header %}
<header class="masthead" style="background-image: url({% static 'assets/img/home-bg.jpg' %}); ; background-position: center; margin-bottom: 0;padding-top: 21%;padding-bottom: 10%;">
<div class="container position-relative px-4 px-lg-5" style="padding-top: 0;">
<div class="row gx-2 gx-lg-5 justify-content-center">
<div class="col-md-10 col-lg-8 col-xl-7">
<div class="site-heading">
<span class="subheading"> Novel life hacks, tricks, skills and methods in all walks of life.</span>
</div>
</div>
</div>
</div>
</header>
{% endblock %}
I am making a blogging website like this
I want to remove these tags (<p> <em>) which are being displayed in these cards
page-html (before adding safe tag):
<div class="container">
<div class="card-deck">
{% for post in top_posts %}
<div class="card">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">{{post.title|truncatechars:14|safe}}</h5>
<p class="card-text text-justify">{{post.content|truncatechars:190}}</p>
<br>
<p class="card-text"><small class="text-muted">{{post.timeStamp|timesince}}</small></p>
<div>
ReadMore
</div>
</div>
</div>
{% endfor %}
</div>
</div>
page-html (after adding safe tag):
<div class="container">
<div class="card-deck">
{% for post in top_posts %}
<div class="card">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">{{post.title|truncatechars:14|safe}}</h5>
<p class="card-text text-justify">{{post.content|truncatechars:190|safe}}</p>
<br>
<p class="card-text"><small class="text-muted">{{post.timeStamp|timesince}}</small></p>
<div>
ReadMore
</div>
</div>
</div>
{% endfor %}
</div>
</div>
how page looks:
help me to remove these italics and display the text in the original cards style.
BTW I am using ck editor as my richtext editor
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'?
There is a menu on the left with the effect of the accordion, on the right content is formed with a jinja. I need to do so that the height of the menu and the contents do not depend on each other.
as here: click
HTML:
<!-- menu -->
<div class="col-md-3">
<div class="wrapper">
<h1 class="header-tabs">Brands</h1>
<div class="tab">
{% for brand in brands %}
<button value="{{ brand.id }}">{{ brand.brand_name }
</button>
{% endfor %}
</div>
</div>
</div>
<!-- content -->
{% for sm in smartphones %}
<div class="col-md-2">
<img class="photo-phone" height="150" width="150" src="{{ sm.photo.url }}">
</div>
<div class="col-md-5">
<h3 class="header-phone">{{ sm.brand }} {{ sm.model }}</h3>
<p descr-phone>{{ sm.description }}</p>
</div>
<div class="col-md-2">
<h4 class="price">{{ sm.price }}$</h4>
<input type="button" class="button-buy" value="Buy">
</div>
{% endfor %}
The usual way to achieve that is by nesting. Nesting must always be done using row-column pairs i.e. never nest a column directly inside another column.
So, in your case, you'd first create a column with the class col-md-9 then put a .row inside that column and then put all your content columns inside that newly created row.
Note that inside this newly created row you now have a total of 12 column units to work with.
Click "run code snippet" below and expand to full page for testing:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row">
<!-- menu -->
<div class="col-md-3">
<div class="wrapper">
<h1 class="header-tabs">Brands:</h1>
<div class="tab">
<!-- {% for brand in brands %}-->
<button value="{{ brand.id }}">
<!-- {{ brand.brand_name }-->
Brand Name
</button>
<!-- {% endfor %}-->
</div>
</div>
</div>
<!-- content -->
<div class="col-md-9">
<div class="row">
<!-- {% for sm in smartphones %}-->
<div class="col-md-3 mb-3">
<!-- <img class="photo-phone" height="150" width="150" src="{{ sm.photo.url }}">-->
<img class="photo-phone img-fluid" src="https://placeimg.com/640/480/tech">
</div>
<div class="col-md-6">
<h3 class="header-phone">
<!-- {{ sm.brand }} {{ sm.model }}-->
Brand Model
</h3>
<p descr-phone>
<!-- {{ sm.description }}-->
Description
</p>
</div>
<div class="col-md-3 mb-3">
<h4 class="price">
<!-- {{ sm.price }}$-->
$1,000
</h4>
<input type="button" class="button-buy" value="Buy">
</div>
<div class="col-md-3 mb-3">
<!-- <img class="photo-phone" height="150" width="150" src="{{ sm.photo.url }}">-->
<img class="photo-phone img-fluid" src="https://placeimg.com/640/480/tech">
</div>
<div class="col-md-6">
<h3 class="header-phone">
<!-- {{ sm.brand }} {{ sm.model }}-->
Brand Model
</h3>
<p descr-phone>
<!-- {{ sm.description }}-->
Description
</p>
</div>
<div class="col-md-3 mb-3">
<h4 class="price">
<!-- {{ sm.price }}$-->
$1,000
</h4>
<input type="button" class="button-buy" value="Buy">
</div>
<div class="col-md-3 mb-3">
<!-- <img class="photo-phone" height="150" width="150" src="{{ sm.photo.url }}">-->
<img class="photo-phone img-fluid" src="https://placeimg.com/640/480/tech">
</div>
<div class="col-md-6">
<h3 class="header-phone">
<!-- {{ sm.brand }} {{ sm.model }}-->
Brand Model
</h3>
<p descr-phone>
<!-- {{ sm.description }}-->
Description
</p>
</div>
<div class="col-md-3 mb-3">
<h4 class="price">
<!-- {{ sm.price }}$-->
$1,000
</h4>
<input type="button" class="button-buy" value="Buy">
</div>
<!-- {% endfor %}-->
</div>
</div>
</div>
</div>
Also note the use of the spacing class mb-3 (margin-bottom 3 units).
The img-fluid class makes the images responsive.
Reference:
https://getbootstrap.com/docs/4.0/layout/grid/#nesting