Expandable sidebar using responsive Twitter Bootstrap

I am in search of a CSS solution to implement a button that can toggle a sidebar on and off using twitter bootstrap.

Is there a specific term for those small icons seen on webpages that resemble pull tabs when the sidebar is closed and then move along with the sidebar once it's pulled out?

I have created a toggleSidebar icon link to achieve this, but I encounter two issues:

  1. I am unable to make it align with the sidebar using float: left or display: inline-block
  2. When fixed, it forms its own column... instead, I want it to overlay on top of the main content.

The html:

<div class="container-fluid">
  <div class="row-fluid">
    <div id="sidebar" class="span3 scrollDiv" style="display: none;">
      <!--Sidebar content-->
    </div>
    <div id="content" class="span12">
      <!--Main content-->
    </div>
    <a id="toggleSidebar" href="#" class="toggles"><i class="icon-chevron-right"></i></a>
  </div>
</div>

The css:

#toggleSidebar {
  /* float: left; */
  /* display:inline-block; */
  position:fixed;
  display:block;
  left:0;
  top:45px;
  color:#779DD7;
  padding:2px 4px;
}

The javascript:

function sidebar(panels) {
  if (panels === 1) {
    $('#content').removeClass('span9');
    $('#content').addClass('span12 no-sidebar');
    $('#sidebar').hide();
  } else if (panels === 2) {
    $('#content').removeClass('span12 no-sidebar');
    $('#content').addClass('span9');
    $('#sidebar').show();
  }
}

$('#toggleSidebar').click(function() {
  if ($.asm.panels === 1) {
    $('#toggleSidebar i').addClass('icon-chevron-left');
    $('#toggleSidebar i').removeClass('icon-chevron-right');
    return sidebar(2);
  } else {
    $('#toggleSidebar i').removeClass('icon-chevron-left');
    $('#toggleSidebar i').addClass('icon-chevron-right');
    return sidebar(1);
  }
})

A demonstration of this can be viewed here: http://jsfiddle.net/amorris/dmyTR/

Despite extensive searching online, I could not find an example - however, I have provided a rough sketch of what I am aiming for:

It bears some resemblance to the effect showcased at - where they seem to use display: block; clear: both; and then position the pull tab absolutely within the div with a negative right position.

Answer №1

This appears to be the solution you are looking for, view it here.

The relevant code is as follows:

#content {
    float:left;
}

#mapCanvas img {
    max-width: none;
}

#maincont{
    margin-top: 42px;
}

#toggleSidebar {
    float:left;
    color:#779DD7;
    padding:2px 4px;
}

#sidebar{
    float:left;   
}

Please verify if this aligns with your requirements!

Answer №2

Is this the solution you were looking for?

http://jsfiddle.net/dmyTR/37/

Instead of using .hide() and .show(), I implemented an animation to change its position.

// hiding the sidebar
$('#sidebar').animate({
    left: -180,
});

// showing the sidebar
$('#sidebar').animate({
    left: 20,
});

I made some adjustments by removing #sidebar from .container-fluid as it is not part of that container. Additionally, I placed #toggleSidebar inside #sidebar for better organization.

Answer №3

Check out this dynamic side drawer design that I created with minimal bootstrap adjustments:

@media screen and (max-width: 768px) {
    /* Move the container to the side when a specific class is added */
    .side-collapse-container{
        width:100%;
        position:relative;
        left:0;
        transition:left .4s;
    }
    /* Slide out when navbar is activated */
    .side-collapse-container.out{
        left:200px;
    }
    .side-collapse {
        top:50px; /* Maintain space below fixed header */
        bottom:0;
        left:0;
        width:200px;
        position:fixed;
        overflow:hidden;
        transition:width .4s; /* Animate the element's width */
    }
    /* Slide in when navbar is hidden */
    .side-collapse.in {
        width:0;
    }
}

By using the styles of .side-collapse, we can create a fixed navbar positioned at the edge of the screen.

Simply add .side-collapse-container to the content container after the header to allow for easy shifting on opening.

A script attaches a click event to the [data-toggle=] selector.

$(document).ready(function() {   
    var sideslider = $('[data-toggle=collapse-side]');
    var sel = sideslider.attr('data-target');
    var sel2 = sideslider.attr('data-target-2');
    sideslider.click(function(event){
        $(sel).toggleClass('in');
        $(sel2).toggleClass('out');
    });
});

For the HTML or jade source code, visit the github page:

HTML source https://github.com/ZombieHippie/Side-drawer/tree/gh-pages

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

Ways to remove unwanted line breaks following PHP code within HTML documents

Currently working on building my blog, and I'm facing some challenges with the post div. It seems like every element within is automatically getting line breaks. Despite trying to float them or adjust padding, it's not giving me the desired layou ...

