How add space between two cards - bootstrap? - web

I was creating a simple blog page using Django. When I added cards for the articles it came like this
There is no space between the cards.
{% extends 'base.html' %}
{% block content %}
<div class="card mt-3" style="width: 100%;">
{% for post in posts %}
<div class="card-header">
<cite title="Source Title">{{ post.author }}</cite>
<small class="text-muted float-right">{{ post.date_posted | date:"F d, Y" }}</small>
</div>
<div class="card-body">
<div class="card-title">{{ post.title }}</div>
<p class="card-text">{{ post.content }}</p>
</div>
{% endfor %}
</div>
{% endblock content %}
How do I add space between these cards?

your for loop is not in correct place change code from
{% extends 'base.html' %}
{% block content %}
<div class="card mt-3" style="width: 100%;">
{% for post in posts %}
<div class="card-header">
<cite title="Source Title">{{ post.author }}</cite>
<small class="text-muted float-right">{{ post.date_posted | date:"F d, Y" }}</small>
</div>
<div class="card-body">
<div class="card-title">{{ post.title }}</div>
<p class="card-text">{{ post.content }}</p>
</div>
{% endfor %}
</div>
{% endblock content %}
to bellow code
{% extends 'base.html' %}
{% block content %}
{% for post in posts %}
<div class="card mt-3" style="width: 100%;">
<div class="card-header">
<cite title="Source Title">{{ post.author }}</cite>
<small class="text-muted float-right">{{ post.date_posted | date:"F d, Y" }}</small>
</div>
<div class="card-body">
<div class="card-title">{{ post.title }}</div>
<p class="card-text">{{ post.content }}</p>
</div>
</div>
{% endfor %}
{% endblock content %}

Firstly, you need to do the loop for every card, instead of doing it for the inner divs 'card-header' and 'card-body'. Secondly, to answer you question, you should use a spacing by either a margin or a padding.
I would suggest to make the cards a standard width and use a 'margin right 3':
{% for post in posts %}
<div class="card mt-3 mr-3" style="width: 250px">
<div class="card-header">
...
</div>
<div class="card-body">
...
</div>
</div>
{% endfor %}
Besides this solution, I suggest you read the Bootstaps Grid Layout documentation, so you can place the cards nicely within your content block.

Related

In Django website even if I add an item by pressing add to cart button the status of True for the product added is not shown and still false is visibl

I have made a django e-comm website , when I press the add to cart button on my home page I have written a function which should change the status of a product from false to true once it is added in the cart but it does not work
I have given my cart.py and index.html code
Thank you
cart.py
from django import template
register = template.Library()
#register.filter(name='is_in_cart')
def is_in_cart(product,cart):
keys = cart.keys()
for id in keys:
print(id , product.id)
if int(id) == product.id:
return True
return False
index.html
{% extends 'main/base.html'%}
{% block title %}
index
{% endblock %}
{% block content %}
{% load cart %}
<div class="container-fluid">
<div class="row">
<div class="col-lg-3">
<div class="list-group mt-3">
{% for items in category %}
{{items.Category_name}} <!--i first used a small c for category but it did not pick the words from my category.py fle-->
{% endfor %}
</div>
</div>
<div class="col-lg-9">
<div class="row">
{% for items in product %}
<div class="card mx-auto mb-3 mt-3" style="width: 18rem;">
<img class="card-img-top" src="{{items.product_image.url}}" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">{{items.product_name}}</h5>
<p class="card-text"><b>{{items.product_price}}</b></p>
<p class="card-text"><b>{{items.product_detail}}</b></p>
{{product | is_in_cart:request.session.cart }}
<form action="/" mthod="POST">
{% csrf_token %}
<input hidden type="text" name='product' value='{{items.id}}'>
<input href="#" type="submit" class="float-right btn btn-light border btn-sm" value="Add to Cart">
</form>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
{% endblock %}

The listing is incorrect

