Creating consistent image sizes using Bootstrap or pure CSS styling

I've been attempting to create 6 images that are all responsive and the same size. I've tried using just CSS and also tried using bootstrap cards, but I can't seem to achieve the desired result.

I've experimented with flexbox, grids, setting width to 100%, height to auto, height to 400px (the actual height of each image), h-100, object-fit-cover, and many other techniques, but I feel like I'm missing something. My goal is to have all images be 100% wide on mobile, 2 columns on medium screens, and 3 columns on large screens, all while being responsive. I know it shouldn't be this difficult! Any assistance would be greatly appreciated.

<section id="portfolio">
  <h2>Portfolio</h2>
  <div class="container">
    <div class="row">
      <div class="col-md-6 col-lg-4">
        <div class="card my-5">
          <a href="" class="card-link">
            <img
              src="img/blog.jpg" class="card-img"
              alt="landing page for a recipe website, showcasing fresh vegetables, uncooked pasta noodles, hand towel, and wooden spoon"
            >
          </a>
          <h4 class="card-title">Blog</h4>
        </div>
      </div>
      
      <!-- Additional image cards removed for brevity -->

    </div>
  </div>
</section>

Here is a screenshot of how my code is currently displaying the images

Answer №1

object-fit: cover; seems to be functioning correctly.

