The component's width appears to be constrained by the use of display flex

I am currently working on a reactjs application that includes a header and another component. Initially, everything looks fine, but when I apply display: flex to their div, it seems to reduce the width of the header. Here are some images showing the issue: https://i.sstatic.net/98zr8.png

https://i.sstatic.net/RIHoM.png

Does anyone have any suggestions on how to fix this problem? Here is how the code is structured:

function App() {
  return (
    <div className="App">
        <div className="wrapper">
          <main>
            <Header />
          </main>
          <Player />
        </div>  
    </div>
  );
}

export default App;

Here is the CSS code:

*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
:root{
  --red: #990606;
  --black: #222224;
  --white: #f0f0f0;
}

@media (max-width: 1080px){
  html{
    font-size: 93.75%;
  }
}
@media (max-width: 720px){
  html{
    font-size: 87.5%;
  }
}

body{
  background-color: var(--white);
}

body, input, textarea, button{
  font: 500 1rem sans-serif;
}
h1{
  font-size: 2rem;
  font-family: 'VT323', monospace;
  font-weight: 500;
}
h2{
  font-size: 1.5rem;
}
button{
  cursor: pointer;
}

.wrapper{
  display: flex;
}

.wrapper.main{
  flex: 1;
}

Header JSX:

export function Header() {
    return(
        <header className="headerContainer">
         
        </header>
    )
}

Header CSS:

.headerContainer{
    background: var(--black);
    height: 6.5rem;
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 2rem 4rem;
    border-bottom: 1px solid var(grey);
}

And now for the player component:

export function Player() {
    return(
        <div className="playerContainer">

        </div>  
    )
}

Player CSS:

.playerContainer{
    padding: 3rem 4rem;
    width: 26.5rem;
    height: 100vh;
    background: var(--red);
    color: var(--white);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
}

Answer №1

To resolve the issue, simply take out the display:flex property from your .wrapper class.

You can view a demonstration of the solution here:

If you have any further questions or concerns, please feel free to reach out.

Answer №2

To resolve the issue, I implemented the flex grow property or used flex:1 in the code

.container{
  display: flex;
}

.container.primary{
  flex: 1;
}

The mistake I made was not realizing that main is not a class, so I should reference it differently in the CSS:

.container{
  display: flex;
}

.container main{
  flex: 1;
}

After making this adjustment, everything is now working correctly

Answer №3

Implementing Flexbox Wrapper with column direction
Visit : Explore...

.flex-wrapper {
    display: flex;
    flex-direction: column;
 }

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

AWS and Azure are encountering difficulties in successfully executing the build process for a React application

