React component background image not fitting properly into the container when resizing the window


I have a problem with background image is not fitting properly inside the container element. The image is coming from an API call so I can only set the image inside the component and then I added styling in corresponding CSS file. The image is somewhat showing better on desktop but not properly at all on smaller screen.

Here is the link to my deployed app on GitHub pages:
Netflix Clone App

The problem comes when you click on individual movies and go to movie details page. Banner and thumbnail images in the description are the issues.


 useEffect( () => {
        const getMovie = async () => {
        const response = await fetch(`${baseUrl}/${}?api_key=${APIKEY}`);
            if (response.ok) {
                const data = await response.json();
                if (data !== null) {
            } else {
                const handleError = () => {
                    alert('Movie not found');
                    setTimeout( () => {
                    }, 1000);

    }, []);

    let moviePoster = movie.backdrop_path;
    if (moviePoster == null) {
        moviePoster = imageNotFound;
    } else {
        moviePoster = baseImageUrl + moviePoster;

    return (
        <div className="movie">
            <div className="banner"
                backgroundImage: `url("${moviePoster}")`
            <div className="movie_details">
                <div className="movie_image">
                    <img src={moviePoster} alt="Movie poster" />
                <div className="movie_overview">
                    <h1>{movie?.name || movie?.title || movie?.original_title}</h1>
                    <div className="more_details">
                            <p>{movie.release_date && `Release Date: ${movie?.release_date}`}</p>
                            <p>{movie.genres && `Genres: ${movie? genre => ' ' +}`}</p>
                            <p>{movie.runtime && `Runtime: ${movie?.runtime} minutes`}</p>
                            <p>{movie.vote_average && `IMDB Rating: ${movie?.vote_average}`}</p>
                    <button className="btn-back" onClick={() => history('/')}>Go Back</button>
.banner {
    padding: 100px 10px;
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center center;
    width: 100vw;
    max-width: 100%;
    height: 100vh;

>Solution :

The Problem is, that you set the banner as a Background. If the format of the window is wrong, it zooms into the middle of the picture.

I would change the div to something like this:

<img src="${moviePoster}" style="width: 100%">

Does this solve your problem ? Let me know in the comments.

Leave a ReplyCancel reply