The image on the card is barely visible due to the applied Bootstrap 4 styles

When uploading an image with a greater height and narrower width, it may appear distorted in the user cards on the website. Below are the HTML and CSS components used in our Angular framework:

HTML

<div class="container-fluid" >
  <div class="row people-row">
    <div class="col-12 row">
      <div class="m1-* col-md-3 text-center" *ngFor="let user of filteredUsers | filter: searchByKeyword: 'name' | paginate: { itemsPerPage: 12, currentPage: p }">
        <div class="card card-person">
          <a  (click)="ViewUser(user)">
            <img class="card-img-top" src="http://res.cloudinary.com/dfg5p1pww/image/upload/v{{user.picVersion}}/{{user.picId}}"
            alt="Card image" style="width:100%">
            <div class="card-body">
              <h4 class="card-title"> {{user.firstName}} {{user.lastName}}</h4>
              <p class="card-text">{{user.age}}</p>
              <p class="card-text">{{user.country}},{{user.city}}</p>
              <p class="material-icons" *ngIf="CheckIfOnline(user.username)">online</p>
              <a class="btn button-image closeButton btn-message" [routerLink]="['/chat', user.username]">Message</a>
            </div>
          </a>
        </div>
      </div>
    </div>

CSS

.card-img-top {
    position: relative;
    overflow: hidden;
    height: 200px;
    width: auto
}

.card-person {
  margin: 50px auto;
  background-color: #ffffff;
  border-radius: 0;
  border: 0;
  box-shadow: 1em 1em 2em rgba(0,0,0,.2);
}

.card-text {
 margin-bottom:0.2rem
}

.btn-match,
.btn-message {
  color:#ffffff;
  background: #FF512F; 
  transition: all .4s;
  margin:5px;
  border-radius:40px
}

.button-image:before {
  content: "";
  width: 23px;
  height: 23px;
  display: inline-block;
  background-size: 100%;
  vertical-align: text-top;
  background-color: transparent;
  background-position : center center;
  background-repeat:no-repeat;
}

.btn-match.closeButton:before{
   background-image : url('../../../assets/images/heart-white.png');
}

.btn-message.closeButton:before{
  background-image : url('../../../assets/images/chat-white.png');

}

a.fill {
  width: 100%;
  height: 50px;
  }

If you encounter issues with image distortion in Bootstrap 4, check the aspect ratio of your images and adjust the container settings accordingly to ensure that all types of images display correctly.

Answer №1

One common issue arises from the CSS property called background-size. If set to 100%, the browser attempts to stretch the background image in both directions to fill the container.

Understanding the various inputs for the background-size property is crucial:

background-size:cover will ensure that the smallest dimension of the image fills the container while hiding any excess parts.

background-size:contain will cause the largest part of the image to cover the container with a letterbox effect if there is additional space.

Additionally, you can utilize background-position to determine where the excess content gets cropped or which part of the container remains visible.

Answer №2

It seems like you are currently utilizing the .card-img-top class. To enhance it, make sure to include the class .card-person.card-img-top.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilize the Jquery Datatable responsive plugin within a collapsed panel of Bootstrap 3

Encountered an issue while integrating a Jquery Datatable (with its own responsive plugin) in a collapsed panel within bootstrap 3. Example that functions correctly: http://jsfiddle.net/Wc4xt/1804/ Example that is not functioning as expected: http://jsfi ...

What is the method for choosing an Object that includes an Array within its constructor?

Is there a way to retrieve a specific argument in an Object constructor that is an Array and select an index within the array for a calculation (totaling all items for that customer). I have been attempting to access the price value in the Items Object an ...

Expanding Material Ui menu to occupy the entire width of the page

I'm encountering an issue with a menu I created where I can't seem to adjust its height and width properly. It seems to be taking up the full width of the page. import React, { Component } from "react"; import Menu from "@material-ui/core/Menu"; ...

What is the best way to use jQuery to apply CSS only to elements with a specific attribute set?

Currently, I am attempting to utilize jQuery to apply specific CSS styles to elements, but only those that possess a particular attribute. The rationale behind not resorting solely to CSS is due to the immense amount of content on the site, making it impr ...

