Just trying to pick up Vue.js so please be gentle :smiley:
The issue I’m facing is that when i’m binding elements separately on two different columns it everything works, but it messes up my layout. All images load on first row and articles are rendered below.
the code =>
```<div class="row no-gutters"> <!-- remove horizontal paddings between columns 4 this row -->
<div class="col-md-2" v-for="(post, img) in posts">
<div class="article-image">
<img :src="post.img" />
</div>
</div>
<div class="col-md-6" v-for="(post, title) in posts" v-bind="post.id">
<div class="article">
<div class="card">
<div class="card-body">
<h3 class="card-title">{{ post.title }}</h3>
<h6 class="card-subtitle text-muted">21st Dec 17</h6>
<p class="card-text">{{ post.content }}</p>
</div>
</div>
</div>
</div>```
So, I decided to put the v-for on the row class instead and have it loop through image and article one after another, rather than loading all images first and then all the articles.
the code =>
```<div class="row no-gutters" v-for="(post, img, title) in posts" v-bind="post.id">
<div class="col-md-2" v-for="(post, img) in posts">
<div class="article-image">
<img :src="post.img">
</div>
</div>
<div class="col-md-6" >
<div class="article">
<div class="card">
<div class="card-body">
<h3 class="card-title">{{ post.title }}</h3>
<h6 class="card-subtitle text-muted">21st Dec 17</h6>
<p class="card-text">{{ post.content }}</p>
</div>
</div>
</div>
</div>```
I’m not sure if I’m failing at declaring it properly, but I’m getting the following error =>
(source: vuejs.org)
Any help would be much appreciated.
Wrap your template in a div
<div>
<div class="col-md-2" v-for="(post, img) in posts">
<div class="article-image">
<img :src="post.img" />
</div>
</div>
<div class="col-md-6" v-for="(post, title) in posts" v-bind="post.id">
<div class="article">
<div class="card">
<div class="card-body">
<h3 class="card-title">{{ post.title }}</h3>
<h6 class="card-subtitle text-muted">21st Dec 17</h6>
<p class="card-text">{{ post.content }}</p>
</div>
</div>
</div>
</div>
</div>
Why?
You can only have one root element in your template; v-for makes multiple.
Thats the final template that worked for me...
<div>
<div class="row no-gutters" v-for="(post, img, title) in posts" v-bind="post.id"> <!-- remove horizontal paddings between columns 4 this row -->
<div class="col-md-2">
<div class="article-image">
<img :src="post.img" />
</div>
</div>
<div class="col-md-6">
<div class="article">
<div class="card">
<div class="card-body">
<h3 class="card-title">{{ post.title }}</h3>
<h6 class="card-subtitle text-muted">21st Dec 17</h6>
<p class="card-text">{{ post.content }}</p>
</div>
</div>
</div>
</div>
</div>
Related
how can I fix these cards so that they are the same size and width?
Because if I add more text to a product on a card, the body goes lower, but the edges of the card remain the same.
I would like the body to be aligned regardless of content
It's possible?
<div class="card-body">
<div class="product-name col-12 no-padding">
<a
class="unset"
:title="product.name"
:href="`${baseUrl}/${product.slug}`">
<span class="fs16">{{ product.name.substring(0,20) }} <br> {{ product.name.substring(21,40) }} <br> {{ product.name.substring(41,60) }} <br> {{ product.name.substring(61,81) }} </span>
</a>
</div>
<div class="sticker new" v-if="product.new">
{{ product.new }}
</div>
<div class="product-price fs16" v-html="product.priceHTML"></div>
<div
class="product-rating col-12 no-padding"
v-if="product.totalReviews && product.totalReviews > 0">
<star-ratings :ratings="product.avgRating"></star-ratings>
<a class="fs14 align-top unset active-hover" :href="`${$root.baseUrl}/reviews/${product.slug}`">
{{ __('products.reviews-count', {'totalReviews': product.totalReviews}) }}
</a>
</div>
<div class="product-rating col-12 no-padding" v-else>
<span class="fs14" v-text="product.firstReviewText"></span>
</div>
<vnode-injector :nodes="getDynamicHTML(product.addToCartHtml)"></vnode-injector>
</div>
</div>
I am presenting a case with pure CSS + HTML. The idea is that you can see how to format the cards so that the bodies are the same size.
HTML
<div class="container">
<!-- Page Features -->
<div class="row text-center">
<div class="col-lg-4 col-md-6 mb-4">
<div class="card h-100">
<img class="card-img-top" src="https://dummyimage.com/600x400/000/fff&text=1" >
<div class="card-body">
<h4 class="card-title">card 1</h4>
<p class="card-text">product1 </p>
<p class="card-text">product1 </p>
<p class="card-text">product1 </p>
</div>
<div class="card-footer">
+info
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card h-100">
<img class="card-img-top" src="https://dummyimage.com/600x400/000/fff&text=2" >
<div class="card-body">
<h4 class="card-title">card 1</h4>
<p class="card-text">product1 </p>
<p class="card-text">product1 </p>
<p class="card-text">product1 </p>
<p class="card-text">product1 </p>
<p class="card-text">product1 </p>
</div>
<div class="card-footer">
+info
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card h-100">
<img class="card-img-top" src="https://dummyimage.com/600x400/000/fff&text=3" >
<div class="card-body">
<h4 class="card-title">card 1</h4>
<p class="card-text">product1 </p>
<p class="card-text">product1 </p>
<p class="card-text">product1 </p>
<p class="card-text">product1 </p>
<p class="card-text">product1 </p>
<p class="card-text">product1 </p>
<p class="card-text">product1 </p>
</div>
<div class="card-footer">
+info
</div>
</div>
</div>
</div>
</div>
run # codeply
The key class is h-100 # card tag.
Good luck!
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>
I have problem with my columns in bootstrap, right now they appear vertically, one above the other.
I need to show to the left
Code:
<div class="col-xl-4 col-lg-6 col-md-6 col-sm-12 col-12 layout-spacing">
<div class="widget widget-card-two">
<div class="widget-content">
<div class="media">
<div class="w-img">
<img src="assets/img/90x90.jpg" alt="avatar">
</div>
<div class="media-body">
<h6>{{ $tracking->order->shipping_address }}</h6>
<p class="meta-date-time">{{ $tracking->order->user->name }}</p>
</div>
</div>
<div class="card-bottom-section">
<h5>{{ $tracking->order->shipping_method }}</h5>
<div class="img-group">
<a style="text-decoration: none; background-color: #ffffff;" href="https://api.whatsapp.com/send?phone={{$tracking->order->user->telefono}}&text=Hola" target="_blank"> <img src="https://i.imgur.com/C5L19Q8.png" alt="avatar"> </a>
</div>
Ver Pedido N° {{ $tracking->order->id }}
</div>
</div>
</div>
</div>
help pls
Just add a row class, as shown below:
<div class="container">
<div class="row">
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
</div>
</div>
Please refer the docs for more info: https://getbootstrap.com/docs/4.0/layout/grid/
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>
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 %}