Having trouble getting the background image to display full screen in ReactJS

Currently, I am venturing into the world of reactjs with an aim to create a seamless user experience by implementing login, register, and home screens through routing. Below is a snippet of my code.

import React from 'react';
import { render } from 'react-dom';

import { App } from './App/App.js';
import {Login} from './LoginPage.js';
import '../src/styles/homestyle.css';

// setting up fake backend
import { configureFakeBackend } from './_helpers/fake-backend.js';
configureFakeBackend();

render(
<App />,
document.getElementById('app')
);

Snippet of App.js focusing on routing.

import { HomePage } from '../HomePage/Homepage.js';
import { LoginPage } from '../LoginPage.js';
import { RegisterPage } from '../RegisterPage.js';
import { Details } from '../_details/Details.js';
import {styles} from '../styles/homestyle.css';


class App extends React.Component {
render() {
    return (
        <div className="login">

                    <Router>
                        <div>                            
                <PrivateRoute  path="/" exact component=    {HomePage} />
                  <Route  path="/login"  exact  component={LoginPage} />
             <Route  path="/register"  exact  component={RegisterPage} />
                        </div>
                    </Router>
                </div>

    );
}

Next, I'll share my login screen setup.

 render() {
    const { username, password,confirmpassword, submitted, loading, error } = this.state;
    return (
        <div className="innerdiv">
         <div className = "demo">
            <div className="movie-dcard">
                Username: test<br />
                Password: test
            </div>
            <h2 align = "center">Login </h2>
            <form name="form" >
            <div className={'form-group'}>
                    <button className={'form-group'} onClick = {this.handleRegisterClick} disabled={loading}>Register</button>
                    {loading &&
                        <img src="data:image/gif;base64,R0lGODlhEAAQAPIAAP" />
                    }
                </div>
            </form>
             <form name="form" onSubmit={this.handleSubmit}>
                <div className={'form-group' + (submitted && !username ? ' has-error' : '')}>
                    <label htmlFor="username">Username</label>
                    <input type="text" className="form-control" name="username" value={username} onChange={this.handleChange} />
                    {submitted && !username &&
                        <div className="help-block">Username is required</div>
                    }
                </div >
                <div className = {'form-group'+ (submitted && !confirmpassword ? 'has-error' : '')}>
                <label htmlFor = "confirmpassword">confirm Password</label>
                <input type = "text" className = "form-control" name = "confirmpassword" value = {confirmpassword} onSubmit = {this.handleChange} />
                {submitted && !confirmpassword &&
                        <div className="help-block"> confirm Password is required</div>
                    }
                    </div>
                <div className={'form-group' + (submitted && !password ? ' has-error' : '')}>
                    <label htmlFor="password">Password</label>
                    <input type="password" className="form-control" name="password" value={password} onChange={this.handleChange} />
                    {submitted && !password &&
                        <div className="help-block">Password is required</div>
                    }
                </div>
                <div>
                <div className={'form-group'}>
                    <button className="btn btn-primary" disabled={loading}>Login</button>
                    {loading &&
                        <img src="data:image/gif;base64,R0lGODlhEAAQAPIAAP" />
                    }
                </div>

                </div>
                {error &&
                    <div className={'alert alert-danger'}>{error}</div>
                }
             </form>
            </div>
        </div>
    );
}
}

Lastly, here's the CSS styling included:

   .movie-card {
    background-color: red;
    align-content: center;
    text-align: center;

  }
  .background {
    height: 100%;
    background-image: url("/images/background.jpg");
    -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
    }
    .login {
      background: url("http://web3canvas.com/wp-content/uploads/2014/02/littlevisuals-high-quality-hd-banner-images-stock-photos-free-laptop-topview-download.jpg") no-repeat; 
      -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
    }

.home {
  background: url("https://www.w3schools.com/cssref/mountain.jpg") no-repeat; background-size: cover;
  height: 100vh;
 width: 100vw;
}

.innerdiv {
  align-content: center;
  height: 20%;
 margin: auto;
 width: 50%;
 border: 3px solid green;
 padding: 10px;
}

However, I'm facing difficulty in achieving full-screen background images. https://i.sstatic.net/qOd93.jpg

If you have any tips on how to make it full screen while using different images for each page/screen, please do share!

Answer №1

A suggestion would be to include the following code in your main CSS file and adjust the height property to 100% for the main component:

html,
body,
#app {
    height: 100%;
}

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 it possible to utilize Bootstrap Icons as bullet points on a website?

Is it possible to use Bootstrap icons for bullet points with CSS? I am aware that FontAwesome can be used for this purpose, but I would like to confirm if the same can be achieved using Bootstrap. Though there is a method using: <ul> <li>< ...

How to create an image overlay in Angular with the help of Bootstrap

