I have been having trouble getting the entire background to display in a specific color with Styled Components

It seems like a simple issue, but I just can't get the background to cover the entire screen. Even though I have provided the code I used, only a quarter of the top of the screen appears black when wrapping something in the component.

Here is the code snippet from Home.js:

import React from 'react'
import styled from "styled-components";
import Background from './images/Cryptid.png'

const Home = () => {

    return (

        <Container>
            <InnerContainer>
                <Logo />
                <JoinInfo><p>test</p></JoinInfo>
            </InnerContainer>
        </Container>
    )


}

const Container = styled.div`
display: flex;
height: 100%;
width: 100%;
background: black;
background-size: cover;
`;

const InnerContainer = styled.div`
height: 100%;
width: 100%;

`;

const Logo = styled.div`
border: 1px solid red;
margin: auto;
padding: auto;
height: 100px;
width: 400px;
background-image: url(${Background});
    `

const JoinInfo = styled.section`
color: white;
`
export default Home;

Answer №1

To make the entire screen have a background color, you can simply set the background color for the HTML body element:

import { createGlobalStyle } from 'styled-components'

const GlobalStyle = createGlobalStyle`
  body {
    background: blue;
  }
`

const <MainPage> = () => 
  <GlobalStyle />
  <Header /> {/* example of other main components */}
</MainPage>

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

Issues with div placement arise when incorporating relative positioning and floats

I have been attempting to position two divs with images next to the other divs but they appear underneath them instead. Can someone help me figure out what I am missing? FIDDLE CSS #main { margin: 0 auto; } #header { clear:both; float:left; ...

Interact with a webpage element using Selenium

My goal is to extract information from the following page: I want to interact with each blue stats icon on the page (one for every match of the tournament). Below is the code I am using: from selenium import webdriver from selenium.webdriver.common.by im ...

Refresh the table following the removal of an item

I am currently working on displaying server data in a table. The delete function is functioning properly, but the deleted item only disappears from the table after refreshing the page. Is there a way to trigger a re-render of the component after deleting a ...

Tips for incorporating css @keyframes within a cshtml file:

My cshtml page includes a Popup that I created, but I encountered an issue with keyframes. When I tried to use it without keyframes, the fade effect was lost. I am looking for a way to fix my @keyframes. (I tested the code on Chrome and Opera) I found the ...

"Unexpected behavior: datatables.net plugin causing left menu to be hidden behind table in Internet

My webpage was functioning perfectly in Internet Explorer. I decided to enhance it by incorporating the impressive jQuery plugin Datatables. I added the following code in DOMReady: $('#articlestable-container table').dataTable({ "bPaginate ...

Utilize React Material to ensure the table is well-suited for the page

I am looking to create different subpages: https://i.sstatic.net/FOy96.png https://i.sstatic.net/hS6FE.png Here is a complete code example: https://stackblitz.com/edit/react-qvzw66?file=src%2FBusinessDetails.js Main page: const useActiveAccountStyles ...

Error encountered when attempting to build Reactjs using the npm run command with

Issue Explanation I am working on a React project where running the command 'npm start' works fine. However, when I try to execute 'npm run build', I encounter the following error: verbose node v12.16.3 verbose npm v6.14.4 ...

Is there a more secure alternative to using the risky eval() function? Do I need to take the lengthier route by implementing a switch case instead?

I've been practicing and honing my Javascript skills by working on a calculator code that initially had lots of repetitive lines. I managed to simplify it, but I am aware that using the eval() method is not generally recommended. let current = 0; f ...

Creating a single page application in Angular2+ using JSON data

I am looking to create an Angular JS application using the provided JSON structure: { name: 'App Name', pages: [ { name: 'Home', url: '/', layout: { type:'HTMLElement' tag:'div ...

Issue with React Components Displaying LocalStorage List

I have been developing a React application that features an Input component, a Select component for form input, and a List component to display the stored data. Upon form submission, the data is saved in local storage. My issue arises when attempting to re ...

Changing the React Navigation header based on the screen displayed

I am working with a StackNavigation and I want to have a default Header (component Header) that will be applied to the "deep pages". These deep pages should show the default header generated for the React Navigation. In my index page **Index**, I only wan ...

The header one tag does not wrap around content when the window size is adjusted; instead, it

I have been struggling to position my page title in the center of the header image both horizontally and vertically on my portfolio pages. I managed to get the h1 title where I want it but now I need to make it larger. The issue arises when I resize the wi ...

Should component did update always be called upon creation?

Often, I catch myself writing code that resembles the following structure: class MyComponent extends Component { constructor(props) { super(props); const {foo, bar, fetchFoo, fetchBar} = props; if (!foo) { fetchFoo(); ...

In VueJS, where specifically do you typically look to catch emitted events?

Let's set the stage: export default Vue.extend({ name: 'Home', computed: { ...mapState('user', ['card']), }, created() { this.fetchData(); }, mounted() { this.$once('dataLoaded', () => { if ...

Is there a practical limit for uploading HTML files?

We are currently working on an internal web application and need to find a way to upload a very large file (100mb). Can an HTML file upload handle this size or do we need to consider other options like Java applets, Silverlight, or Flash? Is it even feasi ...

Navigate to the anchor element within the webpage that contains adaptive images

My Bootstrap 4 page contains responsive images and anchor tags within the text. .img-fluid { max-width: 100%; height: auto; } Once I navigate to this page by clicking a link (e.g., 'mypage#section-one'), the page initially loads on the ...

Removing classes from multiple elements on hover and click in Vue 2

Can Vue be used to remove a class from an element? I am looking to remove the class when hovering over the element, and then add it back once the mouse is no longer on the text. Additionally, I want the class to be removed when the element is clicked. He ...

Not all dynamic content is loaded through Ajax requests on a single domain

I currently have my domain forwarded (cloaked) to The main page (index.html) utilizes Ajax for loading content. All content loads properly at the original host (moppy.co.uk/wtcdi). However, on the forwarded domain (whatthecatdragged.in), some content fai ...

Adjustable table region in PHP

I need help with displaying multiple results in a dynamically created table within my program. Even though I want to show around 25 records, the program cuts off after the 5th record, leaving empty space. The issue seems to be that the area does not expand ...

Receiving a response from a Node.js server using an AJAX GET request

Here's a snippet of code from app.js that retrieves an aggregated value from mongo.db. I'm attempting to use this response value on my HTML page by making an AJAX call. However, I'm facing an issue where I can't retrieve the value in my ...