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

What is the method to establish the table format in HTML using several for each loops?

I need to arrange the table structure for product plans as follows: +------------------+---------------+---------------+ | product1 | product2 | product3 | +------------------+---------------+---------------+ | product1plan1 | product ...

Customize the List Box Appearance for a Specific HTML Item (Option)

I am working on achieving a specific behavior. When using a listBox (or comboBox), the first element (such as "choose one") should have a unique style. Here is an example of code to test: <style type="text/css"> .testX {font-style: italic;} </ ...

calculation of progress bar advancement

I want to make the progress bar in my game responsive to changes in the winning score. Currently, it moves from 0% to 100%, which is equivalent to 100 points - the default winning score. But I need the progress bar to adjust accordingly based on the user-i ...

Issue with uneven spacing on both ends of the screen on mobile devices

I have successfully used a <div style="margin:0 auto; "> tag with the specified property, working perfectly. However, I added another <div> above and set the float as follows: .gallery-div{ background:url(images/gallery-bg.png) repeat-y; ...

Transferring information from a React form to an ExpressJS backend and then seamlessly redirecting to the PayuMoney platform for secure payment processing

Challenge Overview : I am currently working on the integration of payuMoney in a website built with ReactJS, NodeJS, and Express. The goal is to create a form where users can input their data, and then pass this information to the backend API located in in ...

Interacting with JQuery UI Button causes it to shift position on mouseover

In my table, there are two large cells. The left cell contains two drop-downs and a JQuery UI button that is causing trouble, while the right cell displays a list generated from an AJAX database query. As the list grows longer, the button gradually moves u ...

Ensure that the Popover vanishes upon scrolling the page - Material UI (MUI) v5 compatibility with React

When implementing the MUI v5 standard pattern for displaying a popover upon hovering over another element, everything works smoothly except for one scenario: If you hover over the element And without moving the mouse, use the scroll wheel to scroll throug ...

Top method for setting a cookie in the App router server component using NextJS

I am faced with a task that involves updating a flag in the database and creating a cookie with a 5-minute expiry time whenever a page is loaded. Furthermore, upon subsequent page loads, I need to check if the cookie has expired, update the flag, and gener ...

Invoke multiple dispatch once axios response is received in Redux

I'm facing an issue where I need to call multiple dispatches after receiving the response from axios. Currently, my approach only allows me to send one dispatch and when I attempt to fire a second dispatch, it throws an error stating that the response ...

The Laravel error message "Attempting to access 'index()' on a null object"

After generating a model in Laravel, I attempted to migrate the table using 'php artisan migrate', but encountered an error message on the terminal: "Call to a member function index() on null" ...

The style of the button label does not persist when onChange occurs

Encountered an interesting issue here. There is a button designed for selection purposes, similar to a select item. Here's the code snippet: <button class="btn btn-primary dropdown-toggle" style="width: 166%;" type="button" id="dropdownMe ...

Protecting against overflow for text inside a container that changes when hovered over

There is text displayed on top of an image within a div container that functions as a link. <a href="https://link.com" style="color:white"> <div class="thumbnail"> <img src="image.jpg" clas ...

Utilizing FontAwesome Icons in React Input Placeholder

Currently, I am developing an app using React and I am eager to incorporate FontAwesome icons into the input placeholder. My desired outcome is to have it appear like this: <input type="text" placeholder="[here should be the user icon] Username" /> ...

Differences in typography across Mozilla Firefox and Internet Explorer

I have come across a question that seems quite common, yet unsolvable. However, I will give it a try anyway. Take a look at this image: To view a larger version of the image, visit the following URL: https://i.stack.imgur.com/dddNm.jpg HTML code: <d ...

When using React Material UI Table to spread a detail line over 2 rows, a warning may appear: "Warning: Each child in a list should have a unique 'key' prop."

I am working on formatting my table in a specific way: EVENT ID EVENT NAME DATE LOCATION 12345678 Rolling Stones 01/01/2024 Merriweather Post Pavillion Rain or shine! No weapons or alcohol will be permitted 1234567 ...

Converting text into HTML format using Nextjs and React

Currently, I am working on a project that involves using Next.js and React. I am considering creating my own component to parse text based on certain conditions, but I am unsure if something similar already exists. My goal is to: Format the content in HT ...

Learn the easy steps to exporting all the pages to CSV format using MUI DataGrid

I'm working with a DataGrid table from Material UI that has over 3000 rows, with a maximum of 50 rows per page. My goal is to export all rows to CSV when I click the export button. Current issue: Only data from the current page is being exported Co ...

Removing scrollbar from table in React using Material UI

I successfully created a basic table using react and material UI by following the instructions found at: https://material-ui.com/components/tables/#table. The table is functioning properly, but I am finding the scrollbar to be a bit inconvenient. https:// ...

Assigning value to a state within a map function of a reducer: A guide

Attempting to retrieve the type value of a clicked card and I am expecting to extract the type of that card. The state.memoryCards shows the following output in the console: 0: {name: "Aircraft", type: "200", maxSpeed: 880, imageName: "a1", …} 1: {name ...

How can I dynamically set the width of a span element in HTML?

Hello there! As a beginner in html and angularjs, I'm experimenting with dynamically assigning span width based on an angular js response. <div class="statarea" ng-repeat="x in names"> <div class="ratingarea"> <div class=" ...