Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Card image width not equal when I gave max-height

I am making a card with equal image size and text. I had given max-height to the image. but the images are not equal in size. I will give my code below. I am attaching my website's snap for better reference. In this project, I am using HTML, CSS and BOOTSTRAP4

Problem is : Image

  .kbcard {
        box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
        max-width: 300px;
        margin: auto;
        text-align: center;
        font-family: arial;
    }

    .kbtitle {
        color: grey;
        font-size: 18px;
    }

    a .kb{
        text-decoration: none;
        font-size: 22px;
        color: black;
    }
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
 

<div class="row">
    <div class="col-md-3">
        <div class="kbcard">
            <img src="https://www.saintleuparis.catholique.fr/IMG/arton691.jpg?1467978372" alt="John" style="max-width:300px">
            <h1>John Doe</h1>
            <p class="kbtitle">CEO & Founder, Example</p>
            <p>Harvard University</p>

        </div>

    </div> 
    <div class="col-md-3">
        <div class="kbcard">
            <img src="https://www.saintleuparis.catholique.fr/local/cache-vignettes/L187xH270/images-74-b67fc.jpg?1468002198" alt="John" style="max-width:300px">
            <h1>John Doe</h1>
            <p class="kbtitle">CEO & Founder, Example</p>
            <p>Harvard University</p>

        </div>

    </div>
     
</div>

I need : Snap

like image 276
Pritesh Avatar asked Jun 04 '19 04:06

Pritesh


People also ask

How do you fix the width and height of an image?

The height and width of an image can be set using height and width attribute. The height and width can be set in terms of pixels. The <img> height attribute is used to set the height of the image in pixels. The <img> width attribute is used to set the width of the image in pixels.

What will happen if width and height of the image is not specified?

If width and height are not specified, the page will flicker while the image loads.

What is the effect of applying height and width attributes to an image?

If height and width are set, the space required for the image is reserved when the page is loaded. However, without these attributes, the browser does not know the size of the image, and cannot reserve the appropriate space to it.


1 Answers

 img {
        vertical-align: middle;
        border-style: none;
        width: 100%;
        height: 250px;
        object-fit: cover;
    }

try these stylings to your image tag

like image 60
Udayavani Avatar answered Oct 05 '22 10:10

Udayavani