Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
Setting background image to full screen React

I am trying to set a background image to be full screen.

App.js:

import React from 'react';
import backgroundImage from './Resources/img.jpeg'

function App() {
  return (
    <div className="container"
    style={{ backgroundImage: `url(${backgroundImage})` }}  >
      <h1>Hello</h1>
    </div>
  );
}

export default App;

index.css

.container {
  height: 100%;
  background-size: cover;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  overflow: hidden;
}

index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <title>Weakly Scheduler</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
  </body>
</html>

The image is cut and shows only the part where the Hello is. if I add more of these then the images "reveals" more of its height. From this I think that the container itself is not full screened but I don't know why. The width is full screen as I want it to be. And ideas?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Update your style as follows:

.container {
  height: 100vh;
  width: 100vw;
  background-size: cover;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  overflow: hidden;
}
about 4 years ago · Juan Pablo Isaza Report

0

index.css

body, html {
    height: 100%;
    margin: 0;
    padding:0;
}

.container {
        width: '100vw';
        height: '100vh';
        background-image: `url(${backgroundImage})`;
        background-position: 'center';
        background-size: 'cover';
        background-repeat: 'no-repeat';
}

Or,

const containerStyle= {
        width: '100vw',
        height: '100vh',
        backgroundImage: `url(${backgroundImage})`,
        backgroundPosition: 'center',
        backgroundSize: 'cover',
        backgroundRepeat: 'no-repeat',
}

function App() {
  return (
    <div className="container"
      style={containerStyle} >
      <h1>Hello</h1>
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!