Creating resizable images using CSS in Bootstrap

I have a horizontal scrolling page implemented with bootstrap 5. The images all have the same height but varying widths. My objective is for the images to always fill the width of the page, so they should resize accordingly when the browser window size changes.

What steps do I need to take to achieve this? Any assistance would be greatly appreciated.

https://i.sstatic.net/LqIwV.png

.container-fluid{
  /* Vertical Scroll */
  overflow-x: scroll;
  overflow-y: hidden;
  white-space: nowrap;
  height: 100%;
}

.flex-nowrap {
  -webkit-flex-wrap: nowrap!important;
  -ms-flex-wrap: nowrap!important;
  flex-wrap: nowrap!important;
}

.row {
  flex-direction: column;
}

.col > img {
  min-height: 100px;
  max-height: 300px;
  height: 300px;
  padding-right:10px;

}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2a4845455e595e584b5a6a1f041a0418">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" />

<div class="container-fluid ">
  <div class="row flex-row d-flex flex-nowrap">
    <div class="col">
      <img src="https://via.placeholder.com/450x600.png" alt="">    
    </div>
    <div class="col">
      <img src="https://via.placeholder.com/500x600.png" alt="">    
    </div>
    <div class="col">
      <img src="https://via.placeholder.com/550x600.png" alt="">    
    </div>
    <div class="col">
      <img src="https://via.placeholder.com/333x600.png" alt="">    
    </div>
    <div class="col">
      <img src="https://via.placeholder.com/450x600.png" alt="">    
    </div>
    <div class="col">
      <img src="https://via.placeholder.com/500x600.png" alt="">    
    </div>
    <div class="col">
      <img src="https://via.placeholder.com/550x600.png" alt="">    
    </div>
    <div class="col">
      <img src="https://via.placeholder.com/333x60 [...]

Answer №1

To ensure that the children of .flex-row have their widths determined by the image, make sure to replace .col with

.w-auto.flex-shrink-1.flex-grow-1
and include .img-fluid with your images. It seems there are some issues in your stylesheet as well. Here's a revised snippet for reference:

UPDATE

If you're aiming for vertical responsiveness (a non-standard approach), utilize the unit vh on height settings and avoid using .flex-shrink-1. This will proportionally adjust the images based on viewport height while preserving aspect ratio. Check out the modified snippet below incorporating height: 30vh; and min-height: 100px;:

.container-fluid {
  /* Enable Vertical Scrolling */
  overflow-x: scroll;
  overflow-y: hidden;
  white-space: nowrap;
  height: 100%;
}

.flex-nowrap {
  -webkit-flex-wrap: nowrap !important;
  -ms-flex-wrap: nowrap !important;
  flex-wrap: nowrap !important;
}


/* .row {
  flex-direction: column;
} */

