Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the img-fluid class in Bootstrap 4 not resizing my images in their divs?

I have a Bootply playground example here: https://www.bootply.com/eXlkXkUvDJ

I'm trying to align the bottom three images so that the far left and far right images are flush with the main image and titles. I also want the images to fill the divs completely -- I highlighted the first image div in black so you can see that the image is not completely filling it.

I checked the Bootstrap 4 documentation and it looks like the 'img-fluid' class should make the images fill each div, but that's not happening.

Here's my HTML code:

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Aisha Wells Portfolio</title>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="main.css">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<div class="container" alt="this is the main container">
    <div class="row">
        <div class="col-md-6" alt="udacity logo">
            <img src="http://cdn.onlinewebfonts.com/svg/img_369247.png" alt="fake logo" width="50" height="50" class="img-responsive">
        </div>
        <div class="col-md-6 text-right text-uppercase" alt="my name">
                <h1> Shere Wells </h1>

                <h3> Writer and Filmmaker </h3>

        </div>
    </div>
</div>
<div class="container" alt="this is the main container">
    <div class="row">
        <div class="col-md-12 rule">
            <hr>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12 main-img" alt="this is the main image">
            <img class="img-fluid" src="http://www.placepuppy.net/400/250" width="100%">
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
                <h4>Featured Work</h4>

        </div>
    </div>
    <div class="container">
        <div class="row">
            <div class="col-md-4 first" alt="First project image">
                <img class="img-fluid" src="https://placekitten.com/250/250" alt="kitteh">
                    <h5>First Name</h5>

            </div>
            <div class="col-md-4 second" alt="Second project image">
                <img class="img-fluid" src="https://placekitten.com/250/250" alt="kitteh">
                    <h5>Second Name</h5>

            </div>
            <div class="col-md-4 third" alt="Third project image">
                <img class="img-fluid" src="https://placekitten.com/250/250" alt="kitteh">
                    <h5>Third Name</h5>

            </div>
        </div>
    </div>
</div>
<div id="push"></div>

And here's my CSS code:

/* CSS used here will be applied after bootstrap.css */

@charset "UTF-8"; 
/*CSS Document for My Portfolio Page*/

h1 { 
    color: #2d3c49; 
    float: right; 
    font-family: 'Montserrat', sans-serif;
}

h3 {
    color:#7d97ad;
    float: right;
    font-size: 20px;
    font-family: 'Montserrat', sans-serif;

}

h4 {
    color:#7d97ad;
    font-family: 'Montserrat', sans-serif;

}

h5 {
    color:#7d97ad; 
    font-family: 'Montserrat', sans-serif;
}

hr {
    border-top-style: solid;
    border-top-width: thick;
    border-top-color:#7d97ad; 
    padding-top:20px;

  }

.first {
    background-color:black; 

}

.col-md-6 {
    background-color:black; 

}
like image 410
WeCareALot Avatar asked Sep 05 '18 05:09

WeCareALot


People also ask

How do I fit an image in a div in Bootstrap 4?

Just add a bit of padding to the image and it resizes itself to fit within the div. Solved WITH Bootstrap rather than custom CSS.

How do I make an image fluid in Bootstrap 4?

Responsive images automatically adjust to fit the size of the screen. Create responsive images by adding an . img-fluid class to the <img> tag. The image will then scale nicely to the parent element.

How do I make an image fit the screen in Bootstrap?

Images in Bootstrap are made responsive with .img-fluid . max-width: 100%; and height: auto; are applied to the image so that it scales with the parent element.

What does image fluid do in Bootstrap?

Images in Bootstrap are made responsive with .img-fluid . This applies max-width: 100%; and height: auto; to the image so that it scales with the parent element.


1 Answers

Add w-100 class on the img tag

<img class="w-100 img-fluid" src="https://placekitten.com/250/250" alt="kitteh">

Also remove the second "container" div just before the start of kitten's row.

No need of another container inside a container.

Bootply link

like image 123
Nandita Sharma Avatar answered Oct 02 '22 21:10

Nandita Sharma