How to make columns not dependent on each other with Bootstrap? - html

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

Related

how to display <div> next to each other within a for loop?(laravel)

I'm working on a alumni portal where I need to display the committee member details. I need to print like 4 members in a line and next 4 in the next line. Any solution would be helpful.
<h2>Member Details</h2>
<div class="jumbotron container">
<div class="pull-right">
<a class="btn btn-primary" data-toggle="modal" id="mediumButton" data-target="#mediumModal" data-attr="{{ route('add_details')}}" title="Add Institute Details"> <i class="fas fa-plus-circle"></i>
</a>
</div>
<div class="container main" id="wrapper">
#foreach ($members as $member)
<div class="img-box">
<pre>
<img src="/uploads/image/{{ $member->image }}" width="100" height="100"/>
{{ $member->id }}<br/>
<a> {{ $member->name }}</a>
<!-- #if(($member->id) >=5 )
<span style="white-space: pre-line">
</span>
#endif
</pre> -->
</div>
#endforeach
</div>
</div>
if you use Bootstrap try this
<div class="row">
#foreach ($members as $member)
<div class="col-md-3">
<div class="img-box">
<pre>
<img src="/uploads/image/{{ $member->image }}" width="100" height="100"/>
{{ $member->id }}<br/>
<a> {{ $member->name }}</a>
</pre>
</div>
</div>
#endforeach
</div>
Add "display:grid;" to the container "div" tag You need to define the property.

4 products on the same line in the template

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>

Bootstrapping with card and for loop

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.

Displaying items horizontally instead of columns

I need to make an index view for my posts, and I choose a photo gallery for that.In my controller I have paginate set at 10.Unfortunately, my column is divided by one, horizontally : https://imgur.com/a/8sUm5eb .
I want to make this to be divided by 2 columns, 5 items/column.Can you give me a little help with that?Thank you.
My view
<!-- Promo Block -->
<div class="container g-pt-100 g-pb-70">
<!-- News Section -->
<div class="u-heading-v3-1 g-mb-30">
<h2 class="h5 u-heading-v3__title g-color-gray-dark-v1 text-uppercase g-brd-primary">Latest News</h2>
</div>
#foreach($posts as $post)
<div class="masonry-grid-item col-sm-6 g-mb-30">
<!-- Blog Background Overlay Blocks -->
<article class="u-block-hover">
<div class="g-bg-cover g-bg-white-gradient-opacity-v1--after">
<img class="d-flex align-items-end u-block-hover__main--mover-down" src="/storage/{{ $post->image }}" alt="Image Description">
</div>
<div class="u-block-hover__additional--partially-slide-up text-center g-z-index-1 mt-auto">
<div class="u-block-hover__visible g-pa-25">
#foreach($post->tags as $tag)
<span class="g-color-white-opacity-0_7 g-font-size-10 text-uppercase">{{ $tag->name }}</span>
<span class="g-color-white-opacity-0_7 g-pos-rel g-top-2 mx-2">·</span>
#endforeach
<h2 class="h4 g-color-white g-font-weight-600 mb-3">
<a class="u-link-v5 g-color-white g-color-primary--hover g-cursor-pointer" href="/post/{{ $post->id }}">{{ $post->caption }}</a>
</h2>
<h4 class="d-inline-block g-color-white-opacity-0_7 g-font-size-11 mb-0">
By,
<a class="g-color-white-opacity-0_7 text-uppercase" href="/post/{{ $post->id }}">{{ $post->user->username }}</a>
</h4>
<span class="g-color-white-opacity-0_7 g-pos-rel g-top-2 mx-2">·</span>
<span class="g-color-white-opacity-0_7 g-font-size-10 text-uppercase">{{ $post->created_at->diffForHumans() }}</span>
<span class="g-color-white-opacity-0_7 g-pos-rel g-top-2 mx-2">·</span>
<span class="g-color-white-opacity-0_7 g-font-size-10 text-uppercase">{{ $post->comments()->count() }} comments</span>
</div>
<a class="d-inline-block g-brd-bottom g-brd-white g-color-white g-font-weight-600 g-font-size-12 text-uppercase g-text-underline--none--hover g-mb-30" href="/post/{{ $post->id }}">Read more</a>
</div>
</article>
<!-- End Blog Background Overlay Blocks -->
</div>
#endforeach
</div>
</div>
<!-- End News Section -->
Make your first foreach like this
<div class="row">
Your foreach
</div>

silex loop one sql statement over another one

I have to get team members by their groups from a database.
My Database looks like:
table team_groups:
id
name
table team_member:
id
name
description
imagepath
team_group_id
I have an twig template where the team_members are shown by there groups like this:
<div class="row row-centered">
<h3 class="text-center">{{team_group.name}}</h3>
<div class="col-xs-6 col-centered col-fixed">
<div class="item">
<div class="team-member text-center">
<span><img class="img-team" src="{{ app.request.basepath }}/img/team/{{team_member.imagepath}}"
alt="{{team_member.name}}"></span>
<h3>{{team_member.name}}</h3>
<p>{{team_member.description}}</p>
</div>
</div>
</div>
<div class="col-xs-6 col-centered col-fixed">
<div class="item">
<div class="team-member text-center">
<span><img class="img-team" src="{{ app.request.basepath }}/img/team/{{team_member.imagepath}}"
alt="{{team_member.name}}"></span>
<h3>{{team_member.name}}</h3>
<p>{{team_member.description}}</p>
</div>
</div>
</div>
<div class="col-xs-6 col-centered col-fixed">
<div class="item">
<div class="team-member text-center">
<span><img class="img-team" src="{{ app.request.basepath }}/img/team/{{team_member.imagepath}}"
alt="{{team_member.name}}"></span>
<h3>{{team_member.name}}</h3>
<p>{{team_member.description}}</p>
</div>
</div>
</div>
</div>
But I don't know how to loop the team_members over the team_groups in my controller.
I started like that:
$teamGroups = $app['db']->fetchAll('SELECT * team_groups');
$teamMembers = $app['db']->fetchAll('SELECT * team_members');
but don't know how to continue.
Please help
Oh yeah twig is really nice...
I thought I have to link the objects in the controller, but now I simply wrote:
{% for teamGroup in teamGroups %}
<div class="row row-centered">
<h3 class="text-center">{{ teamGroup.name }}</h3>
{% for teamMember in teamMembers %}
{% if teamMember.team_group_id is same as(teamGroup.id) %}
<div class="col-xs-6 col-centered col-fixed">
<div class="item">
<div class="team-member text-center">
<span><img class="img-team" src="{{ app.request.basepath }}/img/team/{{ teamMember.image }}"
alt="{{ teamMember.name }}"></span>
<h3>{{ teamMember.name }}</h3>
<p>{{ teamMember.description }}</p>
</div>
</div>
</div>
{% endif %}
{% endfor %}
</div>
{% endfor %}
That did it for me :-)