What is the process for applying a background image to the entire screen within the app js file in a React js application

Hey there, I'm a newbie to react and I'm trying to create a login page with a background image. I have already set up a new login component in app.js but when I apply any CSS properties, it only affects the login component. What I really need is for the background image to cover the entire page.

Expected Output

Current Image

The code in my app.js file looks like this:

var sectionStyle = {
  width: "100%",
  height: "400px",
  backgroundImage: "url(" + ( Background ) + ")"
};

class Section extends Component {
  render() {
    return (
      <section style={ sectionStyle }>
      </section>
    );
  }
}

class App extends Component {
    render() {
                return (
            <div className="App">
                <Login /&>
            </div>
        );
    }
}

This is what my code in login.js file looks like:

render() {

        const { errors, formSubmitted } = this.state;

        return (

            <div className="Login"  style={divStyle}>
                <Row>
                    <form onSubmit={this.login}>
                        <FormGroup controlId="email" validationState={ formSubmitted ? (errors.email ? 'error' : 'success') : null }>
                            <ControlLabel>Email</ControlLabel>
                            <FormControl type="text" name="email" placeholder="Enter your email" onChange={this.handleInputChange} />
                        { errors.email &&
                            <HelpBlock>{errors.email}</HelpBlock>
                        }
                        </FormGroup>
                        <FormGroup controlId="password" validationState={ formSubmitted ? (errors.password ? 'error' : 'success') : null }>
                            <ControlLabel>Password</ControlLabel>
                            <FormControl type="password" name="password" placeholder="Enter your password" onChange={this.handleInputChange} />
                        { errors.password &&
                            <HelpBlock>{errors.password}</HelpBlock>
                        }
                        </FormGroup>
                        <Button type="submit" bsStyle="primary">Sign-In</Button>
                    </form>
                </Row>
            </div>

        )
    }
}

Would greatly appreciate any assistance or guidance on this matter.

Answer №1

I've successfully achieved the desired output you were looking for within the page's content.

import image from "../../assets/img/logo(name).svg";

render() {
    return (
        <div className="content" style={{ overflow: "auto"}}>
             <img id="logo-img" src={image} alt="logo" /> 
        </div>
   )
}

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

Using the ngClass directive to detect screen size breakpoints conditionally with Bootstrap classes

Hey there fellow developers! I'm wondering if it's possible to use ngClass with Bootstrap classes for detecting responsiveness based on screen size. For example, let's say I want to apply a specific class to my template when a particular vi ...

Ant Design is incompatible with React JS projects and cannot be effectively utilized

