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:

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

Is it achievable to animate the offset with React Native Animated?

I am attempting to develop a dynamic drag and drop functionality, inspired by this example: My goal is to modify it so that when the user initiates the touch, the object moves upwards to prevent it from being obscured by their finger. I envision this move ...

Difficulty encountered while attempting to deploy the front-end on Heroku

I recently completed a typeorm project with the following structure: https://i.stack.imgur.com/ReQK1.png Both the client and root directories contain index files located in the src directory. In the package.json file within the client directory, I made a ...

Modify components in a web application based on the content of a JavaScript variable

I'm in the process of developing a webapp that needs to interact with an Arduino for its inputs in order to dynamically change the contents of the webpage. Currently, I am experimenting with variables that I have created and assigned random numbers t ...

The login form is experiencing issues with submission when utilizing the submitFormHandler in ReactJS

In my single-page application, I'm working on creating a separate login page that will redirect the authenticated user to the main application. However, I'm encountering an issue where my submitFormHandler is not being invoked. The purpose of aut ...

What seems to be the problem at hand, and where exactly is the issue located?

import React from 'react'; const card = ({name, email, id}) => { return( <div className='tc bg-light-green dib br3 ma2 grow bw2 shadow-5'> <img alt="robots" src = {'https://uniqueimage. ...

How to Remove Border and Shadow Below Header in React Native

In my react native app, I have a custom header that sits on top of another header to extend the height and add extra content. However, I'm facing an issue with a thin white border between them. I've tried using headerShadowVisible: false in the s ...

Utilizing a variable to pass props to a component (instead of a static component) within React Router 5

In react-router 5, you can pass props to a child component in this way: <Route path="/" exact render={ props => <MyPage title={myTitle} dataPath={myDataPath} {...props} />} /> However, I am using a route model in my ...

Having trouble establishing a default route with React Router v5

I am facing an issue with setting the default route to the home page in react router v5. Despite trying several methods, I cannot get it to work as expected. Index.js import React from "react"; import ReactDOM from "react-dom"; import ...

What is the best way to access the front camera on both Android and iOS devices in order to capture a photo using Vue.J

I am currently developing a PWA Vue.Js application and I am trying to implement a feature that allows users to take a picture with the front camera on their mobile devices. Although I have managed to write code that works on my desktop browser, I have bee ...

The functionality of the custom file upload button is experiencing issues on Microsoft Edge

I've been working on creating a unique custom image upload button that functions perfectly in Chrome, Firefox, and Opera based on my testing. However, I'm facing an issue where it doesn't work properly in Microsoft Edge. Feel free to check ...

Issue arises when trying to display a component located in a separate file upon clicking a button

I am currently working on a React website that features a navigation bar built with Material-UI. My main challenge lies in switching between different components, such as "About" and "Home", based on the user's selection from the navigation bar. As a ...

Toggle the visibility of a dropdown menu based on the checkbox being checked or unchecked

One challenge I am facing involves displaying and hiding DropDown/Select fields based on the state of a Checkbox. When the checkbox is checked, the Dropdown should be visible, and when unchecked, it should hide. Below is the code snippet for this component ...

Updating JQuery function after window is resized

click here Currently, I am using slick-slider to showcase content in 3 columns by utilizing flexbox. The aim is to have the slider activated only on mobile view. This means that when the screen size shrinks down to mobile view, the 3 column flexbox transf ...

Ways to prevent a background image from repeating in an HTML email without relying on CSS

I created a custom background picture, but when I tried to use it with CSS in Outlook, it didn't work. So, I added the picture directly into the body tag which allowed me to display it, but now it is repeating. Even after trying to prevent the repeti ...

When collapsing an accordion, Bootstrap radio buttons fail to properly select

I have attempted various methods to achieve the desired functionality of having the accordion content close and open accordingly when checking a radio button, while also having the button visually appear as 'checked'. For a more in-depth example, ...

What is the best way to close an ajax page within the main page using a button?

I am dealing with a situation where I have 2 pages. The first page contains a div called 'ajaxicall', which loads another page inside it. The challenge I am facing is figuring out how to close the second page when I click on the "close" button w ...

ng-class in Angular seems to be functioning properly on <td> elements, but is not

When using this HTML inside an ng-repeat, there is a difference in behavior: This part works fine: <tr> <td ng-class="info.lastInMonth">{{ info.date_formatted }}</td> ... But this section does not work as expected: <tr ng ...

The existence of useRef.current is conditional upon its scope, and it may be null in certain

I'm currently working on drawing an image on a canvas using React and Fabric.js. Check out the demo here. In the provided demo, when you click the "Draw image" button, you may notice that the image is not immediately drawn on the canvas as expected. ...

Navbar optimization by eliminating unnecessary whitespace at the end

I'm working on a navigation bar that has four links. I need to get rid of the extra space to the left of "Projects" and to the right of "Contact." It seems like this spacing is part of the unordered list structure, rather than padding or margin. Chec ...

Extract SCSS import filepaths using NPM and Gulp

Currently, in my gulp setup, I have several CSS files being produced - a general 'core' one, and then template-specific stylesheets. Instead of re-compiling all stylesheets with each change, the setup only compiles the necessary ones. However, t ...