Fixed: The issue was that I had saved my 10400 objects of JSON data as a .js array, causing the build to take too long (I just didn't know how to handle JSON). Switching it to .json format resolved the problem. I developed a React app that functions ...

Tips for concealing elements beyond div boundaries

First and foremost, I want to mention that my focus is on studying frontend development, so I could really use some assistance with a task. I am looking to create a tab slider where the content on the left and right will flank it, ensuring the tab slider ...

Display the div only during the printing process

Imagine I have a situation where there is a block of content that I only want to show when printing. It looks something like this: <div id="printOnly"> <b>Title</b> <p> Printing content </p> </div&g ...

What is the best way to make jQuery not consider hidden elements?

Apologies for not sharing the code, as I know many of you prefer to see it. I am currently working on developing a comprehensive calculator for my small business, and I am aware that I am making several mistakes. I kindly request that you do not critique ...

Step-by-step guide on connecting to a MySQL database for Next.js using the .env file

const pool = mysql.createPool({ connectionLimit: 100, host: process.env.NEXT_PUBLIC_MYSQL_HOST, user: process.env.NEXT_PUBLIC_MYSQL_USER, password: process.env.NEXT_PUBLIC_MYSQL_PASSWORD, database: process.env.NEXT_PUBLIC_MYSQL_DATABASE ...

Can anyone help me troubleshoot the issue with my iconButton component in React JS?

My IconButton open tag in the console is showing an error as an unexpected token. I have already installed Material UI but I can't figure out what the problem is. Can someone help me with this? Thank you! This is my product.js: import React from &ap ...

What is the best way to center-align my list within the designated area?

I need help centering a two column list on my webpage. It's currently justified to the left. How can I adjust it? To see what I'm working with, check out my jsfiddle: http://jsfiddle.net/huskydawgs/c2yqmfzt/5/ <p> A banana is an edible fr ...

How can we refresh the React-query cache?

My app is pretty straightforward - it fetches a user and allows for changing their name. I use React query to fetch the user so I can take advantage of the cache feature, which works perfectly. However, when it comes to updating the user, I resort to a ty ...

Creating .ipa Files with React Native

Is there a way to generate .ipa files in React Native for iOS without using XCode or an Apple Developer Account? Many references have not been successful in helping me achieve this. I attempted to build from XCode, but encountered issues with provisi ...

Tips for breaking out of the traditional 12 column grid using Bootstrap 4 flexbox grid system

My excitement was palpable when I learned that Bootstrap 4 would be implementing flexbox for a grid system. I anticipated the fast and efficient element sizing capabilities that flexbox offers. However, it appears that Bootstrap 4 simply enhances the exist ...

Guide on dragging and dropping without losing the item, allowing for continuous drag and drop functionality

function allowDrop(ev) { ev.preventDefault(); } function drag(ev) { ev.dataTransfer.setData("text", ev.target.id); } function drop(ev) { ev.preventDefault(); var data = ev.dataTransfer.getData("text"); ev.target.appendChild(document.getElementB ...

Next.js optimizes the page loading process by preloading every function on the page as soon as it loads, rather than waiting for them to

My functions are all loading onload three times instead of when they should be called. The most frustrating issue is with an onClick event of a button, where it is supposed to open a new page but instead opens multiple new pages in a loop. This creates a c ...

Using masonry-layout with Next Js leads to a ReferenceError stating that window is not defined

Implementing the masonry-layout library by David Desandro in my Next app has been a smooth process. You can find the link here. When I apply it, the masonry layout functions perfectly as intended. Here's how I'm incorporating it successfully: imp ...

Tips for effectively utilizing the desktopModeMediaQuery feature in the MUI DatePicker

I need help understanding how to utilize the desktopModeMediaQuery feature from material ui. The only relevant link I found was about the Material UI responsive date picker. However, this did not provide specific instructions on how to use desktopModeMed ...

Struggle with bringing the foreground image to the forefront not successful

Looking to create a web page with a full-page image overlap? I've been struggling with my current code as the image is not displaying properly. If anyone has any tips or advice, it would be greatly appreciated! HTML Code <html> <head> ...

Is there a Pug file that can connect to a Websocket and show the incoming values?

Check out this basic pug file snippet: p Hello The back end consists of typical components such as node, express, passport, and sql. You can set up a route like this: app.get('/example', (request, response) => { response.render('exam ...

Is there a way for me to set distinct values for the input box using my color picker?

I have two different input boxes with unique ids and two different color picker palettes. My goal is to allow the user to select a color from each palette and have that color display in the corresponding input box. Currently, this functionality is partiall ...

Using PHPs nth-child in media queries

There are multiple images on MyPage, typically displayed in rows of 6. However, the number of images per row adjusts based on browser size using media queries. The issue arises with the margin set for the last image in each row, as the nth-child property r ...

Reacotron's presenting behaviors prior to sagas

I recently installed Reactotron and encountered an unusual error. Let me walk you through my process flow to help you understand the issue: 1.) The app is starting 2.) I dispatch an ON_START_APP action 3.) I utilize takeEvery to handle the ON_START_APP a ...

Exploration of Genetic Variants in the SWR Test

How can we effectively test mutation using SWR? function Index() { const { data, mutate } = useSWR("/api/user", fetch); if (data.loggedIn) { return ( <Button onClick={() => { logout(); mutate(); // ...