Bootstrap Card images are not contained perfectly around corners - html

I'm trying to build a portfolio with bootstrap cards where images are also required to be displayed.
Problem is that images are not contained properly within bootstrap card around corners(with class="card-img-top") like some cards are not rounded or some images are not rounded but cards are rounded(tried class="img-rounded").
Kindly zoom in on the images to see the difference. Below are some snippets (and code is given below the snippets):-
Perfect card with image:-
Yellow-> difference
Bug-1:-
Bug-2:-
Bug-3:-
Bug-4:-
Code:-
<%- include('partials/headHTML') %>
<link rel="stylesheet" href="/css/tourpackageStyles.css">
</head>
<!-- <%- include('partials/header') %> -->
<div class="Container">
<div class="container-fluid">
<div class="row">
<div class="col col-md-4">
<div class="card h-100">
<img src="https://cdn.pixabay.com/photo/2022/06/05/20/24/rome-7244828_960_720.jpg" alt="" class="card-img-top">
<div class="card-body">
<div class="card-title">Title-1</div>
</div>
<a target="_blank" rel="noopener noreffer" href="#" role="button"
class="btn btn-sm btn-secondary">Enquire</a>
</div>
</div>
<div class="col col-md-4">
<div class="card h-100">
<img src="/images/wildlife/wildlife_tour.jpg"
alt=""
class="card-img-top">
<div class="card-body">
<div class="card-title">Title- 2</div>
</div>
<a target="_blank" rel="noopener noreffer" href="#"
class="btn btn-sm btn-secondary">Enquire</a>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row row-cols-1 row-cols-md-3 row-cols-sm-2 gy-3">
<div class="col">
<div class="card h-100">
<img src="https://cdn.pixabay.com/photo/2022/06/05/20/24/rome-7244828_960_720.jpg" alt="" class="card-img-top">
<div class="card-body">
<div class="card-title">
Title- 3
</div>
</div>
</div>
</div>
<div class="col">
<div class="card h-100">
<img src="https://cdn.pixabay.com/photo/2022/06/05/20/24/rome-7244828_960_720.jpg" alt="" class="card-img-top">
<div class="card-body">
<div class="card-title">
Title- 4
</div>
</div>
</div>
</div>
<div class="col">
<div class="card h-100">
<img src="https://cdn.pixabay.com/photo/2022/06/05/20/24/rome-7244828_960_720.jpg" alt="" class="card-img-top">
<div class="card-body">
<div class="card-title">
Title- 5
</div>
</div>
</div>
</div>
<div class="col">
<div class="card h-100">
<img src="" alt="">
<div class="card-body">
<div class="card-title">
Title- 6
</div>
</div>
</div>
</div>
<div class="col">
<div class="card h-100">
<img src="" alt="">
<div class="card-body">
<div class="card-title">
Title- 7
</div>
</div>
</div>
</div>
<div class="col">
<div class="card h-100">
<img src="" alt="">
<div class="card-body">
<div class="card-title">
Title- 8
</div>
</div>
</div>
</div>
</div>
</div>
</div>

If you wish to display only image while using card then place image inside card-body to achieve what you want and give card class "overflow-hidden". Because if you use "card-img-top" and then it has only border-top-left-radius and border-top-right-radius so image wouldn't be rounded on bottom.so you have to provide border-radius manually to both bottom side.
<div class="card overflow-hidden">
<div class="card-body">
<img class="img-fluid" src="" alt="">
</div>
</div>
For more information refer official docs https://getbootstrap.com/docs/5.2/components/card/

Related

Can't create a bootstrap nested grid system

