How to fit an image inside a Bootstrap 3 div?

前端 未结 3 1868
余生分开走
余生分开走 2021-02-19 13:33

I am using a div tag in code as shown below:

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-19 14:08

    Just add you images width to 100%.

    But as you are saying user will upload various kind of images, so can use object-fit property.

    Add the CSS like this:

    .fit-image{
    width: 100%;
    object-fit: cover;
    height: 300px; /* only if you want fixed height */
    }
    
    

    You will find the details about object-fit and object-position here : https://css-tricks.com/on-object-fit-and-object-position/

提交回复
热议问题