The primary content division is trapped behind the side navigation bar

Why is my sidebar fixed on the left of the screen overlapping with the main content? I want the main content to be displayed next to the navbar and scroll up and down while keeping the nav bar in place, but no matter what styling I apply, it doesn't work. How can I make the main content div appear beside the navbar?

App.js

  return (
    <div>
      {
        authUser ? <>
          <BrowserRouter>
              <Sidebar>
                <Routes>
                  <Route path="/" element={<Dashboard/>} />
                  <Route path="/dashboard" element={<Dashboard/>} />
                  <Route path="/analytics" element={<Analytics/>} />
                  <Route path="/userbase" element={<Userbase/>} />
                  <Route path="/about" element={<About/>} />
                </Routes>
              </Sidebar>
          </BrowserRouter>
        </>
        : 
        <div className='landing-page'>
          <SignIn />
        </div> 
      }
    </div>
    
    
  );
}

App.css

.landing-page {
    width: 100%;
    border: solid red 1px;
}

.btn-signin {
    width: 100%;
  }

.sign-element {
    width: 1000px;
}

Sidebar.js

    return (
        <div className="container">
           <div style={{width: isOpen ? "250px" : "50px"}} className="sidebar">
               <div className="top_section">
                   <h1 style={{display: isOpen ? "block" : "none"}} className="logo">Changed</h1>
                   <div style={{marginLeft: isOpen ? "50px" : "0px"}} className="bars">
                       <FaBars onClick={toggle}/>
                   </div>
               </div>
               {
                   menuItem.map((item, index)=>(
                       <NavLink to={item.path} key={index} className="link" activeclassname="active">
                           <div className="icon">{item.icon}</div>
                           <div style={{display: isOpen ? "block" : "none"}} className="link_text">{item.name}</div>
                       </NavLink>
                   ))
               }
               <button onClick={userSignOut}>Sign Out</button>
           </div>
           <main className="mainContent">{children}</main>
        </div>
    );
};

Sidebar.css

.link {
    display: flex;
    color: #fff;
    padding: 10px 15px;
    gap: 15px;
    font-size: 20px;
    align-items: center;
    text-decoration: none;
}

.active {
    color: black;
}

.mainContent {
    
}

.container {
    width: 100%;
    float: left;
}

.sidebar {
    background: #000;
    color: #fff;
    height: 100vh;
    width: 200px;
    transition: all 0.5s;
    position: fixed;
    z-index: 1;
    float: left;
}

.top_section {
    display: flex;
    align-items: center;
    padding: 20px 15px;
}

.logo {
    font-size: 30px;
}

.bars {
    display: flex;
    font-size: 25px;
    margin-left: 50px;
}

.link {
    display: flex;
    color: #fff;
    padding: 10px 15px;
    gap: 15px;
}

.link:hover {
    background-color: orange;
    color: #000;
    transition: all 0.5s;
}

.active {
    background: orange;
    color: black;
}

.icon, .link_text {
    font-size: 20px;
}

overlapping example: collapsed

overlapping example: expanded

Answer №1

To apply styling to the primary content division in CSS, utilize the following code snippet:

div.main-content {
     width: 75vw; /* presuming the adjacent division is 25vw wide */
     margin-left: 25vw; /* supposing the adjacent division is positioned on the left */
}

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

Updating the status of a checkbox array within the reducer to reflect changes made in the user interface

I've implemented something similar in React: const CheckboxItems = (t) => [ { checked: true, value: 'itemsCancelled', id: 'checkBoxItemsCancelled', labelText: t('cancellations.checkBoxItemsCancelled&apos ...

The Material UI FilledInput and OutlinedInput components cannot be located within the @material-ui/core library

I recently installed "@material-ui/core": "^1.5.1" and also added material-ui-chip-input@next to my project. When attempting to utilize the material-ui-chip-input component, I encountered an error stating that Module @material-ui/coreFilledInput and @mate ...

Ways to increase the font size of input text using bootstrap's css framework

I currently have a bootstrap textbox set up like this: <input type="text" class="span9" required name="input_text"/> My goal is to increase the height of my input box to 300px. The width, on the other hand, is being handled by span9. I utilized In ...

Using the arrow keys to navigate through a list of items without using jQuery