.w-auto>img {
  min-height: 100px;
  /* max-height: 300px; */
  height: 30vh;
  padding-right: auto;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8defe2e2f9fef9ffecfdcdb8a3bda3bf">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid ">
  <div class="row flex-row d-flex flex-nowrap">
     <!-- Images with Responsive Vertical Heights -->
    ...
  </div>
</div>

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

Adjust the text size to fit perfectly within the boundaries of a textarea input field

Is there a way to ensure that users type within a specific area with formatting and returns in a textarea element? I'm looking for a solution that limits overflow and ensures users stay within the designated area. How can this be achieved? I am worki ...

The column flex-direction property seems to be malfunctioning

Can anyone help me with styling a ul tag using display: flex? I'm trying to order it by column with flex-direction: column;, but for some reason, it's not working. Here is the CSS code for the container: #nav li.four_columns ul.sub-menu { widt ...

A database table named after a pair of digits

My database tables are named "30" and "kev." When I query the table named "30," I receive the following error message: Warning: Invalid argument supplied for foreach() in # on line 94 However, when I query the kev table, I do get the desired results. B ...

Guide on creating an accessible table with rows that can be selected

Managing accessibility in a web application can be challenging, especially when dealing with features like selecting multiple rows using checkboxes. In my current project, I have a view that displays a list of items and allows users to select multiple rows ...

Tips on Utilizing If/Else Conditions in HTML Table TD_TAGS

Can someone please explain how to implement an if/else condition within this <td> tag? <td data-label="Status">{{$t('Status'+item.cStatus)}}</td> This is what I am trying to achieve: if(item.cStatus == NW){ color:red ...

Tips for closing a popup without exiting the entire webpage

I'm facing an issue while trying to create a video playlist using two HTML files (index.html and video.html). In my video.html file, I have set up a popup for playing videos. However, whenever I close the popup or click anywhere on the page, it redire ...

Reveal/Conceal footer upon vertical scrolling

I am attempting to achieve the following goals: Display the div element when the scrolling position is greater than 20 Apply a fadeOut effect after a certain delay Prevent the fadeOut effect when hovering over the sticky footer This is my implementation ...

Troubleshooting a problem with the Bootstrap dropdown menu

Can anyone assist with an issue regarding Bootstrap 4.4.1? I am facing a problem where two consecutive dropdown links+menus are not displaying correctly. The second dropdown menu is showing the content of the previous link instead of its own, even though t ...

How to truncate lengthy text in a table on mobile screens using Bootstrap 4

I am currently working on a responsive table that needs to display correctly on both desktop and mobile devices. However, I have run into an issue where long text in the table gets truncated on mobile devices, compromising the responsiveness of the design. ...

CSS: "Cutting-edge" design. In what way?

I am seeking to replicate a design similar to that of Fantastical's website (https://flexibits.com/fantastical), where the edge of a screenshot extends beyond the page boundary. As the user resizes the window, more of the screenshot becomes visible. A ...

Having trouble transmitting parameters through ajax

I have been attempting to use ajax to send variables to a php page and then display them in a div, but unfortunately, it's not functioning as expected. Below is the HTML code: <div id="center"> <form> ...

My experience with jquery addClass and removeClass functions has not been as smooth as I had hoped

I have a series of tables each separated by div tags. Whenever a user clicks on a letter, I want to display only the relevant div tag contents. This can be achieved using the following jQuery code: $(".expand_button").on("click", function() { $(th ...

Events related to key press timing in HTML 5 canvas

Currently, I am developing a game similar to Stick Hero for Android using HTML5. I am working on the code that will capture the time of key press (specifically the right arrow key with ASCII 39) in JavaScript and expand a stick accordingly. <!doctype h ...

Combining GET and POST requests for CSRF attack

Imagine a scenario where a web application includes a delete button. When the button is clicked, the application initiates a GET request that returns a POST form containing a token key. The user is then prompted with a Yes or No question to confirm deletio ...

What is the process for utilizing bootstrap to automatically adjust font size on larger screens?

I'm facing an issue with displaying bullet points on varying screen sizes while using bootstrap. The fonts resize perfectly on my laptop, but when displayed on a large TV screen or tested with the responsive tool in the browser, the font size remains ...

Using the / (forward slash) in CSS styling statements

Similar Query: Understanding the CSS font shorthand syntax As I was examining the styling on Apple's website, I encountered a CSS rule that left me puzzled: body { font: 12px/18px "Lucida Grande","Lucida Sans Unicode",Helvetica,Arial,Verdana, ...

The input texts are intertwined with one another through an autocomplete function

My latest project involves two input fields, one for ID and the other for Name. When I enter an ID in the first input field and then move to the second (either by pressing tab or clicking), the second input field automatically populates with the correspond ...

Incorporating Computer Modern Serif into Your Jekyll GitHub Page

I have customized a version of the Jekyll GitHub page from here and am trying to incorporate Computer Modern Serif font as the main body font across all pages. Following instructions from an informative answer, I have downloaded the necessary files from th ...

After reducing the size of the table, the data spills over

Hey there, amazing individuals of the internet! Hope you're all doing well today. I've encountered a rather perplexing issue that's got me stumped. So, here's the situation - I have this table full of data and I want it to initially be ...

What is the best way to emphasize this specific section of text?

Looking for help with my tumblr template. I have the following block of code: {block:IfNotEndlessScroll}{block:Pagination}{block:PreviousPage}Previous Page{/block:PreviousPage} {block:NextPage}Next Page{/block:NextPage}{/block:Pagination}{/block:IfN ...