can anyone please help me with this formula? It doesn't give me what I need. The first two posts to the active section, all the others to the inactive one.
{% set memberLength = members|length / 2 %}
{% for i in 1..memberLength %}
{% set sliceStart = i * 2 - 2 %}
{% set sliceLength = 2 %}
{% if i < 2 %}
<div class="carousel-item active">
<div class="row m-0">
{% for key, member in members|slice(sliceStart,sliceLength) %}
<div class="col-lg-6 py-4 ps-lg-3 pe-lg-5 d-lg-block d-none">
<div class="pb-4 mb-2 text-white">
<p class="fw-7 mb-0">{{ member.name }}</p>
<p>{{ member.podjmeno }}</p>
</div>
<div class="text-primary PF fz-19">
<h2 class="fw-4 mb-3">{{ member.nadpisvelky }}</h2>
<p><em>{{ member.description }}</em></p>
</div>
</div>
{% endfor %}
</div>
</div>
{% else %}
<div class="carousel-item">
<div class="row m-0">
{% for key, member in members|slice(sliceStart,sliceLength) %}
<div class="col-lg-6 py-4 ps-lg-3 pe-lg-5 d-lg-block d-none">
<div class="pb-4 mb-2 text-white">
<p class="fw-7 mb-0">{{ member.name }}</p>
<p>{{ member.podjmeno }}</p>
</div>
<div class="text-primary PF fz-19">
<h2 class="fw-4 mb-3">{{ member.nadpisvelky }}</h2>
<p><em>{{ member.description }}</em></p>
</div>
</div>
{% endfor %}
</div>
</div>
{% endif %}
{% endfor %}
If you want to create a repeating HTML structure you are best off with using the filter batch
To set the class active on the first item you can use the attribute first of the loop variable
{% for items in members|batch(2) %}
<div class="carousel-item{{ loop.first ? ' active' }}">
{% for item in items %}
<div class="col-lg-6 py-4 ps-lg-3 pe-lg-5 d-lg-block d-none">
<div class="pb-4 mb-2 text-white">
<p class="fw-7 mb-0">{{ item.name }}</p>
<p>{{ item.podjmeno }}</p>
</div>
<div class="text-primary PF fz-19">
<h2 class="fw-4 mb-3">{{ item.nadpisvelky }}</h2>
<p><em>{{ item.description }}</em></p>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
demo

Inheritance multiple view from base view

I want to include multiple layout file in index file of view and extends all of them from master.volt. But my problem is level-1.volt doesn't render when I run index.volt. Is my workflow ok? What is the problem?
I have on base view file named master.volt that have basic view of my frontend:
<div class="row justify-content-center" id="Level-1">
<div class="col-11">
<div class="row flex-column justify-content-center align-items-center">
{% block bannerOne %}
{% endblock %}
</div>
</div>
</div>
I have one view file named level-1.volt:
{% block bannerOne %}
<div class="col-12 d-flex justify-content-center align-items-center">
<img src="img/pop-1-2.png" class="img-fluid"/>
</div>
{% endblock %}
And this is my index.volt view:
{% extends 'master/master.volt' %}
{% include 'layouts/level-1.volt' %}

Shopify: How to change color of selected menu item?