As a beginner in web development, I am utilizing Angular in conjunction with Bootstrap for a practice project. My goal is to create a header component and integrate it into my app.component. Within the app.component, I aim to have a background image coveri ...

Android browser experiences a sudden surge of unexpected data influx

I am facing an issue with my application where it maps an array from the state. The array should ideally only contain 6 sets of data, as limited by the backend. However, sometimes it spikes and displays data that is not supposed to be there or shows old da ...

Beginner attempting to comprehend Safari CSS font-size test outcomes

Currently, I am delving into the realm of CSS. To test my skills, I am making edits to an HTML file and previewing the outcome in Safari V11.0. My objective is to present an online version of a traditional printed report, complete with fixed columns and a ...

Positioning a full-width background-image in the center is causing the page to expand

I've been struggling to find a solution to this issue for hours, scouring the internet with no success. The problem I'm facing is trying to center a background image on the page. However, when using the method shown here, it ends up stretching t ...

Problems with spacing in Slick slider and lazyYT integration

Utilizing lazyYT helps to enhance the loading speed of YouTube videos. Once loaded, these lazyYT videos are then placed within a slick slider. However, an issue arises where the videos stick together without any margin between them. To address this problem ...

What is the best way to show HTML code on a REACT website without disrupting the existing styles?

I am trying to showcase the following code in a REACT webpage, but it is not displaying as code. Instead, it is showing as actual elements. How can I display the button codes below as actual code? <code> <pre> <Button className='btn-grv ...

Do you need to align images side by side and have clickable images positioned beneath each one?

After searching high and low, I couldn't find a similar question. My goal is to transform this from a vertical layout to a horizontal one: https://i.stack.imgur.com/4kZNM.png Check out the code snippet below: ghost<br class="newline"> <img ...

The time update in React Js is not showing on Material UI's DatePicker

Utilizing the Material UI KeyboardDatePicker in my application has proven to be quite tricky. When I select a date, the initial selection displays both the date and time correctly. However, after waiting for 1-2 minutes and selecting another date, the date ...

bootstrap for building responsive websites

I am trying to modify the width of an input from 100% to 50%, and position it in the center of the page so that it remains responsive when resizing the browser window. <!DOCTYPE html> <html> <head> <title>test</title&g ...

Determining the position coordinates of an element in relation to the viewport using JavaScript, regardless of its relative positioning

I am currently developing a vueJs web application and I'm in need of determining the position of an element within my web app relative to the viewport itself, rather than its parent elements. I'm curious if there exists a function or property tha ...

"Troubleshooting errors with React Query's useQuery hooks: a guide to better error handling in your

Below is a sample component that I have been working on. My goal is to fetch data from my Graphql endpoint using React Query. I have also included a custom hook that I am using in this component. const App =(props)=>{ if (me && me.token) { ...

implement a dynamic filtering system for products on a React webpage

My header component contains a filter list with categories like men, women, kids, etc. <span className="category" onClick={()=>{filter('men')}}>Men </span> <span className="category" onClick={ ...

Customize the color of the label and underline in a Reactjs material-ui TextField when the field input

https://i.stack.imgur.com/oJ2ah.png <TextField id="standard-full-width" label="Password" style={{ margin: 8 }} fullWidth margin="normal" placeholder="*******" /> Struggling to understand how to modify the color of the label ...

What can I do to improve the quality of the resolution?

Check out this demonstration on my website. I'm utilizing the jQuery cycle plugin to create a slider and ensuring that the photos maintain their full height and width. However, I've noticed that when I zoom in on the page, the picture doesn&apo ...

Stop material button from animating when clicked

On my webpage, I have created a unique button structure using Angular Material design: <button mat-button class="library-tile-button"> <button mat-button class="edit-library-button"> <img class="edit-library-img" src="..."/> ...

Creating an engaging Uikit modal in Joomla to captivate your audience

I need help optimizing my modal setup. Currently, I have a modal that displays articles using an iframe, but there is some lag when switching between articles. Here is the JavaScript function I am using: function switchTitleMod1(title,id) { document.g ...

Cross-Origin Resource Sharing policy does not include the 'Access-Control-Allow-Origin' header for AWS and Vercel

Currently, I am facing a minor issue with my API while using Express JS. I have deployed it on AWS and Vercel, and the problem persists on both platforms except for Heroku. All my GET and POST routes are functioning correctly. However, I encounter an erro ...

Struggling to integrate authentication and authorization features into a ReactJS application with Microsoft Azure AD or Database login functionality

We have an application built on React v18 with a backend that includes a Web API and SQL Server database. Our requirement is to authenticate and authorize users using either MS Azure AD or the database. If a user attempts to log in with a username and pas ...

The data retrieved from the Youtube API is not being saved in the useState variable

Having an issue with the YouTube API integration in my React app. The fetched data isn't being stored correctly in the useState variable, causing my VideoCard component not to render. How can I fix this and ensure the data is stored properly? import R ...