import React from 'react'; import styled from "styled-components"; import {Col, Row} from "antd"; const TitleBig = styled.div` font-family: "Bebas Neue Pro"; font-size: 20px; `; const TitleSmall = styled.div` ...

Storing a reference globally in React and Typescript: Best practices

In my application, I have multiple instances of a specific component called <Item>. Each <Item> needs to display a dynamic tooltip when hovered over. To achieve this, I am utilizing semantic-ui-react and its Popup component. The conventional m ...

The React state persists to reset back to its initial state consistently

Currently, I am developing a mobile signature feature for my website which involves three components: Form.js (the parent component using Formik for the form), Admin.js (a child of Form), and Signature.js (a child of Admin). Upon entering the Admin sectio ...

Sure thing: "Yes! Ways to confirm that out of multiple input text fields, only one is necessary

Utilizing React forms with yup validation, I have implemented a form with 5 input text fields. My requirement is that at least one field should be filled out, otherwise display the error message "Please fill at least one field." Below is the code snippet u ...

Determining the condition of the menu: understanding whether it is open or closed

I'm diving into the world of jQuery and JavaScript, trying to grasp the ins and outs of the mmenu API. Despite my efforts to understand the libraries, the JavaScript code remains a mystery to me. Following the tutorial provided on , I successfully cr ...

Using an image link in CodeIgniter will not function properly

Could someone please clarify why this particular code is not functioning properly in CodeIgniter? .linkBack{ background-image:url('/myBlog/CodeIgniter_1.7.2/pictures/arrow.gif'); display:block; height:58px; width:105px; text-indent:-999px ...

In ReactJS, organizing arrays within arrays for nesting purposes

Recently, I initiated a fresh project with React. I designed and brought in images by importing them: import Tip1 from "./img/Tips1.png"; import Tip2 from "./img/Tips2.png"; import Tip22 from "./img/Tips2-2.png"; ...

Obtain the DOM element for the Card Body in order to enable scrolling downwards

Currently utilizing ant.design and seeking to scroll the content of a <Card>'s body to the bottom. Two common solutions are available for achieving this. Insert an empty <div> at the bottom of the body and execute div.scrollIntoView() Ret ...

Issues with the disappearance of elements when using the Toggle() function

I've created a toggle feature for displaying a sub menu (.li-one) when clicking on the main menu (.ul-one). The issue arises when you click on another menu item, as the previous one does not disappear unless you click outside of the .main-nav div. Is ...

When the filter feGaussianBlur is applied to an SVG circle, it disappears on Safari but not on Chrome

While implementing the filter with feGaussianBlur to an SVG circle, I encountered a peculiar issue. It works perfectly on Chrome, but unfortunately, the circle disappears when viewed on Safari. https://i.sstatic.net/k916B.png https://i.sstatic.net/5Bfp9. ...

Deactivating Cluetip tool tips and adjusting the height limit in JQuery

How can I momentarily turn off the hints? I have seen references to being able to do so on the website and in this forum, but I am having trouble locating the command to disable them. I just need to temporarily deactivate them and then enable them again. ...

What is the best way to crop and edit a picture, incorporating rounded edges and a unique perspective?

Is there a way to create a unique design using HTML and CSS, where a div contains an image that is clipped and masked to achieve a specific look? Here's an example of what I'm aiming for: https://i.sstatic.net/nmDCp.png I've spent the past ...

What could be causing the content to disappear when switching from flex: column to flex: row?

In the code snippet provided below, you may notice that when the screen size is less than 768px, the video and content underneath it are visible. However, as soon as the screen size exceeds 768px, the video disappears. Have you ever wondered why the video ...

There is a lack of a responsive page after being redirected from Facebook

Having an issue with responsiveness on my website at . When I access a webpage from the browser on my smartphone, the site is fully responsive. However, when I try to open it from a link in Messenger, it appears like the PC version shrunk down to fit a mob ...

What could be the reason for the text not showing up?

I'm currently working on developing a "MEME Generator" but I've hit a roadblock at this stage. Whenever I: upload > Enter Text > Submit All of the JavaScript changes revert back to the default state. It seems like I might be overlooking s ...

Error: JSON data contains an unexpected token '<', which is causing a SyntaxError and making the JSON invalid

This PERN application is throwing an error that I have never encountered before, and after searching on Google, I couldn't find any relevant information. Upon reviewing the index.html file, everything seems to be in order: <!DOCTYPE html> <h ...

Establish and assign values for a collection of Material UI Autocompletes that retrieve options in real-time

I have a Material UI Autocomplete combo-box child component class that dynamically fetches results as the user types: ... fetchIngredients(query) { this.sendAjax('/getOptions', { data: { q: query } }).then((options) = ...

Encountering problem when attempting to incorporate fade in/fade out effect animation

I have a webpage that features multiple buttons, each triggering a fade-in/fade-out animation when clicked. This animation also involves changing the contents of a specific div. Though everything is functioning properly, there is a brief moment (about hal ...

What are some effective strategies for safeguarding confidential information, such as protecting it from potential threats like 'man in the middle attacks', when transmitting data between the Frontend and Backend systems?

I need to ensure the security of my confidential information (such as 'password') when sending it through requests. On the frontend, I am using React and on the backend, I am using MongoDB. Currently, I am storing a user's password in the ...