Dynamic content alongside a stationary sidebar that adjusts in width

Attempting to create a switchable sidebar (toggling between short and long form) using bootstrap, multiple examples, and online resources.

The width of the sidebar changes when toggled, and I want the content to appear next to it regardless of its length.

Each page is divided into sections, and I aim for each section to display full-width on the screen similar to this.

$(document).ready(function() {
  $("#sidebarCollapse").click(function() {
    $("#sidebar").toggleClass("active");
    $(this).toggleClass('active');
  });
});
$("#aboutbutton").click(function() {
  $('html, body').animate({
    scrollTop: $("#aboutDiv").offset().top
  }, 2000);
});
body {
  font-family: 'Poppins', sans-serif;
  background: #fafafa;
}

p {
  font-family: 'Poppins', sans-serif;
  font-size: 0.1em;
  font-weight: 300;
  line-height: 1.7em;
  color: #3498db;
}

a,
a:hover,
a:focus {
  color: inherit!important;
  text-decoration: none!important;
  transition: all 0.3s;
}

.wrapper {
  display: flex;
}
/* Other CSS code remains unchanged */

<!-- Link and script references remain the same -->

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

<head>

  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>José Gomes - Website</title>
  <!-- Latest compiled and minified CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
  <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
  <!-- Material Design Bootstrap -->
  <link rel="stylesheet" href="css/mdb.min.css">
  <!-- Scrollbar Custom CSS -->
  <link rel="stylesheet" href="css/jquery.mCustomScrollbar.css">
  <!-- Our Custom CSS -->
  <link rel="stylesheet" href="css/custom.css">

  <!-- in your header -->
  <link rel="stylesheet" href="https://cdn.rawgit.com/konpa/devicon/df6431e323547add1b4cf45992913f15286456d3/devicon.min.css">
</head>

<body>

  <!-- Content will go here -->
  <div class="wrapper">
    <nav class="sidebar-nav" data-spy="affix" id="sidebar">
      <!-- Sidebar HTML structure remains the same -->
    </nav>
  </div>

  <!-- Page Content -->
  <div id="content container-fluid p-0">
    <!-- Div containing sections with content, dividers, etc. -->
  </div>

  </div>

Link to the jsfiddle example

Tried using a content wrapper and adjusting margin for the content class but still facing issues with the content appearing below or inside the sidebar.

Answer №1

Is this what you were looking for?

$(document).ready(function() {
  $("#sidebarCollapse").click(function() {
    $("#sidebar").toggleClass("active");
    $(this).toggleClass('active');
  });
});
$("#aboutbutton").click(function() {
  $('html, body').animate({
    scrollTop: $("#aboutDiv").offset().top
  }, 2000);
});
body {
  font-family: 'Poppins', sans-serif;
  background: #fafafa;
}

p {
  font-family: 'Poppins', sans-serif;
  font-size: 0.1em;
  font-weight: 300;
  line-height: 1.7em;
  color: #3498db;
}

a,
a:hover,
a:focus {
  color: inherit!important;
  text-decoration: none!important;
  transition: all 0.3s;
}

.wrapper {
  display: flex;
}

#sidebar {
  min-width: 250px;
  max-width: 250px;
  background: #2980b9;
  color: #ecf0f1;
  transition: all 0.3s;
  height: 100%;
  min-height: 100vh;
  position: fixed;
}

#sidebar.active {
  min-width: 80px;
  max-width: 80px;
  text-align: center;
}

#sidebar ul.components {
  padding: 20px 0;
}

#sidebar ul p {
  color: #fff;
  padding: 10px;
}

#sidebar ul li a {
  padding: 10px;
  font-size: 1.6em;
  display: block;
  text-align: left;
}

#sidebar ul li a:hover {
  color: #ecf0f1;
  background: #3498db;
}

#sidebar .active ul li a {
  padding: 20px 10px;
  text-align: center;
  font-size: 0.85em;
}

#sidebar .active i {
  font-size: 1em;
}

#sidebar .active ul li a i {
  margin-right: 0;
  display: block;
  font-size: 1.8em;
  margin-bottom: 5px;
}

#sidebar ul li.active>a,
a[aria-expanded="true"] {
  color: #ecf0f1;
  background: #3498db;
}

ul ul a {
  font-size: 0.9em !important;
  padding-left: 30px !important;
  background: #ecf0f1;
}

#sidebarCollapse {
  width: 100%;
  height: 80%;
  background: #2980b9;
  padding: 20px 0;
  font-size: 1.6em;
  display: block;
  border: 0;
}

#sidebarCollapse-wrapper {
  padding-top: 5%;
  padding-bottom: 5%;
}

