SAndreeaM
SAndreeaM

Reputation: 99

Video background doesn't show on page

I'm having issues setting an mp4 as my background for a page. I tried importing LoginPage directly into App.js but it didn't work either, my page is blank. Here's my code:

App.js

import React from 'react';
import './App.css';
import Navbar from './components/Navbar';
import {BrowserRouter as Router, Routes, Route} from 'react-router-dom';
import Home from './components/pages/Home';

function App() {
  return (
    <>
      <Router>
        <Navbar/>
        <Routes>
          <Route path='/' exact component={Home}/>
        </Routes>
      </Router>
    </>
  );
}

export default App;

App.css

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'PT Sans', sans-serif;
  }

LoginPage.js

import React from 'react';
import '../App.css';
import './LoginPage.css';
import Extraction from '../img/extraction.mp4';

function LoginPage() {
  return (
    <div className='login-container'>
      <video src={Extraction} autoPlay loop muted />
      <h1>Login</h1>
      <p>Choose your fighter!</p>
    </div>
  );
}

export default LoginPage;

LoginPage.css

video {
    object-fit: cover;
    width: 100%;
    height: 100%;
    position: fixed;
    z-index: -1;
  }
  
  .login-container {
    height: 100vh;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: inset 0 0 0 1000px rgba(0, 0, 0, 0.2);
    object-fit: contain;
  }
  
  .login-container > h1 {
    color: #fff;
    font-size: 100px;
    margin-top: -100px;
  }
  
  .login-container > p {
    margin-top: 8px;
    color: #fff;
    font-size: 32px;
    font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande',
      'Lucida Sans', Arial, sans-serif;
  }

  @media screen and (max-width: 960px) {
    .login-container > h1 {
      font-size: 70px;
      margin-top: -150px;
    }
  }

  @media screen and (max-width: 768px) {
    .login-container > h1 {
      font-size: 50px;
      margin-top: -100px;
    }
  
    .login-container > p {
      font-size: 30px;
    }
}

Home.js

import React from 'react';
import '../../App.css';
import LoginPage from '../LoginPage';

function Home() {
  return (
    <>
      <LoginPage />
    </>
  );
}

export default Home;

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

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

Upvotes: 0

Views: 41

Answers (1)

Mujeeb Qureshi
Mujeeb Qureshi

Reputation: 500

Modify your Route to this:

<Route path="/" exact element={<Home />} />

Upvotes: 1

Related Questions