Exploring JavaFX and FXML TreeTableView customization for column and header styles

I've been working on a JavaFX project and I'm having trouble customizing the style of the TreeTableView header or columns, like changing the color, width, font size, etc. I've tried using various codes like these but none seem to work. ...

Is it possible to utilize onclick for various table cells in jQuery?

I have a situation where I need to loop through dates and display table content accordingly. Could someone please assist me in figuring out how to do this? index.html.erb <% @batches.each do |batch| %> <tr> **<td class = "pie" id ...

Tips for positioning a div between two vertically aligned input elements

I'm trying to figure out how to place a div between two inputs with the same height and vertically aligned. It seems like a simple task, but for some reason, the code below isn't working: input{ width: 35%; border: 1px solid #A7A7A7; ...

Centering an image and menu in the middle of an HTML page

I have a school project where I am trying to align both an image and a menu in the center and middle. Here is my code on CodePen: LINK I will also share the code here: HTML <header> <img id="logo" src="https://exampleimage.com/logo.jpg"> < ...

There appears to be an issue with the functionality of the Bootstrap toggle tab

Currently, I am facing a toggle issue and having trouble pinpointing the root cause as there are no errors appearing in the console. The problem involves two tabs that can be toggled between - "pay" and "method". Initially, the default tab displayed is "pa ...

Accordion featuring collapsible sections

Looking to build an accordion box using Javascript and CSS. The expanded section should have a clickable link that allows it to expand even further without any need for a vertical scroll bar. Any ideas on how this can be achieved? Thank you ...

Mysterious anomaly observed: Peculiar trajectory detected in canvas image during left

I have a fascinating HTML5 Canvas that showcases the movement of two identical objects to both the right and the left. Although the right side operates flawlessly, I've noticed that the left object leaves behind an intriguing trail with a hint of gree ...

Velocity.js causing a slowdown in animated performance

Currently, I am attempting to animate spans, and while the animation is functional, it appears to be somewhat choppy and lacks smoothness. https://codepen.io/pokepim/pen/JBRoay My assumption is that this is due to my use of left/right for animation purpos ...

Troubleshooting a problem with the transition of the hamburger menu icon in SC

I'm encountering an issue with the transition property and attempting to utilize the all keyword. After including a fiddle, I can't seem to figure out if I've made a simple mistake or if there is something else going on. I have seen the all ...

Encountering a 404 error while trying to delete using jQuery

I have been attempting to execute a 'DELETE' call on an API, but so far I have had no success. Despite being able to access the URI and view the JSON data, my DELETE request does not work. Interestingly, other web services are able to perform thi ...

the functionality of jquery/ajax is not functioning properly

It seems like I am having some trouble with this code. Despite copying and pasting it correctly, the output is going to html-echo.php instead of displaying in htmlExampleTarget Can someone please point out what mistake I might be making here? Thank you, ...

Functionality of click events disabled upon loading of ajax content

Can anyone help me figure out how to make the function "live('click',function()" work after an ajax call that returns content with html(data)? I've been searching for 4 hours and haven't made any progress. This part of the code is work ...

Manage and update events in the Angular Bootstrap Calendar

For the past few days, I have been working on integrating a calendar into my project. I decided to repurpose an example provided by the developer. One issue that I've come across is related to the functionality of deleting events when using the dropdo ...

Do AJAX requests hinder performance and how long do they typically last?

Even though I have experience in web development, I still find myself feeling a bit uneasy asking these basic questions. However, I believe it's always good to verify my assumptions... In my application, I am working on recording unique image views. ...

Informing the parent window of the child window's activities in order to adjust the timer for the user timeout feature

Within my Jquery function, I have implemented a feature that darkens the screen after a period of user inactivity. This triggers a pop-up window giving the user the option to stay logged in by clicking a button. If there is no response within the set time ...

Converting multiple rows of data from MySQL into JSON format

Currently, I am working on a project that involves displaying multiple rows of MySQL JSON data in an HTML table using PHP and jQuery. The process includes input from a search box on the front end. The layout of my HTML table on the search page is structur ...

Uncover comprehensive error analysis via AJAX communication

I am seeking a more comprehensive response regarding a domain through the use of ajax. Currently, I possess the following code: $.ajax({ url: domain, type: "POST", data: { //To identify any errors, an empty response is set xml ...

Creating a hover effect for displaying image masks

My website features a profile page displaying the user's photo. I am attempting to create a functionality where when the user hovers over their photo, a transparent mask with text appears allowing them to update their profile picture via a modal. How ...

What is the best way to dynamically implement text ellipsis using CSS in conjunction with Angular 7?

i need to display a list of cards in a component, each card has a description coming from the server. In my component.html, I am using a ngFor like this: <div [style.background-image]="'url('+row.companyId?.coverUrl+')'" class="img- ...