Guide on effortlessly cropping images that exceed screen height in React Bootstrap

Currently, I am working on developing my personal website with a vision of featuring a captivating picture slideshow using a Carousel tool. My goal is to place this slideshow in the rightmost 10 columns of the screen where the images will occupy the full width but only the height of the screen itself. To maintain the aspect ratio of the images, I intend to cut off any parts that exceed the screen's height. Although I have made progress, the issue lies in correctly controlling the image height to avoid it extending beyond the screen.

I've experimented with adjusting the max height and view height properties for the images, rows, and columns in various ways, yet I can't seem to achieve the desired result.

Below is the code snippet for the carousel:

import React, { Component } from 'react'

import Container from 'react-bootstrap/Container'
import Row from 'react-bootstrap/Row'
import Col from 'react-bootstrap/Col'

import Carousel from 'react-bootstrap/Carousel'
import Image from 'react-bootstrap/Image'

import img1 from '../assets/Home/img1.jpg'
import img2 from '../assets/Home/img2.jpg'
import img3 from '../assets/Home/img3.jpg'


export default class Home extends Component {
    render() {
        return (
            <Container fluid>
                <div className="vh-100">
                <Row className="row">
                    <Col className="col-2"></Col>
                    <Col className="col-10 px-0 align-items-start">
                        <Carousel>
                            <Carousel.Item>
                                <Image className="mh-100" src={img1} fluid />

                                <Carousel.Caption>
                                    <h3>First slide label</h3>
                                    <p>Description of image.</p>
                                </Carousel.Caption>

                            </Carousel.Item>

                            <Carousel.Item>
                                <Image className="mh-100" src={img2} fluid />

                                <Carousel.Caption>
                                    <h3>Second slide label</h3>
                                    <p>Description of image.</p>
                                </Carousel.Caption>
                            </Carousel.Item>

                            <Carousel.Item>
                                <Image className="mh-100" src={img3} fluid />

                                <Carousel.Caption>
                                    <h3>Third slide label</h3>
                                    <p>Description of image.</p>
                                </Carousel.Caption>
                            </Carousel.Item>
                        </Carousel>
                    </Col>
                </Row></div>
            </Container>
        )
    }
}

If you have any insights or guidance on fixing this issue, it would be greatly appreciated. Thank you!

Answer №1

In my case, I decided to forego trying to customize the style using react-bootstrap and opted for using pure CSS to adjust the image appearance:

img.slide {
  width: 100%;
  height: auto;
  object-fit: cover;
  max-height: 100vh;
}

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

Adjusting the dimension of a bootstrap button based on a value using React

Just getting started in the world of React and could use some assistance achieving this specific design: https://i.stack.imgur.com/E8PAr.png The buttons/widgets displayed above represent a certain number of items. I'm looking to adjust the size of t ...

The inability to read the 'map' property of undefined is causing an error in the useQuery function

I've been utilizing the API calls from , but I keep encountering an error message saying "Cannot read properties of undefined (reading 'map')." Below is the error message and code for reference: https://i.sstatic.net/UhO8U.png import React ...

Ever since the new update to [email protected], I have been unable to utilize any material-ui components

I encountered this error message in my console: Failed Context Types: Required context muiTheme was not specified in AppBar AppBar.js:158 Uncaught TypeError: Cannot read property 'prepareStyles' of undefined Although I have just an AppBar ...

Preventing style conflicts in react-native with styled-components

Attempting to customize the properties of a button in the calling component using styled-components, but encountering issues. The overriding of properties does not seem to be successful, and the button appears unchanged. The button is defined as follows: ...

The requested 'default' export (imported as 'LoadingButton') is not present in the module '@mui/lab/LoadingButton' (module does not have any exports available)

When trying to load buttons from MUI after running `npm install @mui/lab`, I encountered an error stating: "module has no exports". ...

Encapsulate every list item with a <ul> tag using jQuery