I am developing a site on Shopify and I need to know how to change color of selected menu items. When a user clicks on any menu items, the color will change and remove once another menu item is selected.
I have tried to solve this problem many times now by using CSS and JQuery, but nothing I do seems to work.
Here is the code for the megamenu liquid file in Shopify.
<nav class="navbar navbar-inverse" data-spy="affix" data-offset-
top="197">
<div class="container">
<div class="mega-menu">
<!-- Brand and toggle get grouped for better mobile display -->
<ul class="nav navbar-nav" id="navbar">
{% assign meagemenu_lists = settings.Megamenu-list %}
{% for link in linklists[meagemenu_lists].links %}
{% assign item = link.title | downcase %}
<li class="level1 dropdown">
<a class="megamenu_icon{% increment count %} a1" href="{{ link.url }}"
title="{{link.title}}">{{ link.title }}</a>
{% for i in (2..5) %}
{%capture Megamenu%}megamenu_{{i}}_parent{%endcapture%}
{% if settings[Megamenu] == item %}
<div class="sub-menu dropdown-menu">
<div class="top-sub-menu">
<div class="item">
{% if settings.service-megamenu-icon1 != blank %}<p
class="image"><i class="{{ settings['service-megamenu-icon1']
}}"></i></p>{% endif %}
<div class="text">
<h3>{{ settings['service-megamenu-title1'] }}</h3>
<p>{{ settings['service-megamenu-subtitle1'] }}</p>
</div>
</div>
<!-- End item -->
<div class="item">
{% if settings.service-megamenu-icon2 != blank %}<p
class="image"><i class="{{ settings['service-megamenu-icon2']
}}"></i></p>{% endif %}
<div class="text">
<h3>{{ settings['service-megamenu-title2'] }}</h3>
<p>{{ settings['service-megamenu-subtitle2'] }}</p>
</div>
</div>
<!-- End item -->
<div class="item">
{% if settings.service-megamenu-icon3 != blank %}<p
class="image"><i class="{{ settings['service-megamenu-icon3']
}}"></i></p>{% endif %}
<div class="text">
<h3>{{ settings['service-megamenu-title3'] }}</h3>
<p>{{ settings['service-megamenu-subtitle3'] }}</p>
</div>
</div>
<!-- End item -->
</div>
<ul class="menu-level-1">
{% for j in (1..3) %}
{% capture mega_title %}megamenu_{{ i }}_column_{{ j }}_title{%
endcapture %}
{% capture mega_col %}megamenu_{{ i }}_column_{{ j }}_menu{%
endcapture %}
<li class="level2"><h4>{{ settings[mega_title] }}</h4>
<ul class="menu-level-2">
{% for link in linklists[settings[mega_col]].links %}
<li class="level3"><a href="{{ link.url }}" title="{{
link.title }}">{{ link.title }}</a></li>
{% endfor %}
</ul>
</li>
{% endfor %}
{% capture _image1 %}megamenu_{{ i }}_image1.jpg{% endcapture %}
{% capture _image2 %}megamenu_{{ i }}_image2.jpg{% endcapture %}
<li class="level2">
<img src="{{ _image1 | asset_url }}" alt="Sub-Menu" />
</li>
<li class="level2">
<img src="{{ _image2 | asset_url }}" alt="Sub-Menu" />
</li>
</ul>
<div class="bottom-sub-menu">
<p>{{ settings['Megamenu-description'] }}</p>
</div>
</div>
{% endif %}
{% endfor %}
<!-- End Dropdow Menu -->
</li>
{% endfor %}
</ul>
</div>
</div>
</nav>
There will be a CSS class somewhere in the menu HTML which applies a CSS rule to color the active item. Across different e-commerce themes and platforms, this class is generally 'active', 'open', 'nav-open'. This class may be added via JavaScript after page load, so you may not see it in the HTML file.
I recommend using the inspect element tool to find the rule being applied to the item.

Jinja2 Child content not showing up

