Despite using the 'img-fluid' class, the image is still not fully responsive

Despite using the img-fluid class in my img tag, I am facing an issue with image responsiveness. The image is responsive on smaller screens but loses its responsiveness after a certain screen size.

I have researched solutions on How to make an image responsive using bootstrap without having it take up the entire width of the division? and Bootstrap: img-responsive vs img-fluid, but none have resolved the problem.

This is how I attempted to address the issue:

HTML:

    <!-- THE HEADER -->
    <div class="container-fluid header">
        AUST CSE
    </div>
    <!-- IMAGE JUST BELOW HEADER -->
    <div class="wrapper" style="background: blue">
        <img src="images2/banner.jpg" class="img-fluid">
    </div>

CSS:

    .wrapper {
        width: 100%;
    }

The page appears like this on smaller screens: https://i.sstatic.net/YUX2j.png However, on larger screens, the image fails to occupy 100% of the space and looks like this: https://i.sstatic.net/mh9Zy.png I aim for the image to cover 100% of the width and scale up its height, similar to its behavior on smaller screens.

Answer №1

img-fluid utilizes max-width: 100%;. This means that once the containing element reaches the same size or larger than the image's width, it will cease resizing.

There are two options to consider:

1) Opt for an image with a resolution equal to or greater than the widest width of your container element. If your container element's width is not fixed (e.g. always 80% of viewport width), choose an image large enough to look good on most displays (consider common browser resolutions).

@import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css' );

/* Demonstrational styling, not essential. */
.demo {
  background-color: rebeccapurple;
}
<div class="container">
  <div class="row">
    <div class="col-md-4">
      <div class="demo">
        <img class="img-fluid" src="https://via.placeholder.com/1000x1000">
      </div>
    </div>
    <div class="col-md-8">
      <p>
        Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. 
        Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. 
        Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. 
      </p>
  </div>
</div>

2) Override .img-fluid to allow the image to resize beyond its native resolution. The drawback is that the image may appear grainy. Smaller native resolutions will result in more noticeable distortion when scaled up. In my example, you can see that the text becomes quite fuzzy.

@import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css' );

/* Demonstrational styling, not essential. */
.demo {
  background-color: rebeccapurple;
}

/* Will override all instances of .img-fluid. */
.img-fluid {
  width: 100%;
}
<div class="container">
  <div class="row">
    <div class="col-md-4">
      <div class="demo">
        <img class="img-fluid" src="https://via.placeholder.com/100x100">
      </div>
    </div>
    <div class="col-md-8">
      <p>
        Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. 
        Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. 
        Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. 
      </p>
    </div>
  </div>
</div>

I've included a scoping example below that enables you to selectively override certain images to exceed their native resolution.

@import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css' );

/* Demonstrational styling, not essential. */
.demo {
  background-color: rebeccapurple;
}

/* Scoped for targeting specific images. */
.img-fluid.img-full-width {
  width: 100%;
}
<div class="container">
  <div class="row">
    <div class="col-md-4">
      <div class="demo">
        <img class="img-fluid img-full-width" src="https://via.placeholder.com/100x100">
      </div>
    </div>
    <div class="col-md-8">
      <div class="demo">
        <img class="img-fluid" src="https://via.placeholder.com/100x100">
      </div>
    </div>
  </div>
</div>

Answer №2

If you want your image to stretch across the entire width of the screen on larger devices, ensure that the image width matches the screen width.

It seems like your image dimensions are not large enough. The img-fluid class will resize the image, but only up to its maximum dimensions.

To resolve this issue, you have two options:

  1. (The recommended method) Choose an image with the correct width for the maximum screen size you desire (usually 1920px).

  2. You can add width: 100% to your image so that it spans the full width of the page. However, if your image's width is smaller than the screen size, the image may appear blurry. It's best to use images with the appropriate dimensions.

Example:

  • Example of an image with smaller dimensions (your current issue): JSFiddle