#sidebarCollapse span {
  width: 30%;
  height: 2px;
  margin: 0 auto;
  display: block;
  background: #fff;
  transition: all 0.8s cubic-bezier(0.810, -0.330, 0.345, 1.375);
}

#sidebarCollapse span:first-of-type {
  /* rotate first one */
  transform: rotate(45deg) translate(2px, 2px);
}

#sidebarCollapse span:nth-of-type(2) {
  /* second one is not visible */
  opacity: 0;
}

#sidebarCollapse span:last-of-type {
  /* rotate third one */
  transform: rotate(-45deg) translate(1px, -1px);
}

#sidebarCollapse.active span {
  /* no rotation */
  transform: none;
  /* all bars are visible */
  opacity: 1;
  margin: 5px auto;
}

.sidebar-nav.active + div#content{
margin-left:80px;
}
.sidebar-nav:not(.active) + div#content{
margin-left:250px;
}


section {
  min-height: 100vh;
  height: 100vh;
  box-sizing: border-box;
  display: flex;
}
<link href="https://fonts.googleapis.com/css?family=Poppins" rel="stylesheet">
<link href="https://cdn.rawgit.com/konpa/devicon/df6431e323547add1b4cf45992913f15286456d3/devicon.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.4.3/css/mdb.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.1/js/tether.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.4.3/js/mdb.min.js"></script>


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

<head>

  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>José Gomes - Website</title>
  <!-- Latest compiled and minified CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
  <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
  <!-- Material Design Bootstrap -->
  <link rel="stylesheet" href="css/mdb.min.css">
  <!-- Scrollbar Custom CSS -->
  <link rel="stylesheet" href="css/jquery.mCustomScrollbar.css">
  <!-- Our Custom CSS -->
  <link rel="stylesheet" href="css/custom.css">

  <!-- in your header -->
  <link rel="stylesheet" href="https://cdn.rawgit.com/konpa/devicon/df6431e323547add1b4cf45992913f15286456d3/devicon.min.css">
</head>

<body>

  <!-- Content will go here -->
    <!-- Sidebar -->
    <nav class="sidebar-nav" data-spy="affix" id="sidebar">
      <!-- Sidebar Header -->
      <div id="sidebarCollapse-wrapper">
        <button type="button" id="sidebarCollapse" class="navbar-btn waves-effect waves-light">
        <span></span>
        <span></span>
        <span></span>
      </button>
      </div>
      <!-- Sidebar Links -->
      <ul class="list-unstyled components">
        <li class="active waves-effect waves-light" id="aboutbutton"><a href="#"><i class="fa fa-user-circle" aria-hidden="true"></i>  Home</a></li>
        <li class="waves-effect waves-light"><a href="#"><i class="fa fa-briefcase" aria-hidden="true"></i> Page1
          </a></li>
        <li class="waves-effect waves-light"><a href="#"><i class="fa fa-cogs" aria-hidden="true"></i>   Page2</a></li>
        <li class="waves-effect waves-light"><a href="#"><i class="fa fa-home" aria-hidden="true"></i>   Page3</a></li>
      </ul>
    </nav>


  <!-- Page Content -->
  <div id="content" class="p-0">


    <div class="d-flex flex-column">
      <section class="p-3 p-lg-5 content-page" id="Section1">
        Section 1 TEST - Section 1 TEST - Section 1 TEST - Section 1 TEST - Section 1 TEST - Section 1 TEST - Section 1 TEST - Section 1 TEST -
      </section>
      <section class="p-3 content-page">
        Section 2 TEST - Section 2 TEST - Section 2 TEST - Section 2 TEST - Section 2 TEST -
      </section>
      <section class="p-3 content-page">
        Section 3 TEST - Section 3 TEST - Section 3 TEST - Section 3 TEST</section>
    </div>

  </div>

  </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

Using Jquery in combination with Bootstrap modal and PHP for website

Upon submission of a form with numerous fields, I aim to display a bootstrap modal popup that prompts the user with a question before data is saved in the database. The user can respond with either "yes" or "no", leading to different actions being taken ba ...

Learn how to dynamically show the chosen option from a dropdown menu in input text fields using AngularJS

html file: <select ng-model="shipping" ng-options="shipping.shipping for shipping in shipAddress"> <option value=''>--Select Address --</option> </select> <form name="shippingForm" class="form-horizontal" role="form" ...

Utilizing HTML Elements for Conditional Statements

I had a question regarding HTML code and JavaScript functionality that I came across while honing my coding skills. My curiosity lies in understanding how an HTML element can act as a boolean condition within a JavaScript while loop. Take, for instance, ...

