What is the technique to link a sidebar to the body so that it moves when the navbar

Currently, I am working on implementing Bootstrap with sidebars positioned on the left and right. While using Bootstrap works effectively in pushing the body down on mobile devices, I have encountered an issue with the sidebar not being pushed down as expected because it is styled using CSS rather than Bootstrap.

Here is my HTML code:

<!-- Left sidebar -->
<div class="sidenav">
  <a class='active'">
    Home
  </a>
</div>

<div class="container-fluid mt-1 mt-sm-1 mt-md-3 mt-lg-5">
  <div class="row">
    <div class="col-8 offset-2 col-sm-10 offset-sm-1 col-md-10 offset-md-1 col-lg-10 offset-lg-1">
      <v-fade-transition>
        <router-view></router-view>
      </v-fade-transition>
    </div>
  </div>
</div>

<!-- Right sidebar -->
<div class="sidenav">
  <a class='active'">
    Twitter
  </a>
</div>

Along with the corresponding CSS:

.sidenav {
  height: 100%;
  width: 150px;
  position: fixed;
  z-index: 1;
  top: 0;
  left: 0;
  overflow-x: hidden;
  padding-top: 160px;
}

.sidenav a {
  padding: 6px 8px 6px 16px;
  color: #1c465b;
  font-family: 'poppins', sans-serif;
  padding-top: 80px;
  margin-bottom: 35px;
  text-decoration: none;
  font-size: 16px;
  font-weight: bold;
  color: #818181;
  display: block;
  transform: rotate(90deg);
  white-space: nowrap;
  transform-origin: center;
}

.sidenav a:hover {
  color: #f1f1f1;
}

I am aiming to achieve the same behavior of pushing the body down when using these sidebars.

https://i.sstatic.net/GdIw5.gif

Answer №1

To achieve this functionality, utilize the navbar components provided in Bootstrap 4. For detailed instructions, refer to the Navbar toggler documentation
Check out the following snippet to see the desired behavior in action:

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
    <ul class="navbar-nav ml-auto">
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
    </ul>
  </div>
</nav>
<div class="container">
  <h1>hello</h1>
</div>

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

Nested divs with inline formatting

On my HTML page, I have the following structure: <div id="frst"> FIRST </div> <div id="top"> <div id="mid"> <div id="bottom"> <ul class="menu"> <li>A</li> ...

Position CSS triangles for active hyperlinks

I'm having trouble creating a triangle for hover-over links, as the triangle always shows up in one corner instead of below the links. Can anyone help me pinpoint the exact issue? Fiddle #navcontainer a:hover::after { background: white; ...

Navigating pinch to zoom: Strategies for managing varying page locations

I've been using a combination of JS and CSS to position images within the viewport in a way that allows them to scale and translate accurately to fill the space. For the most part, this method works smoothly and is also able to handle browser zoom fu ...

What is the best method for validating a div element using Angular UI Bootstrap?

When I try to display an array of objects in a view, my issue arises when I place a div element inside the li and ul tags. The challenge now is to validate elements such as "number", "url", and "email" on blur and keyup events. Some elements may be require ...

Positioning a logo in HTML/CSS so that it remains fixed at the top left corner regardless of the screen size

So, I'm facing a bit of a challenge here! I'm working on coding a website with HTML/CSS and I want the logo to remain fixed at the top left corner. The issue arises when resizing the browser window on a Windows machine – my logo ends up getting ...

Using jQuery to enable scrolling and dynamically changing classes

I'm currently working on enhancing my website with a feature that changes the opacity of the first section to 0.4 when a user scrolls more than 400 pixels down the page. I attempted the following code without success: if($("html, body").offset().top ...

Gridview displaying varying border styles in CSS

I'm really struggling with this issue. I have a GridView and I want to ensure that the borders are consistent across all browsers. Right now, I'm experiencing different outcomes in IE, FF, and Chrome. Despite my best efforts with CSS (I'm re ...

Ways to adjust the border color when error helper text is displayed on a TextField

I am currently working with React Material UI's TextField element. What I aim to achieve is when the submit button is pressed, the helpertext displayed should be "Please enter the password." It should look like this: https://i.sstatic.net/Nu0ua.png ...

Tips for integrating CSS keyframes in MUI v5 (using emotion)

Hey there! I'm currently working on adding some spinning text, similar to a carousel, using keyframes in my React app. The setup involves MUI v5 with @emotion. Basically, I want a "box" element to show different words every few seconds with a rotating ...

Obtaining a single element from a hidden display while dragging using Jquery UI

Is there a way to move an element outside of a container with overflow hidden when using drag and drop functionality in CSS? Currently, when I drag an element with the "item" class, it stays within the confines of the container with overflow set to hidden. ...

Sticky top navigation bar in Bootstrap 4 followed by a section immediately below

Struggling to achieve a transparent Bootstrap 4 sticky navbar that reveals the background color of the following section on initial load. Once the user scrolls past 50px, I want the navbar to smoothly fade to white. I'm close to getting it right, but ...

Adapt Non-Adjacent Content Sections For XL Screens in Sidebar Without Replicating Source Code Segments

I'm struggling to figure out how to achieve my desired layout. Details The solution presented by sheriffderek using CSS grid seems promising, but it causes issues with white space when adding content to the profile block on XL screens. Adjusting the ...

alternative for firebug in internet explorer

I'm currently on the lookout for a Firebug alternative that works well with Internet Explorer 8. I gave Firebug Lite a shot by simply embedding the JavaScript code in my HTML files, however, it wasn't as effective as I hoped. My website, way2enj ...

Reverse the order of jQuery toggle animations

Looking for something specific: How can I create a button that triggers a script and then, when the script is done, reverses the action (toggles)? (I am currently learning javascript/jquery, so I am a beginner in this field) Here's an example: ...

Changing the Size of a Youtube Video Based on the Width of a DIV Element

When embedding a Youtube video iframe, it is important to ensure that it scales according to the width of the containing div. The width of the div can vary depending on the layout of the page snippet. The aspect ratio of the Youtube video is 560/315, widt ...

Is there a method to track the progress of webpage loading?

I am working on a website built with static HTML pages. My goal is to implement a full-screen loading status complete with a progress bar that indicates the page's load progress, including all images and external assets. Once the page has fully loaded ...

Triggering animation with jQuery and CSS

I am working on a one-page site and I want to make a parallelogram disappear when a button is clicked for the next part. Currently, it is disappearing from right to left but I would like to change the direction to left to right. Additionally, I have a simi ...

Solving issues with the autocomplete feature in typeahead search through ajax calls

Currently, I am setting up a text input to function as a search box for retrieving search results through ajax calls with the assistance of the bootstrap typeahead plugin <form class="form-inline ml-3" action="/phone-autocomplete/"&g ...

Customize the dimensions of the bootstrap dropdown menu

I have a dropdown feature on my bootstrap second textbox with a lot of content. The issue is that the dropdown overflows and leaks into the textbox located on the left below it. How can I resize it properly to fit within the confines of the drooping textbo ...

Tips for arranging images of varying heights on separate lines so they appear cohesive as a group

I've been working with masonry.js but I'm still not achieving the effect I want. Javascript:` var container = document.querySelector('#container'); var msnry = new Masonry( container, {columnWidth: 200, itemSelector: '.item' ...