.card-img {
  object-fit: cover;
  width: 100%;
  height: 200px;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7b5b8b8a3a4a3a5b6a797e2f9e4f9e7fab6bba7bfb6e4">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="264449495255525447566613081508160b474a564e4715">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script>

<section id="portfolio">
  <h2>Portfolio</h2>
  <div class="container">
    <div class="row">
      <div class="col-md-6 col-lg-4">
        <div class="card my-5">
          <a href="" class="card-link"
            ><img
              src="https://cataas.com/cat/cute"
              class="card-img"
              alt="landing page for a recipe website, showcasing fresh vegetales, uncooked pasta noodles, hand towel and wooden spoon"
          ></a>
          <h4 class="card-title">Blog</h4>
        </div>
      </div>

      <div class="col-md-6 col-lg-4">
        <div class="card my-5">
          <a href="" class="card-link"
            ><img
              src="https://cataas.com/cat/orange"
              class="card-img"
              alt="Landing page for Patriot Heating and Air website, red white and blue theme"
          ></a>
          <h4 class="card-title">Small Business</h4>
        </div>
      </div>

      <div class="col-md-6 col-lg-4">
        <div class="card my-5">
          <a href="" class="card-link"
            ><img
              src="https://cataas.com/cat/black"
              class="card-img"
              alt="common area at a university with large floor to ceiling windows, greenery outside, and people milling about"
          ></a>
          <h4 class="card-title">Collegiate</h4>
        </div>
      </div>

      <div class="col-md-6 col-lg-4">
        <div class="card my-5">
          <a href="" class="card-link"
            ><img
              src="https://cataas.com/cat/grumpy"
              class="card-img"
              alt="Landing page for a chef's website showing his bio and an picture of chef Jack in a red apron"
          ></a>
          <h4 class="card-title">Portfolio</h4>
        </div>
      </div>

      <div class="col-md-6 col-lg-4">
        <div class="card my-5">
          <a href="" class="card-link"
            ><img
              src="https://cataas.com/cat/tabby"
              class="card-img"
              alt="landing page screenshot for homestead website, mother and child in garden"
          ></a>
          <h4 class="card-title">Hobby</h4>
        </div>
      </div>
    </div>
  </div>
</section>

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

Emphasize the center row within a moving table

I am interested in developing a scrolling table where only 10 rows are visible at any given time, with the middle row set to stand out even during scrolling. The concept is that as the user scrolls down, the highlighted row changes progressively as they c ...

FAQs about utilizing percentage width and margins in CSS with Bootstrap

Currently, I am working on a mobile responsive web design using Twitter Bootstrap 3, and I am facing challenges with margins and resizing. I previously asked about creating a mobile-first responsive web design along with responsive images, which you can f ...

What is the best way to make my <div> element expand to fill the entire width of the screen? I attempted setting the width to 100%, but it didn

I need help creating a <div> that spans the entire width of the screen. In my CSS, I have this code: #spacer3 { width:100%; height:300px; } Although it seems like it should work, the div is not extending all the way to the edges of the screen on ...

"Despite using the same CSS and HTML code, the fonts appear distinct from each

Feeling lost here, not understanding what's going on. I made changes in Elementor on my first PC and later noticed that the font looked a bit different. I tried to revert the changes but had no luck. I also work on my second PC where the browser showe ...

How can I stop the CSS border of an iframe from flickering and what are some solutions to fix it?

I am encountering an issue with my iframe border when using CSS. The problem arises in Chrome where the border disappears upon resizing the page, while Safari changes the size (Firefox appears unaffected) https://i.sstatic.net/ZUi9z.gif Are there any kno ...

What are some solutions for resolving differences in the display of pseudo elements between Macbooks and Windows desktops?

Greetings! I successfully converted an XD file to HTML and CSS code. I tested it on my Windows PC, but I haven't had the chance to test it on a Macbook yet. Details: I implemented a button with a pseudo element to show a right arrow on the right side ...

Modifying the appearance of InputText through CSS encapsulation

I'm a newbie to using Blazor and I'm currently experimenting with changing the style of InputText by utilizing css isolation. Interestingly, I've managed to successfully change the style when setting it inline or internally, however, things ...

Exploring AngularJS: A Guide to Accessing Millisecond Time

Is there a way to add milliseconds in Time using AngularJS and its "Interval" option with 2 digits? Below is the code snippet, can someone guide me on how to achieve this? AngularJs Code var app = angular.module('myApp', []); app.controller(&ap ...

The way images appear can vary between desktop and mobile devices

I am in the process of creating a photography website with a simple goal of displaying images down the page one after another. However, I am encountering issues with uniform display across various desktop and mobile platforms. The site appears perfect on i ...

Using JavaScript/JQuery, change relative or viewport sizes to fixed sizes when the page loads

Wishing you a delightful day. As I work on my website, I find myself relying heavily on viewport units like vw and vh for all measurements such as font size, padding, margin, width, and height. These units provide the flexibility needed to ensure that the ...

Does jQuery's click event not successfully hide an element on Internet Explorer?

In my dropdown menu, I have the following options: <div class="my_div"> <select name="selection" id="select_id"> <option value="0">A</option> <option value="5">B</option> ...

Disabling Scroll for a HTML Input Tag

My input field has a long value and is set to readonly. Although I have applied overflow-x: hidden; to it, scrolling is still possible on mobile devices. I want to disable this scroll behavior. Can anyone provide a solution? Thank you for your assistance. ...

Creating a CSS grid with uniform row heights, each adjusting independently

I'm currently working on creating a CSS grid for a product display. My goal is to have rows with equal heights, but each row should adjust its height based on the tallest column within that specific row. Right now I have all rows set to be the same he ...

What is the best way to create a line break within a loop in React?

I have a react component that I need to format into multiple lines, specifically having 2 boxes on top and 3 below in a looped return. The desired layout is to stack the boxes in 2x2 or 2x3 depending on the total number of boxes generated by the loop. So, ...

Guide on creating a div container that spans the full width of the HTML page with a horizontal scrollbar

I'm facing an issue where the div container is not extending over the entire HTML page with a horizontal scroll bar. Here's a visual representation of my problem: Image Despite using MathJax to display math formulas, the div container does not ...

jQuery can be used to relocate buttons on a webpage

When the Contact button is clicked, how can I move the Close button below #panel? It's currently fixed in position. Here's my demonstration: https://jsfiddle.net/25u78gff/ https://i.sstatic.net/qDad9.png jQuery('.sub-menu').addClass( ...

How to truncate text in a cell of a Vuetify data table using CSS styling

Is there a way to truncate text in a cell using CSS without it wrapping around or overflowing? The ideal CSS code should include: .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } However, the current implementation caus ...

Raising css properties using jquery

Is there a way to adjust CSS values using jQuery? I am looking to specifically increase values like top and left, but my current attempt is not producing the desired outcome: var left = 5; $(.object).css("left" + 5); The challenge I am facing is that I ...

Having trouble getting the height to work properly on your Blogger Blogspot template?

Issue with embed height=100% not working <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head> & ...

Issues with Jquery datatable causing column header to overlap the table header

I am facing an issue with my datatable as the table is not displaying correctly. Could someone advise me on how to troubleshoot and fix this problem? Below is the code snippet in question: $(tbName).dataTable({ "sScrollX": "100%", "sScro ...