What is the best way to ensure that all of my images are the same size?

I've been working on making my pictures of varying resolutions the same size here, but no matter what I try, it just doesn't seem to work. Here is what I'm getting: . When I change the state to 1, 2, 3, or 4, I want it to look like this: here

import React, { useState } from 'react'
import './Styles/Slide.css'
import { images } from './sliderojects';

function Slide() {

    const [currImage, setCurrImage] = useState(1);

    return (
        <div className="slide-exterior">
            <div className="slide-interior" style={{ backgroundImage: `url(${images[currImage].img})` }}>
                <img src={images[currImage].img} />
            </div>
        </div>

    )
}

export default Slide

import room1 from './Media/room1.jpg';
import room2 from './Media/room2.jpg';
import room3 from './Media/room3.jpg';
import room4 from './Media/room4.jpg';

export const images = [
    {
        title: "Brasov",
        subtitle: "This is the beautiful Brasov",
        img: room1
    },
    {
        title: "Iasi",
        subtitle: "Come check out our city Iasi",
        img: room2
    },
    {
        title: "Suceava",
        subtitle: "The heart of Bucovina - Suceava",
        img: room3
    },
    {
        title: "Bucharest",
        subtitle: "Here you can see the biggest place in Romania",
        img: room4
    },
]
.slide-exterior{
    width: 70%;
    height: 500px;
    margin:auto;
    object-fit: cover;
    background-color: black;
    margin-top:20px;
}

.slide-interior{
    width: 100%;
    height: 500px;
    object-fit: cover;
    background-position: 50% 50%;
    background-repeat: no-repeat;
    background-size: cover;
    display: flex;
}

Answer №1

Here is a suggestion:
Use the objectFit attribute directly on the image tag

<img src={images[currImage].img} style={{ width: '100%', height: '100%', objectFit: 'cover' }} />

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

I am having issues with sendKeys and click() functions in my code. I am unable to access the elements using Protractor's javascript

<input class="form-control validation-field ng-dirty ng-touched ng-invalid" placeholder="Password" type="password"> Despite using the element to retrieve it, I am unable to send keys and no error message is displayed. This issue persists in both Fir ...

What are the best methods for rebooting a Node.js project?

As a developer with over 8 years of experience in PHP, I find myself needing to make changes to a live Node.js project, despite not being a Node.js developer myself. The task at hand is simply to change a payment gateway token, which should be a straightfo ...

Ensure that two div elements expand to occupy the available vertical space

I am looking to create a layout similar to the following: |---| |------------| | | | b | | a | |____________| | | |------------| |___| |______c_____| Here is the code I have so far: <table> <tr> <td class="leftSid ...

Performing a repeated action to choose each item from a dropdown menu

I attempted to streamline the process by creating id tags for each dropdown and implementing a loop to select each manufacturer without having to write an extensive amount of code. However, I encountered difficulties and was unable to find a solution. The ...

The requested resource lacks the 'Access-Control-Allow-Origin' header in a basic HTML form

Can someone help me understand why I keep encountering this error in my basic HTML form? I am attempting to display XML data on my website to showcase news stories, but unfortunately, I keep getting stuck with this persistent error. Any assistance would ...

Tips for displaying a child React component for a specific duration

One of the React components I have is called PopUpBanner, which is utilized to display messages. For instance, in my login component, I employ it in this manner. If an error arises, the bannerMessage state is updated to showcase the message on the banner: ...

MUI: tips for positioning text next to each other on a page

I need assistance aligning numbers and text side by side, similar to the image shown here: https://i.sstatic.net/gXzOM.jpg However, there is a margin to the right of the text(MASTER I 406), causing the numbers to not be in the correct position. Currently, ...

Invoking WinJS.Binding.List.createFiltered with an asynchronous call to the predicate function

Is there a way to wait for the async operation in this code snippet and use its result as the predicate instead of always returning false? return someList.createFiltered(function(item) { var filter = false; var ...

What is the proper way to specify a file destination in React?

After reading this article on downloading objects from GCP Cloud storage bucket, I'm curious about setting the file destination dynamically in React. Is there a way to achieve this? The article can be found at: https://cloud.google.com/storage/docs/do ...

Stop CSS tooltip from overflowing outside of the page or window

One issue I am facing is with a CSS-only tooltip that uses a span to display the tooltip when hovering over a link. The problem arises when the link is positioned near the top or side of a page, causing the tooltip to extend beyond the edge of the page. I ...

Creating a multi-level mobile navigation menu in WordPress can greatly enhance user experience and make

Hey there, I am currently in the process of developing a custom WordPress theme and working on creating a mobile navigation system. Although I have managed to come up with a solution that I am quite pleased with after multiple attempts, I have encountered ...

Upon launching the application, it will automatically update itself and then proceed to open its own interface

After successfully developing an application with react and electron, I encountered a strange issue during packaging. Once the app is open, a notification prompts an automatic update to version 3.0.2. However, upon relaunching the application, I am redir ...

In JavaScript, when you update the property of a nested object within an array, the changes will also be applied to the same property for

Encountered an interesting issue in my code where updating a single property of a nested object within an array of objects results in all similar objects having the same property updated. Snippet of the Code: let financials = { qr: { controlData: [ ...

When attempting to execute the "npm run start" command in a ReactJS environment, an error message appeared

'react-scripts' command is not being recognized as a valid internal or external command, able to use program or batch file. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] start: react-scripts start npm ERR! Ex ...

What is the best method for accessing a specific Data value on the route?

Hello everyone! This is my first time posting on Stack Overflow. I am currently working on developing an attendance management system for a school. In my database tables, I have the following fields: Registration: class_id, section_id, user_id. Attendanc ...

How come executing a function in the Node.js REPL using )( actually functions?

In JavaScript, why is it possible to call a function like this when tested with node.js: ~$ node > function hi() { console.log("Hello, World!"); }; undefined > hi [Function: hi] > hi() Hello, World! undefined > hi)( // Why does this work? Hell ...

Error message when using Vue Global Filter: Value undefined is not defined

Trying to format currency, I initially attempted to use a global filter in Vue: Vue.filter('formatMoney', (val) => { if (!value) return '' val = val.toString() return val.replace(/\B(?=(\d{3})+(?!\d))/g, ",") ...

What is the best way to position a div in the top right corner of my form using Bootstrap?

I have a form displaying some detailed text about elements in my application. Located outside this form is an "add new item" button that redirects the user to a new page for adding a new item. The current placement of this button is on the upper left corn ...

What is the best way to restrict editing on certain columns in a React Material Table?

import React from 'react'; import MaterialTable from 'material-table'; export default class DictionaryTable extends React.Component { constructor(props) { super(props); this.state = { columns: [ ...

Guide to redirecting on click when utilizing an iframe

I needed to prevent the page from reloading before the action was complete by using an iframe. However, I encountered an issue where I needed the page to refresh after the action took place. I attempted two methods to achieve this - refreshing the page and ...