Exploring ways to develop a basic autocomplete feature without relying on third-party dependencies has been my recent project. So far, I have managed to populate a results list using an ajax call and complete fields with mouse onclick events for each optio ...

The type 'xxxx' is not compatible with the parameter type 'JSXElementConstructor<never>'

I am currently enrolled in a TypeScript course on Udemy. If you're interested, you can check it out here. import { connect } from 'react-redux'; import { Todo, fetchTodos } from '../actions'; import { StoreState } from '../red ...

Enhancing Material UI icons with a sleek linear gradient

Despite following the instructions in this post Attempting to incorporate a linear gradient into a MaterialUI icon, as per a comment's recommendation, I am unable to get it to work. I experimented with the idea that the icons could be considered text ...

Restrict modifications in Sharepoint 2013 to text only

Can content editors be restricted to only adding text on websites? I want to prevent them from using inline styling in HTML or buttons in the editor to add styles. I'm dealing with a few rebellious editors who like to get creative with colors and sty ...

Is your animation glitching due to axis restrictions?

I decided to create my own version of the Google Maps icon using Photoshop, and now I want to replace the current image with my duplicate when the link that wraps around both is hovered over. To achieve this, I used the position: absolute property to layer ...

Dynamic color changing AppBar in Material-UI while scrolling in a React application

I have been struggling to change the color of the material-ui Appbar component when scrolling. I am not sure if there is a built-in functionality for this or if 'useScrollTrigger' can be used in this case. Any guidance on how to achieve this woul ...

Ways to overlook concealed elements within a Bootstrap Button Group

Within my button group, there are 10 buttons. On certain screen widths, using media queries for responsiveness, I hide some buttons. The issue arises when the last button is hidden - the rounded edges of the succeeding visible button are not maintained. ...

What is the best way to implement a responsive layout in Bootstrap 5?

<body> <header> <nav class="navbar navbar-expand-md navbar-light" style="background-color:#f6b319"> <div class="container-fluid"> <div class="navba ...

How to Disable Scrollwheel in Google Maps Using React Library

Is it possible to deactivate the scroll wheel feature? I'm struggling with implementing this in google-maps-react. I attempted the following: defaultOptions={{ scrollwheel: false, }} and also this: MAP_OPTIONS = { scrollwheel: false, } Un ...

What is the reason that setState functions properly when parsing each key separately, but fails when passed as an object?

Currently, I am delving into the world of React and TypeScript, but I have encountered a problem when trying to pass an object with a specific type in order to update the state. For some reason, the state remains unchanged. My approach involves using the ...

Achieving vertical center alignment for the label and btn-group in Bootstrap

Is it possible to align other elements with the Bootstrap btn-group? <div class="btn-toolbar text-center"> <div class="pull-left"> <span class="glyphicon glyphicon-envelope " style="font-size:1.5em;"></span> < ...

When an absolute positioned element exceeds the right border of its relative parent, its width will be truncated

When position: absolute; divs are placed inside or around a position: relative; parent, their height and width are based on the size and length of the text they contain. However, if one of these divs extends beyond the right border of the relative parent, ...

Determine the reference type being passed from a third-party component to a consumer-side component

I recently came across this issue with generics when using forwardRef in React: Property 'ref' does not exist on type 'IntrinsicAttributes' Let me explain my situation: import React from "react"; interface ThirdPartyComponen ...

The content in the footer is not displaying correctly (Vuejs)

I recently developed a component with a title and a background color meant to cover the entire page, but it seems to have a top margin that I can't seem to remove. Additionally, I created a footer component that should always stay at the bottom of the ...

Prevent scrolling when popover is activated

I'm struggling to keep the 'Popover' component from Material UI fixed on the screen when it's open. The issue is that when I click to open the popover (https://mui.com/material-ui/react-popover/), it doesn't block the scroll and th ...

Sharing data between React JS components Passing information between different components in React JS

My NavBar.js component contains login information for the logged-in user. It displays "Welcome" along with the user details when the user is logged in. Now, I want to replicate this functionality in the ProductList.js component so that when a user posts a ...

Creating animations with an svg mask can be effective, however, it seems to only work properly

I have been experimenting with creating a transition effect using SVG masks and CSS. Initially, everything was working as intended, but after a few repetitions (usually 1 or 2, unpredictably), the transition effect would suddenly stop and become instantane ...