Not going into specifics, I've written some jQuery code like this: $("nav ul ul").each(function () { var navitems = $(this).html(); alert(navitems); }); I understand that .html uses InnerHTML so the alerts display as follows: <li>xxxx ...

Navigation menu with submenus containing buttons

I attempted to incorporate a dropdown into my existing navigation bar, but unfortunately, the dropdown content disappeared after adding the necessary code. I am now at a loss on how to troubleshoot this issue and make the dropdown function properly. Despit ...

Tips for removing a particular slide from bootstrap carousel with JQuery

I'm a beginner when it comes to bootstrap. I have a Carousel with some slides that include a Decline button. When the button is clicked, I want to delete/remove that slide and move on to the next one. Can this be achieved using JQuery? I've been ...

Utilizing the Bootstrap Button Plugin within a table to emphasize various choices

Utilizing bootstrap table along with the bootstrap button plugin, I have managed to make the columns clickable. While this functionality works as intended for all columns in the tbody except for the first one. The header section (thead) functions correctl ...

Centered flex item with a flexbox grid underneath

Looking to create a layout with an intro section on the left side and a sidebar on the right within a container. Below the intro section, I want four divs evenly spaced like a grid. But I'm struggling with setting up this grid, possibly due to flexbo ...

I am looking to implement tab navigation for page switching in my project, which is built with react-redux and react-router

Explore the Material-UI Tabs component here Currently, I am implementing a React application with Redux. My goal is to utilize a panelTab from Material UI in order to navigate between different React pages. Whenever a tab is clicked, <TabPanel value ...

I am experiencing an issue wherein after using jquery's hover() function, the CSS :hover state is not

Following the jquery hover function, the css hover feature ceases to work. In my html, there are multiple svg elements. A jquery script is applied where hovering over a button at the bottom triggers all svg elements to change color to yellow (#b8aa85). S ...

The CSS styles can vary depending on the web browser being used

Require assistance with my CSS. I designed an HTML/CSS widget on Blogger using my own expertise, but now facing some issues. The trouble arises with the image on the front left in the code. While it displays correctly on Google Chrome, aligned with the te ...

Display a <button> element as a text hyperlink within a paragraph, ensuring proper wrapping and flow

I want to incorporate a link-styled <button> within a block of text while ensuring that it flows smoothly with the surrounding content. Although styling the button is straightforward and setting display: inline allows it to blend into the text flow, ...

The value of "asp-route-id" is dynamically determined through the use of

Hey there, I’m looking to dynamically pass a value from "codeDrink" to my controller using "asp-route-id" and Ajax in my ASP.NET MVC project. This is how I am handling it in my view: <p> <a id="deleteLink" asp-action="Delete& ...

Should values be passed as parameters from the component to the state, or should the status be accessed directly in the action creator

Within my project, I am faced with the dilemma of how to handle an action creator that relies on values stored in the application's state. The question at hand is determining the most effective approach to take. Initially, two possible solutions come ...

Achieve the deliciousness of delect functionality using jQuery with these simple steps

Hi, I have a Bootstrap form that is dynamically appended by jQuery when clicking a button. I would like to have the functionality where clicking on a trash icon deletes the form from the frontend. Attached below is a screenshot of the form that I want to d ...

What is causing the issue of buttons within certain div tags not functioning properly when sharing the same classes?

There seems to be an issue with buttons not functioning properly when they are placed inside specific HTML tags. They become unclickable, even in cases where: a. the classes assigned to them are identical to those of working buttons, and b. the enclosing ...

Inspect HTML elements using Jinja2 placeholders

I am a beginner in the world of web development, currently learning how to create Flask webapps. I am using Atom along with some addons like PreviewHTML to help me visualize live previews of my HTML code. However, I am facing an issue where I cannot see a ...

When I attempt to utilize the API, the JavaScript implementation of a <script src=...> element seems to interfere

Within one of my HTML files, I encountered the following line near the top: <script src="//maps.google.com/maps/api/js?key=apikey"></script> The API key is currently hardcoded in this file, but I would like to use a configuration option store ...