.container {
  border: 2px solid red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <h2>Image</h2>
  <p>The .img-fluid class makes the image scale nicely to the parent element (resize the browser window to see the effect):</p>
  <img class="img-fluid" src="https://cdn-static.denofgeek.com/sites/denofgeek/files/styles/main_wide/public/2015/11/main_0.jpg?itok=k1tyTR75" alt="HL2"> 
</div>

  • Example of an image with larger dimensions (1920px): JSFiddle

.container {
  border: 2px solid red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <h2>Image</h2>
  <p>The .img-fluid class makes the image scale nicely to the parent element (resize the browser window to see the effect):</p>
  <img class="img-fluid" src="https://s.aolcdn.com/hss/storage/midas/f8eff2a90708d58814bb4adc93634cbb/205752037/half-life-2-15622-1920x1080.jpg" alt="HL2"> 
</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

Include draggable functionality to a seating chart that is generated dynamically

I developed a function that generates table seats dynamically with equal spacing. The issue arises when I try to drag names from a list and drop them onto the seats as children. Unfortunately, I can't seem to achieve this functionality with the dynami ...

What are the steps to create a hovering dropdown menu that changes the background window to transparent when hovered over?

Is there a way to create a dropdown menu that changes the background window to transparent when hovered over? Here is an example of what I am looking for: https://i.sstatic.net/FplLm.png The dropdown menu should look like this when hovered over: https: ...

Position images inside a stylish border using CSS styling

//UPDATE: I've made some changes to the Pen, so now everyone can view the solution! Check it out here. My goal is quite simple in my opinion. I want to create an image that zooms in when you hover over it but doesn't increase in size. I attempte ...

Providing an image in a Django web application

I'm having trouble displaying an image on my Django web app. Despite placing the image in the static folder, and the hello.html in the templates folder, I'm still getting a broken image link. Below is the content of hello.html: {% load static %} ...

The footer refuses to stay positioned at the bottom of the page

Can you help me locate the CSS style for the footer? #footer { background-color: #000; bottom: 0px; color: #fff; clear: both; text-align: center; padding: 5px; } What is the best way to ensure the footer is positioned at the bottom of ...

Activate the child for an update

Welcome! I am a newcomer to Angular and would greatly appreciate any assistance. The parent component of my picker has the ability to create various rules for each option. However, these rules are dynamic and can change frequently. I need to ensure that ...

The interaction of flex-box in the presence of absolute positioning

Hey everyone, I need some help understanding why the flexbox is behaving oddly in this code snippet. 1. <!DOCTYPE html> <html> <head> <style> body{ position: relative; } .container { ...

Setting a constant width for text characters across all devices using CSS and HTML

I am looking to display text in my textarea with the same width in pixels across all devices. Essentially, I want to set the character width in pixels so that it appears consistently on any device (Desktop/Mobile). <html> <head> <styl ...

The issue with the min attribute for number inputs not functioning properly when using decimal

When inputting the value 3 in the field and clicking on submit in the HTML snippet below, Chrome displays an error message stating: Please enter a valid value. The two nearest valid values are 2.0001 and 3.0001. This is confusing because I have set the mi ...

Is it possible for a complete CSS ".class" to possess the specificity of '!important'? [closed]

It's quite challenging to determine the exact inquiry being made here. This question lacks clarity, precision, completeness, specificity, and is overly general or rhetorical, making it impossible to answer in its current state. To obtain assistance in ...

upgrading from Internet Explorer 8 to Internet Explorer 9

Similar Topic: Transitioning from IE8 to IE9 Are there any recommendations for transitioning from IE8 to IE9 in order to operate an application smoothly? What factors should be taken into account for CSS, HTML, and JavaScript prior to the migration? ...

Any suggestions on how I can make my modal stand out more?

I'm having trouble getting the modal to show up in this HTML file. Do I need to add something here or somewhere else? Do I also need to write a button onclick function? The modal should display when the "delete" button is clicked. <div class=" ...

Enigmatic blank space found lurking beneath the image tag

Recently, I made a change to the header image on my website. Previously, it was set using <div style="background-image... width=1980 height=350> and now I switched to <img src="... style="width:100%;"> This adjustment successfully scaled do ...

Having trouble displaying a background image on a React application

Public>images>img-2.jpg src>components>pages>Services.js> import React from 'react'; import '../../App.css'; export default function Services() { return <h1 className='services ...

Maximizing the height of a flex container

Two flex containers are utilized: one for the navigation bar and the other for the page content. To make the content occupy the entire height of the page, the container's height was set to 100vh. However, a challenge arose when the navigation bar&apo ...

Guide to Inserting an Image with AngularJS

Recently, I embarked on developing a web application with AngularJS. I encountered an issue while trying to incorporate an image into my page - unfortunately, the image failed to display properly. img src="src/assets/img/f1.png" alt="icon" I utilized the ...

Need help creating perfect round buttons with bootstrap 4?

After incorporating this fiddle into my code, the goal was to design a circular button. View Fiddle Here The code provided is for bootstrap 3. However, when using it with bootstrap 4, the button ends up being square instead of circular. See example here: ...

Managing HTTP requests across different HTML pages in a Cordova mobile application

I have developed a Multiple Page Application (MPA) for Android and iOS which navigates to different pages when users want to view them. Everything is running smoothly so far, but I now want to add some backend sync features. The issue I am facing is that I ...

Adjust the checkbox dimensions within the cells of a bootstrap table

I am utilizing bootstrap-table along with a column containing checkboxes. I need to adjust the size of the checkboxes in my code to be 25x25 pixels. However, when I try using the height and width CSS attributes, it does not seem to take effect. html < ...

I am attempting to add a new row (div) for the invoice, but when I do so, the

Looking for a solution to repeat a row when clicking a button in order to utilize PHP for data manipulation? Check out the code snippet below: <!-- Table row --> <br><br> <div class="row"> <!--Product Table--> <div ...