Why is object-fit not functioning properly? Could it be that the container is influencing the object-fit

Why isn't object-fit working? It only seems to work with inline styling in the image tag. Could it be the hero_media container affecting object-fit? I'm also attempting to use pseudo-elements (after and before) to add text to the image. Is it necessary to modify only the hero_media container?

        Here is my code
import React from "react";
import Navbar from "../navbar/Navbar";
import Footer from "../footer/Footer";
import donation from "./donation.css";

const Donation = () => {
    return (
        <div>
            <div className="content_wrap">
                <Navbar />
                <div className="hero_media">
                    <img
                        //style={{ objectFit: "fill", width='100%', height:'100%' }}// this is work
                        src={process.env.PUBLIC_URL + "/assets/donation.jpg"}
                        alt="donation image"
                        className="image"
                    />
                </div>
            </div>
            <Footer />
        </div>
    );
};

export default Donation;
 Css file   
content_wrap {
    padding-bottom: 300px;
    height: 100%;
}
.hero_media {
    padding-top: 2px;
    max-width: 100%;
    margin: 0 auto;
    position: relative;
    height: 500px;
    box-shadow: rgb(20, 20, 20) 0 0 10px;
}
/*------------------IMAGE-------------*/

.image {
    max-width: 100%;
    max-height: 100%;
    object-fit: fill;//this is not working???
}

Answer №1

Your style property specifies the width and height, but your CSS file only specifies the max-width and max-height.

To address this, update your CSS file to include width and height properties.

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

Is there a way to adjust the selected color of a TextField?

I'm currently working with the Material-UI React library and I am trying to customize the border color of a TextField when it is clicked or in focus. This is my attempt so far: const useStyles = makeStyles((theme) => ({ input: { borderWidth: ...

Creating a custom event handler for form input changes using React hooks

A unique React hook was created specifically for managing form elements. This hook provides access to the current state of form fields and a factory for generating change handlers. While it works seamlessly with text inputs, there is a need to modify the c ...

Changing color of navigation bar link upon refreshing the page using Bootstrap

I am new to the world of HTML/CSS/Bootstrap and recently made a change to the color of a link on the navbar. However, I am encountering an issue where the original blue color of the link briefly appears when I refresh the page. I would like to prevent this ...

What is the best way to add a listener for a modification of innerHTML within a <span>?

How can I detect changes inside a particular <span> element in order to attach a handler, but so far have been unsuccessful? Below is the HTML snippet: <span class="pad-truck-number-position"><?php echo $_SESSION['truckId']; ?> ...

React documentation - GitHub markdown documents that utilize a unique table format

When examining a React docs markdown file (used to generate the corresponding docs html pages), you will notice a table of values at the top in the .md file. The markdown syntax used to create this table is non-standard: --- id: hello-world title: Hello W ...

What is the process for turning off bootstrap form validation?

I am facing an issue with utilizing the default input email validation in my development project. It seems that Bootstrap, which is being used for the website, has its own validation mechanism. Whenever I begin typing in a Bootstrap input field, an error m ...

React Router V6 - page is not found in browsing history

Currently, I am encountering an issue with react router v6. While on the detail page, if I press the arrow in Chrome to go back to the previous page, it takes me to the page before the previous one. I checked the history by long pressing on the back arrow, ...

Here's the secret to completely getting rid of emoji as symbols

I'm facing an issue with using a regular symbol (specifically the up-right-arrow) in a Wordpress menu. When I paste the symbol character into the required field, it shows up correctly on desktop but on my iPhone, it displays as an emoji rather than th ...

Python script causing Bottle window.location.href to become unresponsive

I am working on a project to control a servo motor using buttons on a RaspberryPi web server. Python and Bottle are the languages and framework I am using. So far, my progress has been slow, as I can only manage to have the buttons redirect to '/false ...

Adjust the overall cost according to the quantity using jQuery or JavaScript

I'm currently working on a project that involves input fields for Product Price, Quantity Form Field, and displaying the Total price. My goal is to have the Total price automatically update based on the product price and quantity with jQuery. I am loo ...

Shooting star css animation featuring pre and post effects

Trying to create a falling star using CSS animation. I made a star with a pseudo element, but I'm having trouble setting the animation in the pseudo-element. i{ position: relative; width: 0; height: 0; border-left: 12px solid transpa ...

Tips for Effectively Declaring a Variable with React's useState

How should I correctly specify variable types in useState? In the code below, the value for alert must be either "success","warning", "error", or "info" const [alertValue, setAlertValue] = useState("error" ...

Fixing a ternary conditional statement in React Redirect based on the web token

I am attempting to verify the presence of a token in local storage. If a token is found, I want to navigate to the corresponding component; otherwise, I need the page to redirect to the login page. By manually changing "authTokenhas === true" to "authToke ...

Angular's ng-model is unable to access the value of an object array

When selecting the days, users should be able to input check-in and check-out time ranges dynamically. However, there seems to be an issue with retrieving the values and data format. The ng model is unable to capture the check-in and check-out values. The ...

Go back to the top by clicking on the image

Can you help me with a quick query? Is it feasible to automatically scroll back to the top after clicking on an image that serves as a reference to jQuery content? For instance, if I select an image in the "Portfolio" section of , I would like to be tak ...

Strategies for optimizing PPI and DPI in responsive design

Imagine having two monitors: one 15.5 inches with a resolution of 1920 x 1080 and the other 24 inches with the same resolution. The first monitor has a pixel density of around 72 PPI, while the second has around 90 PPI. If I apply a media query in CSS for ...

Can this be achieved solely with external URLs and not local ones?

I'm currently facing an issue while trying to create a photo gallery using react-images. Despite having the correct URLs, the photos are not loading on my web app. Every time I switch modalIsOpen:false to true, I encounter the broken image icon. I ha ...

Is it possible to permanently alter HTML values with JavaScript?

Can a html value be permanently modified using javascript? I am trying to edit a local file. Below are the codes I'm using: function switchPic(){ top.topPage.activeDef = top.topPage.document.getElementById('h1'); top.topPage.activeDef. ...

Toggle the visibility of the navigation bar in Angular based on the user

I have implemented rxjs BehaviorSubject in my login page to transmit data to auth.service.ts, enabling my app.component to access the data stored in auth.service.ts. However, I now require the app.component to detect any changes made to the data in auth.se ...

Add the unique identifiers of objects to an array when a checkbox is selected within a React.js Functional Component

I am working with an array where I need to add the object IDs when a checkbox is checked, and remove the IDs when the check mark is removed by an admin. <Form.Label>Select Package/s:</Form.Label> {packages.map((item) => ( <Form.Check ...