What's new

Welcome to the forum 👋, Visitor

To access the forum content and all our services, you must register or log in to the forum. Becoming a member of the forum is completely free.

How to use object-fit: contain;

Ahr Aitch

New member
Joined
Aug 12, 2023
Messages
11
Reaction score
0
HTML Coins
14
I have an area of one of my screen designs reserved for a photo. In CSS I defined the width and height as 245px each then used the object-fit: contain; selector. I made no changes in my HTML. My understanding is that object-fit: contain should cause any image coded in HTML with that DIV class to be fitted to the space defined for that DIV class, but this is not working for me. The images display as their actual size without regard to the size of the container defined by CSS. Do I misunderstand how this is supposed to work?

If anyone can tell me what I'm doing wrong, I'd very much appreciate it. I've searched, watched YTs and even ran both my CSS and HTML code through validators without finding any problem. My images are stored in an 'images' sub-folder within my project folder and are referenced (properly, I think) with "images/filename" in the HTML.

HTML:
<div class="item2">
<img src="images/filename">
</div>
There is no declaration of width and height in HTML for the image to be displayed. The actual images vary from 480x480px to 600/500px.

CSS:
.item2
{
grid-area: photo
width: 245px;
height: 245px;
margin-top: 5px;
margin-left: 70px;
border-style: ridge;
border-width: 2.5px;
border-radius: 5px;
padding: 6px;
object-fit: contain;
}
 

Theme customization system

You can customize some areas of the forum theme from this menu.

  • Wide/Narrow view

    You can control a structure that you can use to use your theme wide or narrow.

    Grid view forum list

    You can control the layout of the forum list in a grid or ordinary listing style structure.

    Picture grid mode

    You can control the structure where you can open/close images in the grid forum list.

    Close sidebar

    You can get rid of the crowded view in the forum by closing the sidebar.

    Fixed sidebar

    You can make it more useful and easier to access by pinning the sidebar.

    Close radius

    You can use the radius at the corners of the blocks according to your taste by closing/opening it.

  • Choose the color combination that reflects your taste
    Background images
    Color gradient backgrounds
Back