I'm having troubles trying to create a grid layout like this
Grid layout
what i assumed was to create a row and have 2 columns divided, and create a row+col inside each of the 2 columns and in each col have a card.
this is my code
<div class="container">
<div class="row">
<div class="col-8">
Modules
<div class="module-container">
<div class="row">
<div class="col-3">
<div class="card">
<img src="/images/pat.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
<div class="col-3">
<div class="card">
<img src="/images/pat.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
<div class="col-3">
<div class="card">
<img src="/images/pat.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
<div class="row">
<div class="col-3">
<div class="card">
<img src="/images/pat.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
<div class="col-3">
<div class="card">
<img src="/images/pat.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
<div class="col-3">
<div class="card">
<img src="/images/pat.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
<div class="col-4">
Schedule
<div class="row">
<div class="col-6">
<div class="card">
<img src="/images/star.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
<div class="col-6">
<div class="card">
<img src="/images/star.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
</div>
and this is what came out
my layout
I dont understand why the cards in my second row aren't the same length too?
first you need to add outer row and add 2 columns and then inside first column add row then give your columns col-3, col-4 how much you want in a row same goes to second column. I hope down script help you
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<div class="container">
<div class="row">
<!-- outer grid first column -->
<div class="col-8">
Modules
<div class="module-container">
<!-- first column inner grid -->
<div class="row">
<div class="col-4">
<div class="card">
<img src="/images/pat.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
<div class="col-4">
<div class="card">
<img src="/images/pat.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
<div class="col-4">
<div class="card">
<img src="/images/pat.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
<div class="col-4 mt-2">
<div class="card">
<img src="/images/pat.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
<div class="col-4 mt-2">
<div class="card">
<img src="/images/pat.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
<div class="col-4 mt-2">
<div class="card">
<img src="/images/pat.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
</div>
</div>
</div>
<!-- outer grid second column -->
<div class="col-4">
Schedule
<!-- second column inner grid -->
<div class="row">
<div class="col-6">
<div class="card">
<img src="/images/star.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
<div class="col-6">
<div class="card">
<img src="/images/star.jpg" class="card-img-top" alt="module 1">
<div class="card-body">
title
</div>
</div>
</div>
</div>
</div>
</div>
</div>

Bootstrap Gridsystem col is not Working Properly

Here is my code:
I've tried change container class to container-fluid also resize the page.
<div class="container">
<div class="row">
<!--Product: banana split-->
<div class="col">
<div class="card" style="width: 20rem;">
<img class="card-img-top" src="img/banana-split.png" alt="Banana Split Image">
<div class="card-block">
<h4 class="card-title">Banana Split</h4>
<p class="card-text">Price: 5$</p>
<i class="fas fa-shopping-cart"></i> Add to Cart
</div>
</div>
</div>
<div class="col">
<div class="card" style="width: 20rem;">
<img class="card-img-top" src="img/bengala-doce.png" alt="Bengala Doce Image">
<div class="card-block">
<h4 class="card-title">Doce Natalino</h4>
<p class="card-text">Price: 2$</p>
<i class="fas fa-shopping-cart"></i> Add to Cart
</div>
</div>
</div>
</div>
</div>
The problem is the second col is not being placed side by side. It's being placed below each other.
I looked up on the console and there's not any warning.
Others stuff like bootstrap buttons is working fine.
You forgot to set your column classes depending on screen sizes you are viewing. This way, making 2 columns on mediums screen sizes, and on column in small screens using col-md-6 col-sm-12
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<div class="container">
<div class="row">
<!--Product: banana split-->
<div class="col-md-6 col-sm-12">
<div class="card" style="width: 20rem;">
<img class="card-img-top" src="img/banana-split.png" alt="Banana Split Image">
<div class="card-block">
<h4 class="card-title">Banana Split</h4>
<p class="card-text">Price: 5$</p>
<i class="fas fa-shopping-cart"></i> Add to Cart
</div>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="card" style="width: 20rem;">
<img class="card-img-top" src="img/bengala-doce.png" alt="Bengala Doce Image">
<div class="card-block">
<h4 class="card-title">Doce Natalino</h4>
<p class="card-text">Price: 2$</p>
<i class="fas fa-shopping-cart"></i> Add to Cart
</div>
</div>
</div>
</div>
</div>

How to align these 2 divs vertically with the given html (need them to start at same vertical level)