Center-align text so it is perfectly centered over an image

Looking for help with aligning text in social media images? Currently, the text is positioned at the bottom of each image. Check out this example: http://jsfiddle.net/uT4Ey/ CSS: .img { background-color: red; height: 3em; width: 3em; display: inl ...

Having trouble with the anchor tag not functioning properly on Safari for iPhone?

First, let's include the anchor tag code: <a id="store_follow" class="primary-button" data-user-action='on' data-id='<?php echo $value->storeId;?>' data-mode='<?php echo UserUtils::ACTION_MO ...

What is the best way to align text at the center of a circular animation?

I stumbled upon this fascinating animation and I'm looking to incorporate it into my project. However, I'm facing a challenge in centering text inside the circle without resorting to using position absolute. My goal is to have the text with the ...

Easiest method to align an element in the center while floating another one to the right

My desired layout is shown below: | link | link | link a,b,c search: | The links are centered, while the 'a,b,c search' text is floated to the right. I am attempting to achieve this using basic CSS ...

Creating a Rectangular Trapezoid Shape with CSS - Eliminating Unnecessary Spacing

I'm trying to create a trapezoid button using CSS. Here is the intended look: https://i.sstatic.net/0vqlk.png However, my current implementation looks like this: https://i.sstatic.net/QrR4t.png The button appears fine but there seems to be some e ...

Exploring PHP Queries with Div Classes

I'm in desperate need of assistance. I'm currently working on putting together a website and pulling data from a mysql database. The specific div that I'm trying to populate is provided below. The issue I'm facing is how do I integrate ...

adding a touch of flair to a form input that doesn't quite meet the

My goal is to have a red background appear when an input is invalid upon form submission. I attempted the following code: input:invalid { background-color:red; } While this solution worked, it caused the red background to show up as soon as the page l ...

Select the small image to reveal the larger overlay image

I have a grid of images and I want each image to expand into fullscreen when clicked. However, the JavaScript I am using is causing only the last image in the grid to overlay. How can I resolve this issue? Here is the code I am currently using: http://js ...

Showing a Mat-dialog using a shared component

I have developed a system to trigger a modal window when a click event occurs on table elements. Each column value clicked should result in displaying different content within the dialog box. My goal is to create a single component for the dialog box that ...

Issue with ng-change event not triggering for text input within Bootstrap modal

Currently, I'm facing an issue with my application that utilizes a bootstrap modal containing text boxes populated with values from the server. The problem arises when I open the modal for the first time, remove all items from the text box triggering ...

Transforming JSON data into HTML displays only the final <li> element

Please take a moment to review the question provided at the end of this post. I am struggling with understanding why only the last li element from the JSON is being rendered. As a newcomer in this field, any help or guidance would be greatly appreciated! ...

endless cycle of scrolling for div tags

My goal is to incorporate a tweet scroller on I believe it uses the tweet-scroller from Unfortunately, this link seems broken as the demo is not functioning. I searched for an alternative solution and came across http://jsfiddle.net/doktormolle/4c5tt/ ...

Finding the chosen selection in AngularJs

I've been working on this script for hours and I'm struggling to output the text instead of the value of a select option in AngularJS in HTML through data binding. Despite my efforts, I keep getting the value instead of the text. How can I resolv ...

Applying a Webkit Scroll Bar to a specific element on the webpage

I've been attempting to apply the Scroll Bar webkit styling to a particular element but haven't had any success. Despite searching extensively, I have come across 2 threads on Stack Overflow that do not provide a solution. Most of the available ...

Challenges encountered while incorporating Bootstrap into a Ruby on Rails project

I used this guide to help me start working with Bootstrap on Ruby on Rails. Despite following every step carefully, I keep encountering the same error repeatedly. Without using Bootstrap, my application functions fine but looks unattractive. The moment I ...

Prevent zooming on the entire webpage except for the images

I'm in the process of developing a basic PWA and am aiming to give it the appearance of a native mobile application, but I'm encountering obstacles with pinch-in functionality. In my layout.html file (utilizing Flask for the backend), I've ...