The sidebar I designed didn't completely extend across the column in Bootstrap

My sidebar in Bootstrap didn't fill the entire column because I forgot to set a specific width for it.

Here is the CSS code for my sidebar:

       .sidebar {
            position: fixed;
            /* top: 0;
            bottom: 0;
            left: 0;
            width:100%; 
            z-index: 100; */ /* Behind the navbar */
            background-color: #3A3735;
        }
    
    .sidebar-sticky {
        position: relative;
        top: 0;
        height: 100vh;
        padding-top: .5rem;
        overflow-x: hidden;
        overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
    }
    
    @supports ((position: -webkit-sticky) or (position: sticky)) {
    .sidebar-sticky {
        position: -webkit-sticky;
        position: sticky;
    }
    }
    
    .sidebar .nav-link {
    font-weight: 500;
    color: #ffffff;
    margin-bottom: 15px;
    }
    
    
    .sidebar .nav-link.active {
    color: #3A3735;
    background-color: #fff;
    padding-top: 5px;
    padding-bottom: 5px;
    border-radius: 30px;
    }
    
    .sidebar .nav-link:hover .icon-sidebar,
    .sidebar .nav-link.active .icon-sidebar {
    color: green;
    }
    
    .sidebar-heading {
    font-size: .75rem;
    text-transform: uppercase;
    }

Here is how my HTML structure looks like:

<div class="row">
    <div class="col-2">
      <nav id="sidebarMenu" class="sidebar">
        <div class="sidebar-sticky pt-3">
            <p class="d-flex justify-content-center align-items-center">
                <a href="#">
                <img src="img/logo-white.svg" alt="home">
                </a>
            </p>
            <ul class="nav nav-pills flex-column mx-4">             
        </div>
      </nav>
    </div>

    <div class="col-10">
    </div>
</div>

I am currently using Bootstrap version 4.6 and the full code can be found on GitHub:

CSS: https://github.com/gergerchan/testingfrontend/blob/feature/goal-dan-register/assets/css/sidebar.css

Sidebar: https://github.com/gergerchan/testingfrontend/blob/feature/goal-dan-register/views/partials/sidebar.ejs

Full HTML: https://github.com/gergerchan/testingfrontend/blob/feature/goal-dan-register/views/goal.ejs

Update: I have removed the position:fixed and replaced it with height:100%, but now when I scroll, the sidebar content also scrolls.

I am using Node.js, Express.js, and EJS as the view engine. Thank you in advance!

Answer №1

Could you please review the code snippet below? It is optimized to work efficiently for your needs. We have removed the position: fixed from the sidebar and inserted the row element in the parent container of the col-*

<!doctype html>
<html lang="en>

<head>
  <!-- Necessary meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3e5c51514a4d4a4c5f4e7e0a1008100e">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
  <style>
    .sidebar {
      /* position: fixed; */
      /* top: 0;
            bottom: 0;
            left: 0;
            width:100%; 
            z-index: 100; */
      /* Displays behind the navbar */
      background-color: #3A3735;
    }
    
    .sidebar-sticky {
      position: relative;
      top: 0;
      height: 100vh;
      padding-top: .5rem;
      overflow-x: hidden;
      overflow-y: auto;
      /* Allows for scrollable content if viewport is shorter than the content */
    }
    
    @supports ((position: -webkit-sticky) or (position: sticky)) {
      .sidebar-sticky {
        position: -webkit-sticky;
        position: sticky;
      }
    }
    
    .sidebar .nav-link {
      font-weight: 500;
      color: #ffffff;
      margin-bottom: 15px;
    }
    
    .sidebar .nav-link.active {
      color: #3A3735;
      background-color: #fff;
      padding-top: 5px;
      padding-bottom: 5px;
      border-radius: 30px;
    }
    
    .sidebar .nav-link:hover .icon-sidebar,
    .sidebar .nav-link.active .icon-sidebar {
      color: green;
    }
    
    .sidebar-heading {
      font-size: .75rem;
      text-transform: uppercase;
    }
  </style>
</head>

<body>
  <div class="row">
    <div class="col-2">
      <nav id="sidebarMenu" class="sidebar">
        <div class="sidebar-sticky pt-3">
          <p class="d-flex justify-content-center align-items-center">
            <a href="#">
              <img src="img/logo-white.svg" alt="home">
            </a>
          </p>
          <ul class="nav nav-pills flex-column mx-4">
            <li class="nav-item mb-2">
              <a class="nav-link active" href="#">
                <img src="img/sidebar/home.svg" class="mr-3 icon-sidebar" alt=""> Home <span class="sr-only">(current)</span>
              </a>
            </li>
            <li class="nav-item mb-2">
              <a class="nav-link" href="#">
                <img src="img/sidebar/check-circle.svg" class="mr-3 icon-sidebar" alt=""> Goal
              </a>
            </li>
            <li class="nav-item mb-2">
              <a class="nav-link" href="#">
                <img src="img/sidebar/clipboard.svg" class="mr-3 icon-sidebar" alt=""> To Do
              </a>
            </li>
            <li class="nav-item mb-2">
              <a class="nav-link" href="#">
                <img src="img/sidebar/calendar.svg" class="mr-3 icon-sidebar" alt=""> Calendar
              </a>
            </li>
          </ul>
        </div>
      </nav>
    </div>
    <div class="col-10">
    </div>
  </div>
