Tips on resizing images in card groups with bootstrap 4?

Hey there!

I've come across an issue with my code that was initially working perfectly. The images I'm using have different resolutions, causing the card images to display in various sizes. Is there a way to implement image scaling to ensure all images appear uniform in size?

For reference, here's an example link: https://i.sstatic.net/z1mtb.jpg

The code I'm working with utilizes Bootstrap 4 CDN.

<section>
          <div class="container">
          <div class="card-group">
            <div class="card">
              <img class="card-img-top img-fluid" src="assets/images/removals.jpg" alt="Card image cap">
              <div class="card-body">
                <h5 class="card-title">Card title</h5>
                <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
              </div>
              <div class="card-footer">
                <small class="text-muted">Last updated 3 mins ago</small>
              </div>
            </div>
            <div class="card">
              <img class="card-img-top img-fluid" src="assets/images/truck image.png" alt="Card image cap">
              <div class="card-body">
                <h5 class="card-title">Card title</h5>
                <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p>
              </div>
              <div class="card-footer">
                <small class="text-muted">Last updated 3 mins ago</small>
              </div>
            </div>
            <div class="card">
              <img class="card-img-top img-fluid" src="assets/images/sprintervan.png" alt="Card image cap">
              <div class="card-body">
                <h5 class="card-title">Card title</h5>
                <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
              </div>
              <div class="card-footer">
                <small class="text-muted">Last updated 3 mins ago</small>
              </div>
            </div>
          </div>
</div>
</section>

Any suggestions or solutions are greatly appreciated!

Thank you for your help.

Answer №1

It seems like there is a height issue based on the example provided.

To make images responsive in Bootstrap, use .img-fluid. This applies max-width: 100% and height: auto; to ensure the image scales with the parent element.

https://getbootstrap.com/docs/4.0/content/images/

A potential solution is to include .h-100 (height 100%) in the parent node of each fluid img card

<div class="h-100">
    <img class="card-img-top img-fluid" src="assets/images/removals.jpg" alt="Card image cap">
</div>

https://github.com/twbs/bootstrap/issues/21885

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

Issue with div in simple HTML code

I've been facing challenges with this line of HTML as I keep encountering errors and cannot pinpoint the source. The error highlight appears at the end of the last div, but once removed, another error emerges at the end of the body tag. Check out the ...

What is the reason for the jQuery function not being recognized?

I have encountered a jQuery function that is supposed to replace the default value of "$" with something like "default value". However, for some reason, it seems like the function is not taking effect. <div class="form-group"> @Html.Label("Pr ...

Tips on concealing the overflow content within a Material UI table cell, rather than allowing it to wrap around

I have been trying to use the material UI Table component in order to display a table. The issue I am facing is that when the content in a cell exceeds the allotted space, instead of showing ellipses (...), the text wraps within the cell. I attempted to ap ...

The jQuery append function does not incorporate CSS styling

I am currently facing an issue where my jQuery code successfully appends a piece of HTML, but the CSS styles are not being applied to it after the append operation. What is the correct approach to resolve this? This is the method I am using: if(listone[ ...

PyScript <script type="py-editor"> Issue: SharedArrayBuffer cannot be used in an insecure environment

I am currently using PyScript to execute a basic Python script within my HTML file in order to show a pandas DataFrame. However, upon loading the page in the browser and attempting to run the code block by clicking the run button, I encounter an error rela ...

Issue with ReactStrap input group sizing (width not expanding correctly)

Has anyone else encountered a bug where an input group addon or dropdown is taking up half of the width instead of 100%? It seems that in Reactstrp docs, this behavior is not expected. I want my input group to occupy the full width like the rest of the el ...

Strip the specified span class from the content within $(this).html()

My search function returns search results in spans. When a span is clicked, a new span with a select input and hidden input is added to another div, allowing all selected features to be posted as an array. I have a question: The $(this).html() now include ...

Determine the exact width of text without rounding in Javascript

I'm facing an issue with a div element that I'm manipulating using Javascript to change its position. The problem is that it's rounding off incorrectly. #hi{ background-color: blue; width: 2px; height: 10px; position: absolu ...

Utilizing Selenium for the Upload of an APK Document

I've encountered an issue during my test. I'm attempting to upload an APK file, but the process seems to halt at that stage. My attempts with simple sendKeys using the file path and an AutoIT script have both proven unsuccessful. Below is my in ...

Remove text on the canvas without affecting the image

Is there a way to remove text from my canvas element without losing the background image of the canvas? I'm considering saving the Image source and reapplying it to the Canvas Element after using clearRect, but I'm unsure how to execute this sol ...

Alignment issue with navigation links in React Bootstrap Navbar

Currently working on a navbar design for a website using React and React Bootstrap, but struggling with centering the links. Shown below is an image of the current navbar layout: https://i.sstatic.net/JYmiI.png You'll notice that the "Home" and "Lin ...

Why isn't my CSS button changing color on hover?

div ul li a.button:hover { text-color:#FF0000; background: #0040FF; } I have been attempting to create buttons that change color and text when hovered over. Despite trying different methods, the changes do not seem to be taking effect. Below is the co ...

Is it possible to create a custom tag in HTML 4?

What is a custom tag in HTML (Kindly note that I am specifically talking about the differences from XHTML)? I need to include some additional text to meet StackOverflow's posting requirements. Thanks! ...

Is there a way to eliminate the border surrounding every cell in a table?

I'm facing an issue with a table on a page with a gray background. The challenge is to remove the borders of the cells in the table. <table width="510"> <tbody> <tr> <td style="background-color: #fff;" colspan="2" width="510"> ...

Upon selecting multiple checkboxes, corresponding form fields will be displayed based on shared attributes

When multiple checkboxes are selected by the user, corresponding form fields should appear based on the checkboxes. For example, if both flight and hotel checkboxes are checked, then the full name and last name fields should be displayed while other fields ...

The min-height property in CSS appears to be ineffective on Jelly Bean

In my current project developing an Android application, I have incorporated Webviews in certain activities and fragments. However, I encountered a perplexing issue when running the app on Jelly Bean (api 16 and 18) emulator - the css property min-height ...

troubleshoot clientWidth not updating when CSS changes are made

Summary: When I adjust the size of a DOM element using CSS, its directive fails to acknowledge this change even with a watch on the size. Aim I have multiple custom directives (simple-graph) each containing an svg. My goal is to enlarge the one under the ...

An error occurred while trying to set the property 'IS_CHECK' of an object that is undefined

I'm attempting to create a checkbox that, when selected, should also select everything else. I followed the code example provided in this tutorial for angular 2. However, I encountered an error: "ERROR TypeError: Cannot set property 'IS_CHECK&ap ...

What steps can I take to ensure my HTML5 mobile web app is optimized for compatibility across a variety of devices

I recently developed an HTML5 mobile web app and conducted tests on various devices including iPhones, iPads, Android phones, and tablets. What steps can I take to optimize the size and resolution of this app for seamless performance across all these dif ...

Tips for adjusting the background color of an ag-grid component in a React application

Looking to make a full background color change in ag-grid within a React application. Experimented with row cell style, but aiming for the entire grid background change. Here is my code snippet: { headerName: "Module Name", field: "ModuleName", ...