Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encountering white-space at top of react-app

enter image description here

Image

encountering white space at top of the react-app

Check the image

There's weird whitespace occurring at the top of the react-app. My developed app not even a big react-app but there something occupying the space there and creating a white space there. I have deleted the old project and did this new one thinking it'll remove my error but the same result. I'm using a routing package to route through my app react-route-dom. I tried all the possible ways but couldn't find out the error or the line of code that is triggering the white-space at the top of the react-app. Please anyone help I have to submit my project!.

App.js

import React from 'react'
import './App.css'; 
  function App() {
  return (
   <div className="App">
    <h1>Hello</h1>
   </div>
 );
}export default App

App.css

.App {
 text-align: center;
 background: red;
 height: 30%;
 }

Index.js

        import ReactDOM from 'react-dom';
         import './index.css';
      import App from './App';
   import reportWebVitals from './reportWebVitals';
      import { BrowserRouter } from 'react-router-dom'
         const app = <BrowserRouter><App/></BrowserRouter>
           ReactDOM.render(
       <React.StrictMode>
         {app}
      </React.StrictMode>,
        document.getElementById('root')    );
       reportWebVitals()




**index.css**

  body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: #333;
}

code {
  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
    monospace;
}

like image 359
Abhinav peter Avatar asked Oct 18 '25 03:10

Abhinav peter


1 Answers

Add this to your index.css :

*{
 margin: 0;
 padding: 0;
 box-sizing: border-box; // not neccesary
}

This happens because chrome by default adds some padding to your page

like image 194
Gayatri Dipali Avatar answered Oct 20 '25 18:10

Gayatri Dipali