</body>

</html>

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

Mixing without Collections

After initially posting this question yesterday, I realized that I needed to clean up my code before proceeding. However, for my assignment, I am required to create a JavaScript quiz where the questions and answer choices are shuffled every time a user ret ...

Ensure that bulleted lists and numbered lists are aligned to the left side

Check out this website where the ordered and unordered lists are not aligned correctly. The ideal alignment would have the bullets (or numbers) left aligned. For instance, the number "1." should be aligned to the left on the same line as the heading "Per ...

Trouble getting CSS and Javascript to bind when dynamically appending HTML elements

Attempting to dynamically bind HTML from an Angular controller SkillsApp.controller('homeController', function ($scope, $http, $q, $timeout) { $scope.getAllCategories = function () { $http({ url: "/Categories/GetAllCategories", ...

Is there a way to adjust the time font size according to the dimensions of the time picker?

HTML and CSS .pickthetime { height: calc(var(--vh, 1vh) * 3); width: calc(var(--vw, 1vw) * 25); align-content: center; // center looks better, also tried left to stop it from breaking a new line on Safari on iOS font-weight: 300; } <input cla ...

Is it possible for an Android webview to access the device's geo location?

For the application I'm working on, it's necessary to access the user's geo location. We've created a HTML 5 based website and are using a webview to develop our mobile application by calling the website URL. With the latest geo tags av ...

Unable to set the width for a div element within the bootstrap grid layout

When trying to set the width of a div tag to 100% within a bootstrap grid system (col-lg-3), I noticed that the div ends up taking the full width of the browser instead of just 100% of its parent(col-lg-3). .sidebar { color: #fff; f ...

Learn a valuable trick to activate CSS animation using a button - simply click on the button and watch the animation start over each time

I already know how to do this once. However, I would like the animation to restart or begin again when the user clicks on it a second time. Here is what I have: function animation() { document.getElementById('ExampleButton').className = &apo ...

Adjust the CSS extension within the about:config settings of Firefox

I've been using the Zotero extension and I want to adjust how TinyMCE handles paragraph spacing. I'm looking to customize the CSS in extensions.zotero.note.css by adding specific CSS rules. The reason I want to make these changes is because I fe ...

The Prev and Next controls on the web carousel have mysteriously vanished

I managed to successfully create a carousel in the picture below, but I'm facing an issue where the next button is positioned on the white side of the page. Despite trying to enlarge the carousel's size, it ends up going below the category contai ...

Customizing CSS in Angular Components: Taking Control of Style Overrides

I am new to working with Angular and HTML. Currently, I have two different components named componentA and componentB, each having their own .html, .css, and .ts files. In the componentA.css file, I have defined some styles like: .compA-style { font- ...

Passing index value using navigateByUrl method

I have developed a home component and a view component to display different levels of employee details. The home component presents basic information, while the view component shows comprehensive details. The code in my home.component.html file looks like ...

Arrange an element to appear hidden behind a text

I have a stylish horizontal navigation bar with links set up like this: <div class="blackbar"> <span class="blackbar-text"><a href="news.php">NEWS</a></span> <span class="blackbar-text"><a href="foo.php">F ...

Using Python to retrieve data from MySQL and display it in HTML

I am looking to create a system that queries an SQL database every hour and displays the values on a website using Python. However, I am unsure of where to begin. Most resources online mention PHP or focus on pulling data from a website into a database. ...

Utilizing AngularJS to handle the reception and storage of HTML entities

I am having an issue storing and displaying HTML content (using an HTML editor) in my AngularJS WebApp. The problem is that the code appears as plain text. Here is the JSApp code: $scope.SkipValidation = function (value) { var decoded = $("#showtext" ...

How can I arrange an ItemTemplate and Alternating ItemTemplate next to each other in a Gridview layout?

My webpage features a "Reports" page that will dynamically display buttons (formatted ASP:Hyperlinks) based on the number of active reports in a table. While everything works well, I am struggling with achieving the desired layout. I want my buttons to app ...

What is the best way to use shortcodes to display custom fields for post objects, specifically products, within WordPress posts

I'm in the process of displaying 'featured products' within my blog posts. These specific products need to be chosen using custom post objects on the backend for each individual post. I've outlined what I believe the PHP code should lo ...

Utilize Z-index to hide elements from view

Encountering an issue with hiding other div elements when one is visible. In the code snippet below, I aim to make Pacific Rim and World War Z disappear using z-index when Star Trek is visible. Here's my HTML code: <!doctype html> <html ...

Apply a watermark specifically to fancybox for images in galleries, excluding non-gallery items

I recently encountered an issue with a FancyBox image gallery on my webpage. I wanted to add a watermark to the gallery items, so I followed an example from the FancyBox page at http://jsfiddle.net/w5gQS/. beforeShow: function () { $('<div class=" ...

Challenges arise when utilizing the foundation 6 grid for image overlays within a React application

Having some trouble using the foundation 6 xy grid for the first time and aligning three images with text overlays at the bottom of each image. I am struggling to make the background of the text fill the full width of the image while also ensuring it is re ...

AngularJS and CSS: A Guide to Effortlessly Toggle Sliding List Elements

I am in the process of developing a drop-down menu that can be clicked. Using my custom AngularJS directive, I have successfully implemented functionality to load menu items dynamically. While I have made significant progress, I have encountered a small i ...