Thanks for the help!
So, I'm trying to create a simple layout with a Bootstrap nav-bar and a block of content on the body, and that works fine. But, when I extend that to a child, no matter what changes I make on the child, nothing shows up!
I'll post the two templates I'm using right now.
layout.html
<!doctype html>
{% extends "bootstrap/base.html" %}
<html>
<head>
<title>{% block title %}{% endblock %} </title>
</head>
<body>
{% block navbar %}
<nav class="navbar navbar-inverse navbar navbar-fixed-stop" role="navigation" style="border-radius:0px;">
<div class="container-fluid">
<div class="navbar-header"><a class="navbar-brand" href="#">BGP Monitor</a></div>
<ul class = "nav navbar-nav">
{% if g.user.is_authenticated %}
<li>Admin Panel</li>
{% endif %}
</ul>
<ul class="nav navbar-nav navbar-right">
{% if g.user.is_authenticated %}
<li><a href ="{{ url_for('logout') }}">Logout</li>
{% else %}
<li><a href ="{{ url_for('login') }}">Login</li>
{% endif %}
</ul>
</div>
</div>
</nav>
{% endblock %}
<div class="container-fluid" id="form">
{% block container %}{% endblock %}
</div>
</body>
</html>
And the child:
{% extends "layout.html" %}
<html>
<head></head>
<body>
<h3>aaa</h3>
{% block container %}
<div class="collapse navbar-collapse" id="container">
{{ super() }}
<form action="{{ url_for('login')}}" class="navbar-form navbar-right" method="POST">
{{ form.hidden_tag() }}
<div class="form-group">
{{ form.email(class="form-control", placeholder="Username") }}
</div>
<div class="form-group">
{{ form.password(class="form-control", placeholder="Password") }}
</div>
<div class="form-group">
<button class="btn btn-default" type="submit">Sign In</button>
</div>
</form>
</div>
</div>
{% endblock %}
</body>
The nav-bar shows, but the form doesn't show up, at all. It's as if the child does not exist.
Any ideas?
Thank you
P.S:
So, I changed to this:
layout.html
<!doctype html>
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<nav class="navbar navbar-inverse navbar navbar-fixed-stop" role="navigation" style="border-radius:0px;">
<div class="container-fluid">
<div class="navbar-header"><a class="navbar-brand" href="#">BGP Monitor</a></div>
<ul class = "nav navbar-nav">
{% if g.user.is_authenticated %}
<li>Admin Panel</li>
{% endif %}
</ul>
<ul class="nav navbar-nav navbar-right">
{% if g.user.is_authenticated %}
<li><a href ="{{ url_for('logout') }}">Logout</li>
{% else %}
<li><a href ="{{ url_for('login') }}">Login</li>
{% endif %}
</ul>
</div>
</div>
</nav>
<div class="container-fluid" id="container">
{% block container %}{% endblock %}
</div>
</body>
</html>
And this child:
{% extends "layout.html" %}
{% block container %}
<form action="{{ url_for('login')}}" class="navbar-form navbar-right" method="POST">
{{ form.hidden_tag() }}
<div class="form-group">
{{ form.email(class="form-control", placeholder="Username") }}
</div>
<div class="form-group">
{{ form.password(class="form-control", placeholder="Password") }}
</div>
<div class="form-group">
<button class="btn btn-default" type="submit">Sign In</button>
</div>
</form>
{% endblock %}
This way, there's no duplicate {% extend ... %}.
It now shows the form, but the WHOLE div is clickable, rendering it pretty much useless..
Any ideas?
You aren't supposed to have all the <html><head><body> tags in a child. It should just be:
{% extends "layout.html" %}
{% block container %}
<h3>aaa</h3>
<div class="collapse navbar-collapse" id="container">
{{ super() }}
<form action="{{ url_for('login')}}" class="navbar-form navbar-right" method="POST">
{{ form.hidden_tag() }}
<div class="form-group">
{{ form.email(class="form-control", placeholder="Username") }}
</div>
<div class="form-group">
{{ form.password(class="form-control", placeholder="Password") }}
</div>
<div class="form-group">
<button class="btn btn-default" type="submit">Sign In</button>
</div>
</form>
</div>
</div>
{% endblock %}
And notice how I moved the <h3>aaa</h3> code to inside the block.
Next, you can only have one {% extends ... %} call per rendering (You can't extend an extension). So, you need to consolidate your child to layout.html, making separate layouts per view.
Alternatively, you could change layout.html to use an include, keeping just one {% extends... %} per view:
layout.html
{% include "bootstrap/base.html" %}
{% block navbar %}
<nav class="navbar navbar-inverse navbar navbar-fixed-stop" role="navigation" style="border-radius:0px;">
<div class="container-fluid">
<div class="navbar-header"><a class="navbar-brand" href="#">BGP Monitor</a></div>
<ul class = "nav navbar-nav">
{% if g.user.is_authenticated %}
<li>Admin Panel</li>
{% endif %}
</ul>
<ul class="nav navbar-nav navbar-right">
{% if g.user.is_authenticated %}
<li><a href ="{{ url_for('logout') }}">Logout</li>
{% else %}
<li><a href ="{{ url_for('login') }}">Login</li>
{% endif %}
</ul>
</div>
</div>
</nav>
{% endblock %}
<div class="container-fluid" id="form">
{% block container %}{% endblock %}
</div>
Again, notice there are no duplicated <html> etc tags in layout.html. Those are already in bootstrap/base.html

Resources