Adjusting the dimensions of the "overflow avatar" to be consistent with the other avatars displayed in AvatarGroup

When setting the max prop of the AvatarGroup, the additional avatar does not match the height of the other avatars. <AvatarGroup max={3}> <Avatar alt="Remy Sharp" src="/static/images/avatar/1.jpg" sx={{ width: 24, height: 24 ...

Exploring the capabilities of SVG and audio integration in web browsers

I am curious if it's possible to incorporate audio into an SVG file in a web browser. I came across this thread here, but unfortunately, I can't leave a comment =/ I tried implementing the code from this website, but it doesn't seem to work ...

Issue with border radius not applied to input-group in Bootstrap 3

Can anyone explain why the input-group in Bootstrap 3.4 is missing all border radius? <form action="{{ route('dashboard.users.index') }}" method="get"> <div class="input-group"> <input type="text" name="search" class="f ...

Customize CSS class in ASP.Net

Here's the CSS code I am currently using: LinkButton:hover { color:White; background-color:Gray; } .myClass { color:Blue; } The issue I'm facing is that I have a LinkButton with the CssClass .myClass, and when I hover over it, the b ...

"Troubleshooting: Why is my jQuery .load function returning an empty div when

Currently, I am developing a PHP control panel and I need a div in one of my PHP files to automatically refresh. After researching, I found a jQuery solution that can reload specific parts of a website automatically. However, the issue I am facing is that ...

Implement two different styles within an element's style properties

Welcome everyone, I have a question regarding adding marquee effects to a table row along with highlighting it. Is it possible to include moving text from left to right in the same active row? For example, let's say that the current time is 12:45 AM. ...

Creating a layout with two divs displayed next to each other using CSS

Just when I thought I had it figured out, my two side-by-side divs are not behaving as intended inside the parent div. Why is the orange "Content" div ending up below the navigation bar? Can anyone spot what I did wrong here? Thank you in advance! CSS: ...

Which web browsers are compatible with the input attribute "multiple"?

I am currently incorporating this particular plugin, and its file input does not support multiple file selection. To address this issue, I have added the 'multiple' attribute. However, I am curious if there are any browsers or other platforms (su ...

Utilizing a jQuery variable within an .html() method

Can a Jquery if statement be used to display different content inside a div based on a variable? For example, if the variable is set to "cats", the displayed content might say "I like cats", and if it changes to "dogs", it would read "I like dogs". Is this ...

Troubleshooting error with dual drop-down menus in burger menu on Bootstrap4

During my testing of BS4 (v4.0.0-alpha.6), I encountered a strange issue with the standard template example. I made a slight modification by including another dropdown (dropdown2) next to the original one (dropdown1). <li class="nav-item dropdown"& ...

Guide to designing a progress bar using numerical data stored in a database

I am currently working on a project to create a dynamic progress bar based on numeric values stored in a database. The database has two fields, 'NEXT_STEP' and 'MAX_STEPS'. When the value of NEXT_STEP reaches MAX_STEPS + 1, it indicates ...

merging inline scripts within the <head> section

I have the following code snippet in my HTML file and am looking for ways to optimize its loading process. <script type="text/javascript"> function downloadJSAtOnload() { var element1 = document.createElement("script"); element1.src = "js/jque ...

Why does using rgba color with an alpha value cause my div to become see-through?

I am currently attempting to assign a background color to a specific style of pop-up, but whenever I use a value that includes an alpha channel, it ends up being transparent. This is the CSS code I have been using: --color: 255, 144, 106, 0.18; background ...

Discovering the technique to dynamically load various content using jQuery in a div based on its

After discovering this code to extract information from the first div with an id of container (box4) and retrieve any new data from the URL, everything was functioning correctly. However, I encountered an issue when attempting to load box5 and rerun the co ...

Horizontal image scrolling problem across different browsers

Check out my Fiddle. I'm having trouble with scrolling on different browsers. In Chrome, the scroll behaves as expected and stops when the content ends. However, in Firefox, it keeps scrolling even after reaching the end despite setting a fixed width ...

Issue with Hover Effect on Safari Browser

Encountering a peculiar issue exclusively in Safari - when hovering over a link in the header, the links to the right of the hovered-over link alter their size (appearing smaller) during the hover animation. Once the animation concludes, these links revert ...

The feature in Chrome that automatically reloads generated CSS is failing to refresh the page after SASS recompiles the CSS

I'm attempting to set up Chrome's DevTools to automatically reload a page when I save changes to a watched SCSS file that compiles and updates the CSS file. Although I have checked the Auto-reload generated CSS option, it is unfortunately not fu ...