Images Get Stretched on Circle Image - Bootstrap & SCSS - css

PLEASE HELP !!!
I am using bootstrap cards to make a section of my website.I am facing issue in circle image of the cards.I want my images do not get stretch when i put them in image circle of card.Is there a way i can zoom in middle of the image while showing it in circle or am i doing something wrong in my scss code ??
Here is the issue:
Expected Output:
Dimensions of these Images:
910x592 , 1230x802 , 1230x794
Bootstrap Code:
<section class="about-cards-section">
<div class="container">
<div class="row">
<div class="col-sm-4 card-wrapper">
<div class="card card-style" >
<img class="card-img-top rounded-circle circle-image" src="img/about/card-one.png" alt="Card image cap">
<!-- <img src="img/about/card-one.png" class="img-circle" alt="Cinque Terre" width="250" height="236"> -->
<div class="card-body">
<h3 class="card-title">Our Facilities</h3>
<p class="card-text">A short caption detailing an aspect of the brand which is worth mentioning.</p>
</div>
</div>
</div>
<div class="col-sm-4 card-wrapper">
<div class="card card-style">
<img class="card-img-top rounded-circle circle-image" src="img/about/card-two.png" alt="Card image cap">
<div class="card-body">
<h3 class="card-title">Our Research</h3>
<p class="card-text">A short caption detailing an aspect of the brand which is worth mentioning.</p>
</div>
</div>
</div>
<div class="col-sm-4 card-wrapper">
<div class="card card-style">
<img class="card-img-top rounded-circle circle-image" src="img/about/card-three.png" alt="Card image cap">
<div class="card-body">
<h3 class="card-title">Our Expertise</h3>
<p class="card-text">A short caption detailing an aspect of the brand which is worth mentioning.</p>
</div>
</div>
</div>
</div>
</div>
</section>
SCSS of the Cards Section:
.about-cards-section{
.card-wrapper{
margin: 5% 0;
.card-style{
text-align: center;
border-radius: initial;
border: initial;
.circle-image{
width: 60%;
height: 200px;
text-align: center;
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: 20px;
}
.card-title{
text-transform: uppercase;
letter-spacing: 1.1px;
}
.card-text{
font-family: MerriweatherRegular;
font-size: 22px;
line-height: initial;
}
}
}

The way I see it, you just need to adjust the width, height of .circle-image class and add object-fit: cover; property. But since you're using Bootstrap we can minimize your css using the pre-defined class in BS4
Example:
.card-wrapper {
margin: 5% 0;
}
/* You can adjust the image size by increasing/decreasing the width, height */
.custom-circle-image {
width: 20vw; /* note i used vw not px for better responsive */
height: 20vw;
}
.custom-circle-image img {
object-fit: cover;
}
.card-title {
letter-spacing: 1.1px;
}
.card-text {
font-family: MerriweatherRegular;
font-size: 22px;
line-height: initial;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<section class="about-cards-section">
<div class="container">
<div class="row">
<div class="col-sm-4 card-wrapper">
<div class="card border-0">
<div class="position-relative rounded-circle overflow-hidden mx-auto custom-circle-image">
<img class="w-100 h-100" src="https://source.unsplash.com/910x592" alt="Card image cap">
</div>
<div class="card-body text-center mt-4">
<h3 class="text-uppercase card-title">Our Facilities</h3>
<p class="card-text">A short caption detailing an aspect of the brand which is worth mentioning.</p>
</div>
</div>
</div>
<div class="col-sm-4 card-wrapper">
<div class="card border-0">
<div class="position-relative rounded-circle overflow-hidden mx-auto custom-circle-image">
<img class="w-100 h-100" src="https://source.unsplash.com/1230x802" alt="Card image cap">
</div>
<div class="card-body text-center mt-4">
<h3 class="text-uppercase card-title">Our Research</h3>
<p class="card-text">A short caption detailing an aspect of the brand which is worth mentioning.</p>
</div>
</div>
</div>
<div class="col-sm-4 card-wrapper">
<div class="card border-0">
<div class="position-relative rounded-circle overflow-hidden mx-auto custom-circle-image">
<img class="w-100 h-100" src="https://source.unsplash.com/1230x794" alt="Card image cap">
</div>
<div class="card-body text-center mt-4">
<h3 class="text-uppercase card-title">Our Expertise</h3>
<p class="card-text">A short caption detailing an aspect of the brand which is worth mentioning.</p>
</div>
</div>
</div>
</div>
</div>
</section>

Related

CSS vertically space even divs in IE 11

I was creating a layout which worked in the latest updated browsers (Firefox, Chrome, ...) and then opened the layout in IE 11 and saw a difference. My layout in IE looks like this:
But in every other tested browser the space on the right sided divs is evenly between them, which means that the third div stays on the bottom, while the second divs is right in the middle. I can't get it working in IE 11 and hoped that someone from here has a good advice.
https://jsfiddle.net/1gq2cj3f/2/
<article class="col-12 content-wrapper">
<div class="row content-wrapper-materials">
<div class="col-12 col-lg-6 materials-sectors">
<div class="card materials-sectors-general">
<div class="row no-gutters">
<div class="col-12">
<header class="card-header">
<div class="card-image">
<a href="...">
<img class="card-img-top" src="..." alt="" width="568px" height="430px">
</a>
</div>
<div class="card-img-overlay">
<h3 class="card-title">
Allgemein </h3>
</div>
</header>
</div>
</div>
</div>
</div>
<div class="col-12 col-lg-6 materials-sectors">
<div class="materials-sectors-specific">
<div class="card specific-construction">
<div class="row no-gutters">
<div class="col-12 col-sm-4">
<header class="card-header">
<div class="card-image">
<a href="...">
<img class="card-img-top" src="..." alt="" width="190px" height="117px">
</a>
<div class="card-img-overlay">
<h3 class="card-title">
Headline </h3>
</div>
</div>
</header>
</div>
<div class="col-12 col-sm-8">
<div class="card-body" itemprop="description">
<p class="card-text">
Text </p>
</div>
</div>
</div>
</div>
<div class="card specific-healthcare">
<div class="row no-gutters">
<div class="col-12 col-sm-4">
<header class="card-header">
<div class="card-image">
<a href="...">
<img class="card-img-top" src="..." alt="" width="190px" height="117px">
</a>
<div class="card-img-overlay">
<h3 class="card-title">
Headline </h3>
</div>
</div>
</header>
</div>
<div class="col-12 col-sm-8">
<div class="card-body" itemprop="description">
<p class="card-text">
Text </p>
</div>
</div>
</div>
</div>
<div class="card specific-ict">
<div class="row no-gutters">
<div class="col-12 col-sm-4">
<header class="card-header">
<div class="card-image">
<a href="...">
<img class="card-img-top" src="..." alt="" width="190px" height="117px">
</a>
<div class="card-img-overlay">
<h3 class="card-title">
Headline </h3>
</div>
</div>
</header>
</div>
<div class="col-12 col-sm-8">
<div class="card-body" itemprop="description">
<p class="card-text">
Text </p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</article>
.content-wrapper > div {
max-width: 1200px;
margin-right: auto;
margin-left: auto;
padding-top: 8rem;
padding-bottom: 8rem;
}
.card > * {
flex: 0 0 auto;
}
.materials-sectors .card-header {
height: 100%;
padding: 0;
border-bottom: 0;
background-color: rgba(242, 241, 241, 1) !important;
}
.materials-sectors .card-image {
height: 100%;
}
.materials-sectors .card-img-top {
-o-object-fit: cover;
object-fit: cover;
}
.materials-sectors-general .card-img-overlay {
bottom: 2rem;
padding: 0.75rem;
}
.materials-sectors .card-img-overlay {
background-color: rgba(255, 255, 255, 0.25);
top: auto;
}
.card-img-overlay > h3 {
font-size: 1rem;
margin-bottom: 0;
}
.materials-sectors-specific {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-flow: column;
flex-flow: column;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
}
.materials-sectors-specific > .card {
height: 100%;
}
.materials-sectors-specific .card-image {
display: block;
}
.materials-sectors-specific > div:nth-of-type(2) {
margin-top: 1rem;
margin-bottom: 1rem;
}

How to set image in same height using bootstrap?

I was trying to put same size of image for all card but some images has already small height then How can I fix that?
<div class="row">
<div class="col">
<div class="card h-100" style="width: 18rem;">
<img class="card-img-top" src="/assets/prewedding/pic1.jpg">
</div>
</div>
<div class="col">
<div class="card h-100" style="width: 18rem;">
<img class="card-img-top" src="/assets/prewedding/pic2.jpg">
</div>
</div>
</div>
You just need to set the img to cover the container, like
.card > img {
width: 100%;
height: 100%;
}

Bootstrap card-deck elements not getting the same proportions

I'm displaying card decks in order to show a set of articles stored in a database. This is the pretty simple piece of code I'm using:
HTML
<div class="row">
<div class="card-deck">
<template is="dom-repeat" items="{{articles}}" as="article">
<div class="col-12 col-md-4 mb-md-5">
<div
class="card"
on-tap="showViewer"
data-id$="[[article.id]]"
>
<img
class="card-img-top img-fluid vertical-image"
src$="{{getArticleImage(article)}}"
onerror$="this.src='{{defaultimage}}'"
alt="{{getArticleDescription(article)}}"
/>
<div class="card-body d-flex flex-column justify-content-center py-2">
<div class="d-flex justify-content-start align-items-center mb-2">
<img class="icon-sm mr-2 img-fluid" src={{getFavIcon(article)}}>
<span class="medium-text">
{{getSources(article)}}
</span>
</div>
<p class="card-text primary-headline medium-text">
{{article.schema:headline}}
</p>
</div>
</div>
</div>
</template>
</div>
</div>
CSS
.vertical-image {
width: 100%;
height: auto;
object-fit: cover;
object-position: center;
}
.icon-sm {
height: 20px;
width: auto;
}
.medium-text {
font-family: Raleway-Medium;
}
.primary-headline {
font-size: 25px;
line-height: 25px;
text-align: justify;
}
According to Bootstrap documentation, using the card-deck class should make all the cards in the deck to have equal width and height. However, I'm not acheiving that behaviour. Here you are a picture where you can see what I am getting.
What would be the correct way to achieve that all the images in the cards and all the cards have the same height and width?
Check this. Hope it helps.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-sm-4 py-2">
<div class="card card-body h-100">
Card. I'm just a simple card-block.
</div>
</div>
<div class="col-sm-4 py-2">
<div class="card h-100 text-white bg-danger">
<div class="card-body">
<h3 class="card-title">Danger</h3>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
Outline
</div>
</div>
</div>
<div class="col-sm-4 py-2">
<div class="card h-100 card-body">
Card. I'm just a simple card-block, but I have a little more text!
</div>
</div>
<div class="col-sm-4 py-2">
<div class="card h-100 border-primary">
<div class="card-body">
<h3 class="card-title">Primary</h3>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
Outline
</div>
</div>
</div>
<div class="col-sm-4 py-2">
<div class="card h-100 card-body">
Card. I'm just a simple card-block.
</div>
</div>
<div class="col-sm-4 py-2">
<div class="card text-white bg-primary">
<div class="card-body">
<h3 class="card-title">Hello</h3>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
Outline
</div>
</div>
</div>
</div>
</div>

How to remove the extra space around the image inside a div

I have images inside bootstrap card div which are inside col div
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-8 col-lg-8 B">
<div class="card card-inverse" style="background-color: #333; border-color: #333;">
<img class="img-fluid" src="http://lorempicsum.com/rio/800/500/4" alt="Responsive image">
</div>
</div>
<div class="col-md-4 col-lg-4 row">
<div class="col-md-6 col-lg-6 B">
<div class="card card-inverse" style="background-color: #333; border-color: #333;">
<img class="img-fluid" src="http://lorempicsum.com/rio/800/500/4" alt="Responsive image">
</div>
</div>
<div class="col-md-6 col-lg-6 B">
<div class="card card-inverse" style="background-color: #333; border-color: #333;">
<img class="img-fluid" src="http://lorempicsum.com/rio/800/500/4" alt="Responsive image">
</div>
</div>
<div class="col-md-12">
<div class="card card-inverse" style="background-color: #333; border-color: #333;">
<img class="img-fluid" src="http://lorempicsum.com/rio/800/500/3" alt="Responsive image">
</div>
</div>
</div>
</div>
</div>
I would like to have image on all col div space.
How could I achieve that ?
How could I extend image in order to fill the gap that I represent by a black line
As you describe you just want to consume all the space inside the col div (Left and Right blank space).
What you have to do is to reduce the default padding of bootstrap columns of padding-left: 15px; padding-right: 15px to 0px. And it will work for you.
Sometimes your styles get overloaded by the bootstrap styles. So in that case you have to use the keyword !important with your CSS property to overload all other CSS styles define for that particular property.
.zero-padding {
padding: 0px !important;
}
And to force the image to use all the space inside the col div you have to use the following CSS.
.fill-space {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.fill-space img {
flex-shrink: 0;
min-width: 100%;
min-height: 100%;
}
In order to force the images on the right side to take the 50% of height to the above 2 images and 50% of height to the image below; you should use the following CSS.
.half-height{
height: 50%;
}
OUTPUT:
Working Snippet below:
.zero-padding {
padding: 0px !important;
}
.fill-space {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.fill-space img {
flex-shrink: 0;
min-width: 100%;
min-height: 100%;
}
.half-height{
height: 50%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-8 col-lg-8 B">
<div class="card card-inverse" style="background-color: #333; border-color: #333;">
<img class="img-fluid" src="http://lorempicsum.com/rio/800/500/4" alt="Responsive image">
</div>
</div>
<div class="col-md-4 col-lg-4 row zero-padding">
<div class="col-md-6 col-lg-6 B zero-padding half-height">
<div class="card card-inverse fill-space" style="background-color: #333; border-color: #333;">
<img class="img-fluid" src="http://lorempicsum.com/rio/800/500/4" alt="Responsive image">
</div>
</div>
<div class="col-md-6 col-lg-6 B zero-padding half-height">
<div class="card card-inverse fill-space" style="background-color: #333; border-color: #333;">
<img class="img-fluid" src="http://lorempicsum.com/rio/800/500/4" alt="Responsive image">
</div>
</div>
<div class="col-md-12 zero-padding half-height">
<div class="card card-inverse fill-space" style="background-color: #333; border-color: #333;">
<img class="img-fluid" src="http://lorempicsum.com/rio/800/500/3" alt="Responsive image">
</div>
</div>
</div>
</div>
</div>
In the past, I've used a little javascript to achieve this. Making the image hidden but using it as a full background.
$(function() {
$('.full-image').each(function() {
var img = $(this).find('img');
$(this).css('background-image', 'url(' + img.attr('src') + ')');
img.css('visibility', 'hidden');
});
});
.full-image-wrapper {
position: relative;
border-radius: 3px;
overflow: hidden;
min-height: 120px !important;
}
.full-image {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-8 col-lg-8 B">
<div class="card card-inverse" style="background-color: #333; border-color: #333;">
<img class="img-fluid" src="http://lorempicsum.com/rio/800/500/4" alt="Responsive image">
</div>
</div>
<div class="col-md-4 col-lg-4 row">
<div class="col-md-6 col-lg-6 B full-image-wrapper">
<div class="full-image">
<img class="img-fluid" src="http://lorempicsum.com/rio/800/500/4" alt="Responsive image">
</div>
</div>
<div class="col-md-6 col-lg-6 B full-image-wrapper">
<div class="full-image">
<img class="img-fluid" src="http://lorempicsum.com/rio/800/500/4" alt="Responsive image">
</div>
</div>
<div class="col-md-12 full-image-wrapper">
<div class="full-image">
<img class="img-fluid" src="http://lorempicsum.com/rio/800/500/3" alt="Responsive image">
</div>
</div>
</div>
</div>
</div>
This will still work without JavaScript. You might need to do a bit more work to make mobile/tablet views optimal. I've had to force min-height to override bootstrap behaviour.

Creating responsive materialize cards

We're using materialize cards to display images on our site. The images are user uploaded, so they come in all different sizes (though they have to be greater than 250px).
We're able to maintain the aspect ratio of the images, which is great, but we don't know how to do that while making the cards on each row the same height. That's our goal- to get the cards to be the same height (in a responsive way) while maintaining the aspect ratio of the images inside the cards.
We've been messing with this all day without getting very far. Any help is much appreciated.
HTML:
<div class="row text-center">
<div class="col-xs-12 col-md-4 col-sm-12 test">
<div class="card" ui-sref='forsaleitem({type:"interior"})'>
<div class="card-header card-image waves-effect waves-block waves-light">
<img src="http://images.cdn.stuff.tv/sites/stuff.tv/files/Mercedes-AMG-GT-Interior-illuminated.jpg" class="img-rounded activator" alt="Cinque Terre">
</div>
<div class="card-content">
<h5 class='text-center'>Interior</h5>
</div>
</div>
</div>
<div class="col-xs-12 col-md-4 col-sm-12 test">
<div class="card" ui-sref='forsaleitem({type:"drivetrain"})'>
<div class="card-header card-image waves-effect waves-block waves-light">
<img src="http://www.revworksinc.com/assets/images/products/subaru/exedy/exedy_brz_twindisc.jpg" class="img-rounded activator" alt="Cinque Terre">
</div>
<div class="card-content">
<h5 class='text-center'>Drivetrain</h5>
</div>
</div>
</div>
<div class="col-xs-12 col-md-4 col-sm-12 test">
<div class="card" ui-sref='forsaleitem({type:"performance"})'>
<div class="card-header card-image waves-effect waves-block waves-light">
<img src="http://www.autonotas.tv/wp-content/uploads/2015/05/SHW_0323-1024x603.jpg" alt="Cinque Terre">
</div>
<div class="card-content">
<h5 class='text-center'>Performance</h5>
</div>
</div>
</div>
</div>
CSS:
.card {
position: relative;
background-color: #f4f4f4;
// margin: 10px auto;
height: 100%;
box-shadow: 1px 1px 10px 1px rgba(0, 0, 0, 0.7);
}
.card {
height: 100%;
}
.card .card-image img {
//object-fit: contain !important;
}
Use Media Queries to set the width/height depending on the size of the screen. Example in JS Fiddle: https://jsfiddle.net/3yegzwex/
HTML:
<div class="row text-center">
<div class="col-xs-12 col-md-4 col-sm-12">
<div class="card" ui-sref='forsaleitem({type:"interior"})'>
<div class="card-header card-image waves-effect waves-block waves-light">
<img src="http://images.cdn.stuff.tv/sites/stuff.tv/files/Mercedes-AMG-GT-Interior-illuminated.jpg" class="img-rounded activator resizeimg" alt="Cinque Terre" height="226">
</div>
<div class="card-content">
<h5 class='text-center'>Interior</h5>
</div>
</div>
</div>
<div class="col-xs-12 col-md-4 col-sm-12">
<div class="card" ui-sref='forsaleitem({type:"drivetrain"})'>
<div class="card-header card-image waves-effect waves-block waves-light">
<img src="http://www.revworksinc.com/assets/images/products/subaru/exedy/exedy_brz_twindisc.jpg" class="img-rounded activator resizeimg" alt="Cinque Terre" height="226">
</div>
<div class="card-content">
<h5 class='text-center'>Drivetrain</h5>
</div>
</div>
</div>
<div class="col-xs-12 col-md-4 col-sm-12">
<div class="card" ui-sref='forsaleitem({type:"performance"})'>
<div class="card-header card-image waves-effect waves-block waves-light">
<img src="http://www.autonotas.tv/wp-content/uploads/2015/05/SHW_0323-1024x603.jpg" class="img-rounded activator resizeimg" alt="Cinque Terre" height="226">
</div>
<div class="card-content">
<h5 class='text-center'>Performance</h5>
</div>
</div>
</div>
</div>
CSS:
.card {
text-align: center;
}
#media (max-width: 990px) {
.resizeimg {
height: auto;
}
}
#media (min-width: 1000px) {
.resizeimg {
width: auto;
height: 350px;
}
}
Do the images really have to be inline? Or can they be set as background-image (since they are user uploaded)? If so, you can set the background-size property to cover to address the problem. Also because object-fit is not widely supported (yet).
cover
A keyword that is the inverse of contain. Scales the image as large as possible and maintains image aspect ratio (image doesn't
get squished). The image "covers" the entire width or height of the
container. When the image and container have different dimensions, the
image is clipped either left/right or top/bottom.
Source: MDN
See this updated JSFiddle for the demo. The padding-bottom can be altered to a percentage for your needs. Try to change it and see what it does.
Inline images
If the images do have to be inline, you can apply this solution:
.card-image {
width: 100%;
padding-bottom: 50%;
overflow: hidden;
position: relative;
}
.card-image img {
width: 100%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
The image will be pushed inside the .card-image and stretched to its width that's needed. See this JSFiddle for the demo. The padding-bottom can be altered to a percentage to your needs.

Resources