<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="news-title">
<h3 class="title">NEWS & ARTICLES</h3>
</div>
</div></div>
<div class="row row-cols-1 row-cols-md-3 g-4" style="justify-content: center;margin-top: 25px;">
<div class="col resize-card">
<div class="card-img-wrap h-100">
<img src="SiteAssets/assets/igomd/images/news-1.png" class="card-img-top" alt="...">
<div class="card-body">
<h4 class="card-title">KIOSK</h4>
</div>
</div>
</div>
<div class="col resize-card">
<div class="card-img-wrap h-100">
<img src="SiteAssets/assets/igomd/images/news-2.png" class="card-img-top" alt="...">
<div class="card-body">
<h4 class="card-title">LOREM</h4>
</div>
</div>
</div>
<div class="col resize-card">
<div class="card-img-wrap h-100">
<img src="SiteAssets/assets/igomd/images/news-3.png" class="card-img-top" alt="...">
<div class="card-body">
<h4 class="card-title">IPSUM</h4>
</div>
</div>
</div>
</div>
</div>
Basicly i need to align NEWS & ARTICLES and the Cards below vertically. So they have to start at the same vertical level. I could not manage to find a css solution for this.
I think that the div with the (class="row row-cols-1 row-cols-md-3 g-4" style="justify-content: center;margin-top: 25px;) properties are preventing the title and Cards to start at the same vertical level.
I made a crop and paste picture to show you what i need to accomplish you guys.
Here is the photo of what i need to do.
What can i do to accomplish this below with that given html?
This is working fine in my case maybe there is some CSS conflicts in your code.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="news-title">
<h3 class="title">NEWS & ARTICLES</h3>
</div>
</div></div>
<div class="row row-cols-1 row-cols-md-3 g-4" style="justify-content: center;margin-top: 25px;">
<div class="col resize-card">
<div class="card-img-wrap h-100">
<img src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h4 class="card-title">KIOSK</h4>
</div>
</div>
</div>
<div class="col resize-card">
<div class="card-img-wrap h-100">
<img src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h4 class="card-title">LOREM</h4>
</div>
</div>
</div>
<div class="col resize-card">
<div class="card-img-wrap h-100">
<img src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h4 class="card-title">IPSUM</h4>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

How to center last two cards in bootstrap?

I write application in angular, using bootstrap. I want the last 2 cards to be in the middle, instead of to the left. Now it looks like one last card is missing. I want to correct it. How to do it?
html code:
<div class="container" style="padding-top:1.1cm">
<div class="card-columns">
<div class="card text-center" [routerLink]="['/special/arrangements-salon']">
<div class="card-body">
<img [src]="salon" height="100" width="100"><br><label>
<h5 style="padding-top:6mm">salon</h5>
</label>
</div>
</div>
<div class="card text-center" [routerLink]="['/special/arrangements-study']">
<div class="card-body">
<img [src]="study" height="100" width="100"><br><label>
<h5 style="padding-top:6mm">gabinet</h5>
</label>
</div>
</div>
<div class="card text-center" [routerLink]="['/special/arrangements-bedroom']">
<div class="card-body">
<img [src]="bedroom" height="100" width="100"> <br><label>
<h5 style="padding-top:6mm">sypialnia
</h5>
</label>
</div>
</div>
<div class="card text-center" [routerLink]="['/special/arrangements-kitchen']">
<div class="card-body">
<img [src]="kitchen" height="100" width="100"> <br><label>
<h5 style="padding-top:6mm">kuchnia
</h5>
</label>
</div>
</div>
<div class="card text-center" [routerLink]="['/special/arrangements-bathroom']">
<div class="card-body">
<img [src]="bathroom" height="100" width="100"><br><label>
<h5 style="padding-top:6mm">Ĺ‚azienka</h5>
</label>
</div>
</div>
</div>
</div>
add d-flex align-items-center justify-content-center to parent => card-columns div or you can add mx-auto to last div
<div class="container" style="padding-top:1.1cm">
<div class="card-columns d-flex align-items-center justify-content-center">
<div class="card text-center" [routerLink]="['/special/arrangements-salon']">
<div class="card-body">
<img [src]="salon" height="100" width="100"><br><label>
<h5 style="padding-top:6mm">salon</h5>
</label>
</div>
</div>
<div class="card text-center" [routerLink]="['/special/arrangements-study']">
<div class="card-body">
<img [src]="study" height="100" width="100"><br><label>
<h5 style="padding-top:6mm">gabinet</h5>
</label>
</div>
</div>
<div class="card text-center" [routerLink]="['/special/arrangements-bedroom']">
<div class="card-body">
<img [src]="bedroom" height="100" width="100"> <br><label>
<h5 style="padding-top:6mm">sypialnia
</h5>
</label>
</div>
</div>
<div class="card text-center" [routerLink]="['/special/arrangements-kitchen']">
<div class="card-body">
<img [src]="kitchen" height="100" width="100"> <br><label>
<h5 style="padding-top:6mm">kuchnia
</h5>
</label>
</div>
</div>
<div class="card text-center" [routerLink]="['/special/arrangements-bathroom']">
<div class="card-body">
<img [src]="bathroom" height="100" width="100"><br><label>
<h5 style="padding-top:6mm">Ĺ‚azienka</h5>
</label>
</div>
</div>
</div>
</div>
Bootstrap card-columns uses CSS multi columns and for various reason it's not really possible to center items, or align rows differently.
Instead of using card-columns, use the grid (row > col-*), but you should note this won't give you a masonry layout or top-to-bottom ordering.

Create grid with bootstrap card component

I'm trying to create a grid using the Bootstrap 4 card component. For this, I have read the documentation and used the card-deck option. I want that every row has two columns with a similar behaviour to col-12 col-md-6, with the particularity that the second column will also be splited into two rows, each one having an horizontal card. I have this piece of code:
<div class="container">
<div class="row">
<div class="card-deck">
<div class="card">
<img
class="card-img-top"
src$="{{getArticleImage2(article1)}}"
/>
<div class="card-body py-2">
<div class="d-flex justify-content-start align-items-center mb-2">
<img class="icon-sm mr-2 img-fluid" src={{getFavIcon(article1)}}>
<a class="card-link medium-text" target="_blank" href$="https://{{getSources(article1)}}">
{{getSources(article1)}}
</a>
</div>
<p class="card-text article-headline medium-text">
{{article1.schema:headline}}
</p>
</div>
</div>
<div class="card">
<div class="row no-gutters">
<div class="col-md-5">
<img
class="card-img"
src$="{{getArticleImage2(article2)}}"
/>
</div>
<div class="col-md-7">
<div class="card-body p-2">
<div class="d-flex justify-content-start align-items-center mb-2">
<img class="icon-sm mr-2 img-fluid" src={{getFavIcon(article2)}}>
<a class="card-link medium-text" target="_blank" href$="https://{{getSources(article2)}}">
{{getSources(article2)}}
</a>
</div>
<p class="card-text article-headline medium-text">
{{article2.schema:headline}}
</p>
</div>
</div>
</div>
</div>
<div class="card">
<div class="row no-gutters">
<div class="col-md-5">
<img
class="card-img"
src$="{{getArticleImage2(article2)}}"
/>
</div>
<div class="col-md-7">
<div class="card-body p-2">
<div class="d-flex justify-content-start align-items-center mb-2">
<img class="icon-sm mr-2 img-fluid" src={{getFavIcon(article3)}}>
<a class="card-link medium-text" target="_blank" href$="https://{{getSources(article3)}}">
{{getSources(article3)}}
</a>
</div>
<p class="card-text article-headline medium-text">
{{article3.schema:headline}}
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
The problem is that with this disposition I have three cols instead of two. The last two cards are displayed horizontally, but they are not stacked one below the other. Here is a code snippet. How could I achieve this?
if you added a div with class card-columns like that:
<div class="card-deck">
<div class="card-columns">
<div class="card">
<img
class="card-img-top"
src=""
/>
<div class="card-body py-2">
//.................
it will give you two cloumns one with a card displayed vertically and the other contains two horizontal cards.
Also read the last section of the documentation maybe it will be helpful for you to specify how many cards included in one column
https://getbootstrap.com/docs/4.3/components/card/