Limit the size of an image within a responsive Bootstrap 4 div

I'm struggling with a div that changes in width (col-x) and height (h-100) depending on the browser window size. Inside this div, there is a large image being displayed. The issue I am facing is that while using .img-fluid achieves width constraint based on container size, it does not scale the height proportionally when the container shrinks. Despite trying various combinations of min-height, max-height, object-fit, etc., the image fails to resize correctly along with the container.

To demonstrate my problem, I created a basic plunker where I used vh for the height of the wrapper. The objective is to ensure that both images always remain within the column even as you adjust the browser dimensions for testing.

<div class="wrapper">
  <div class="row h-100">
    <div class="col-4">
      <img src="https://i.sstatic.net/2OrtT.jpg" class="img-fluid" />
    </div>
    <div class="col-8">
      <img src="https://i.sstatic.net/2OrtT.jpg" class="img-fluid" />
    </div>        
  </div>
</div>

Styles:

.wrapper {
  height: 60vh; 
}

Link to Plunker Demo

Answer №1

Include the css property height:100%; in your image styling

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

Unresponsive JavaScript on specific element IDs

I'm experimenting with making three lines perform different animations: line 1 rotating 45deg and translating, line 2 becoming opaque, and line 3 rotating -45deg and translating. Check out my JS Fiddle here <a href="#"><div id="menu" onclic ...

The text is on the left side while the image is placed

I've been attempting to align text on the left and an image on the right within a div. While I stumbled across several examples on Stackoverflow where the image is on the left and the text on the right, I couldn't seem to flip them around success ...

Extract ID for Bootstrap modal display

In my project, I am using a bootstrap modal that displays various strings. The challenge I am facing involves a loop of cards, each with a distinct 'id'. When triggering the modal, I want to show the corresponding id inside the modal itself, whic ...

How to dynamically assign a CSS class to the parent <li> element when a radio button is selected using JavaScript

I am facing a challenge with a form that includes multiple series of input fields created dynamically by a plugin. The structure of the code is as follows: <!-- section 1 --> <div> <ul> <li> <input type=" ...

Creating a Large Image with Boostrap - Enhancing Position and Responsiveness

How can I make an image float to the right of the page, resize in Large and Medium screens, and vanish in Small and Xtra Small screens? I know how to hide the image using hidden-sm and hidden-xs in bootstrap, but I'm struggling to get the large image ...

Styling a Form Submission with CSS

I am currently working on a website that contains the following PHP code: echo "<form action='choice.php' method='post'>"; echo "<input type='submit' name='choice' value='left' /> "; As I am i ...

Fade in text effect using jQuery on a Mac computer

Trying to create a smooth text fading effect across different browsers using jQuery. In the example below, you may notice that during the last part of the animation when the text fades in, the font weight suddenly increases causing a jerky/clunky appearan ...

The jQuery bxSlider is failing to function properly in a responsive design

Anyone else experiencing issues with the jQuery bxSlider not functioning properly on a responsive layout? It seems to be working fine on larger screens. $(document).ready(function () { $('.slider1').bxSlider({ pagerCustom: '#bx-pager&apos ...

What are some ways to customize the appearance of VueJS components?

I am new to Vue, so I apologize if this question seems silly or if I have overlooked something. I believed that you could target a custom element like this: my-element { styles go here} However, when I created an element, it appears that I can only targe ...

The footer is displaying unusual white space beneath it

Recently, I attempted to create a sticky footer using Flexboxes and the <Grid container> Check out the code on Codesandbox However, an issue arose - there was a strange whitespace below the footer. https://i.sstatic.net/2YdaJ.png After some exper ...

Is there a javascript file storing an image?

Currently, I am in the process of creating my personal portfolio website and incorporating react-bootstrap for designing my react components. I have been attempting to add an image using the Image component provided by react-bootstrap. However, I noticed ...

Challenges arising from updating the size and position of a div element during a mouse move event

As I work on creating a basic horizontal split pane using HTML, CSS, and JavaScript, I have drawn inspiration from this post. While the vertical split pane functions smoothly, the horizontal version seems to be glitchy. The sizes and positions of the div ...

The autocomplete feature in Jquery tagsinput is malfunctioning within a Bootstrap modal

Currently, I am working on implementing an autocomplete tag search within a bootstrap modal. The jquery library that I am using for this purpose can be found at this link. While the autocomplete search feature functions properly when the input textbox i ...

clear background with logo embossed

I have encountered an issue while trying to place my logo on a black background with transparency. Instead of the background being transparent, now my logo is also becoming transparent which was not my intention. Does anyone have any suggestions or ideas ...

Having trouble retrieving an image from a MySQL blob column

I'm facing an issue with fetching and displaying an image from a blob column in my MySQL database using a JLabel. Below is the code snippet that I am currently using: pst = con.prepareStatement("SELECT `profilepic` FROM `librarian` WHERE `username` = ...

The settings of the button return to their default state once it is clicked on

I've been working on a small project and I added a button with hover and CSS effects. However, the issue is that once the button is clicked, it reverts back to its basic state without any of the CSS properties applied. I attempted to troubleshoot if ...

"Interactive Connect 4 Game in Javascript - Drop the disk into the bottom row of the chosen

Check out this awesome Connect4 game I found: http://codepen.io/anon/pen/lmFJf I have a specific goal in mind for the game. When I click on an empty space in any column, I want it to automatically drop into the lowest available spot in that column, follow ...

Modify a particular box-shadow within a list of box-shadows using CSS

Is there a way to override one specific value in the box-shadow list while preserving all other values? For example: div{ box-shadow: 0 0 0 5px #00ff00 , 0 0 0 10px #ff0000 , 0 0 0 15px #0000ff ; } If we only want to change the second value without ...

Adjust the horizontal position of a text element using CSS

I am faced with a specific challenge where I need to center the text "test" within a text tag using only CSS, without being able to directly change the HTML. <text width="13.89" height="13.89" x="291.46999999999997" y="156.55" transform= ...

difficulties encountered when implementing a sticky footer with two distinct footer sections

Currently, I am teaching myself web development and reconstructing a website from scratch. The layout should resemble the following: ===========Navigation Bar=========== =========Website Content=========== ===========Footer #1============ ===========Fo ...