Tips for positioning content next to a sidebar using basic CSS

I'm having an issue where my content is being hidden behind the sidebar and I want the sidebar to stay fixed on the left side.

When I changed position:fixed to float:left in the CSS, it gave me the desired result but the sidebar isn't fixed when I scroll.

Here's my CSS:

.Navbar {
    width: 5%;
    height: 100vh;
    background-color: var(--bg-primary);
    position: fixed;
}

The complete code is as follows:

APP.js

import './App.css';
import Navbar from './components/Navbar';
import Topbar from './components/Topbar';

function App() {
  return (
    <div className="App">
      <Navbar />
      <Topbar />
      <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliq...
    
          <a href='lul' class="nav-link">        
            <AiFillHome color='white' size={45} />
            <span className="link-text">Home</span>
          </a>
        </li>
        <li className='nav-item'>
          <a href='lul' class="nav-link">        
            <CgProfile color='white' size={45} />
            <span className="link-text">Profile</span>
          </a>
        </li>
        <li className='nav-item'>
          <a href='lul' class="nav-link">        
            <FiBarChart color='white' size={45} />
            <span className="link-text">Charts</span>
          </a>
        </li>
        <li className='nav-item nav-item-last'>
          <a href='lul' class="nav-link">        
            <FiSettings color='white' size={45} />
            <span className="link-text">Settings</span>
          </a>
        </li>
      </ul>
    </nav>
  )
}

export default Navbar
.Navbar {
    width: 5%;
    height: 100vh;
    background-color: var(--bg-primary);
    position: fixed;
}

.navbar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
}

...

a:visited { 
    text-decoration: none;
    color:White; 
}

Answer №1

When your navbar is set to position: fixed;, it may cause text to appear behind the navbar. To address this issue, consider creating a separate div with class page-content for all content except the navbar. You can then apply the following CSS:

For example:

.page-content{
    padding-left: 30px;
}

The padding-left property will shift the content on the website to the right, excluding the navbar. While there may be minor responsive challenges later on, these can easily be resolved by adjusting the padding.

Although I cannot guarantee that this solution will work perfectly for your situation, it's worth giving it a try. :D

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 there a more efficient method for replacing all attributes on cloned elements?

While this code does the job, I can't help but feel like it's a bit outdated. I'm not very experienced with JS/JQuery and only use them when necessary. My approach involves cloning an element and then replacing all of its attributes with on ...

How to position two divs in a row using Bootstrap

Looking at the output below: https://i.stack.imgur.com/pQM8F.png The blue circle is placed in one div, while the text is in another. I'm perplexed by why the first div appears on top and the second doesn't seem to align properly. Here's th ...

Incomplete Website Encryption Alert

Currently, I am developing a website called "usborroe.com" and have just set up a GeoTrust Business ID SSL Certificate. However, despite my efforts to ensure full encryption on the site, an error message is indicating that it is not fully encrypted and t ...

What is the method for automatically scrolling down while hovering over an image?

How can I make it so that when an image is hovered over, it automatically scrolls to the bottom of the image? I have a couple of questions: How can I ensure the image scrolls to the end when hovered over? Currently, when I hover over the image, it doe ...

Have you ever wondered how to disable a tooltip in React Material UI after clicking on it? Let

I am working with a Material-UI tab component and I would like to include a tooltip feature. The issue I am facing is that the tooltip does not disappear when I click on the tab. It should hide after clicking on the tab. Currently, the tooltip remains vi ...

Utilize MUI styles on elements that are not originally styled by MUI

I am working on a Gatsby application that utilizes MUI v5 and allows users to input custom markup. I want the user-entered markup to have the same base styles as the corresponding Typography elements (as shown below). How can I make this happen? It is wor ...

How come the props aren't being passed from the parent to the child component? (React / TypeScript)

Learning TypeScript for the first time and facing an issue with passing props from parent to child components. The error seems to be related to the type of props, but I'm not sure how to fix it since all types seem correct. Error message: "Property ...

Working with Firestore database in React Js may result in an infinite loop

I have connected my React JS app to Cloud Firestore and I am facing an issue with displaying the objects in my JavaScript file. Even though I only have one object in Firestore, it seems to be reading in a loop and I can't seem to identify the cause. ...

How to Toggle Expand and Collapse Feature for Material-UI Components in React

My table features expand and collapse functionality using material-ui, which is working perfectly. However, I am looking to update it so that only one expand/collapse section is open at a time when clicked. const InvoiceInfo = ({el}) => { const [open, ...

Encountered an error with "Unexpected token import" while attempting to run pm2 on my React application deployed on a Digital

As I attempt to deploy my application on DigitalOcean and run it with pm2, I encounter the following error: /home/bcavenagh/social/src/index.js:1 (function (exports, require, module, __filename, __dirname) { import React from 'react'; ...

Creating consistency in tab spacing within a text area

At the moment, I am utilizing an HTML textarea attribute to collect input from users and then displaying that text back to them formatted. However, there seems to be an issue with how it handles tabs. For instance, when attempting to input the following: ...

Using htaccess to redirect all html pages to php except for one

My website is configured to redirect all html pages to php using htaccess rules: RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^website.com RewriteRule (.*) http://www.website.com/$1 [R=301,L] RewriteRule ^(.+)\.html$ http://www.website.c ...

When sending a file to a node.js/express.js server using jsPDF, the file is being saved without an

My React component is designed to collect user data and use it with jsPDF to create a downloadable PDF file. let doc = new jsPDF(); doc.save() Everything works smoothly, and the file is saved with the .pdf extension as expected. The challenge arises when ...

Problem with React Material UI syled-engine resolution inconsistency during test execution (Functions properly during serve/build process)

Currently, I am utilizing Material UI components from mui.com with styled-components instead of the default emotion library. I have made changes to my tsconfig.json file to include: "compilerOptions": { ..., "paths": { .. ...

Exploration of jQuery Dropdown Menus

Encountering a problem with my dropdown menu. Check out the code here: http://jsfiddle.net/xY2p6/1/ It seems like a simple issue that I can't figure out, but as shown in the link, the functionality is not working properly. I need help linking the hid ...

Running a <script> tag with an external src attribute in a dynamic manner through the use of eval

Currently, I am utilizing the Genius API to fetch lyrics for a particular song and then embed them within an HTML <div> tag. My interaction with this API is through PHP, employing an AJAX GET request. Upon a successful AJAX request, the following HT ...

The art of sketching precise lines encircling a circular shape through the

What is the best way to use a for loop in JavaScript to draw lines around a circle, similar to those on a clock face? ...

Rendering HTML in special characters with AngularJS is an innovative way to display

My last question may have been unclear, but I received a similar response from the server asking for clarification. The HTML is not rendering properly here. How can this be resolved? AppControllers.controller('create', ['$scope',' ...

What could be causing my POST route to be missing in my MERN stack application?

I'm encountering two issues with a MERN stack application: i) Despite the POST route working, Axios fails to send form body data to the server. MongoDB only displays default field values after each submission. ii) The POST route was operational init ...

When loading HTML using JavaScript, the CSS within the HTML is not properly processing. Leveraging Bootstrap 5 might help resolve

Currently utilizing bootstrap 5 for my project. I have a setup in index.html where I am loading the contents of nav.html using JavaScript. However, I am facing an issue wherein the CSS styling for the navbar is not being applied when loaded via JS. Strange ...