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

Looking for a way to transfer the value of a variable to a PHP variable using any script or code in PHP prior to submitting a form?

Within this form, the script dynamically updates the module dropdown list based on the selected project from the dropdown box. The value of the module list is captured in a text field with id='mm', and an alert box displays the value after each s ...

Adjusting the dimensions of a button: What to expect

I'm currently working on a toggle switch that I want to make responsive for future resizing. The toggle switch includes a red square (for demonstration purposes), but I've encountered an issue where the red square stretches and changes its dimens ...

The dynamic combination of jCarousel, jQuery Accordion, and fade in effects

Take a look at this link www.aboud-creative.com/demos/mckinley3. You'll find a jQuery Accordion with jCarousel inside the "Developments" section. I have implemented a standard fadeIn function for the logo, accordion, and a stag on the bottom right to ...

Tips for extracting text from nested elements

I have a collection of available job listings stored in my temporary variable. I am interested in extracting specific text from these listings individually. How can I retrieve text from nested classes? In the provided code snippet, I encountered empty lin ...

"Utilizing CSS to Format Academic Publications in the Style of APA Guidelines

Is there a way to automatically format a list of academic papers for an updated page using CSS rules? I want to style published articles similar to the following example: https://i.stack.imgur.com/jO56V.png I don't want to manually enter &nbsp;& ...

An error is triggered by serializing a TinyBox POST form into an Array

When I implemented the code below, it performed as anticipated: TINY.box.show({url:target, post:$("form[name='currentSearch']").serialize(), width:650, mask:true, close:true, maskid:'boxMask', boxid:'popupBox', openjs:funct ...

What is the method for sending an AJAX request with a dynamically looping ID number parameter in the URL

I am looking to make multiple AJAX calls with a loop parameter named [id] in the URL, starting from request.php?id=1 and ending at id=9. I want to send each call after a 3-second delay. As a JavaScript beginner, I'm unsure of where to begin implementi ...

disable border-collapse styling in ASP.NET DataList

Currently, I am new to the world of ASP.NET and I am facing a challenge in styling a DataList. Lately, I have developed a fondness for rounded corners on borders, and I am attempting to incorporate this effect into all my pages by implementing it across al ...

Swap out original source files in HTML with minified versions

I have successfully utilized a maven plugin to create a minified and compressed version of my CSS and JavaScript files. Now, I am looking to update the section in my main HTML page that currently loads all those individual files. Here is what it looks lik ...

The impressive jQuery plugin forgoes the traditional "thumb" to showcase thumbnail navigation

While utilizing the Supersized jQuery plugin (v3.2.7) with the "thumbnail_navigation" feature enabled, I have noticed that it does not display the thumbnail image for navigating to the next and previous items as expected. Instead, it shows a scaled-down ve ...

Comparison between AJAX and HTML headers for submitting data using JQuery and Rails

This situation is a bit unique... I have a collection of checkbox images that trigger form submission when clicked, utilizing the following Javascript: $('#pin_rose').simpleImageCheck({ image: '/images/rose.png', imageChecked: &ap ...

Following the submission of a message, the textarea automatically inserts a line-break

Can someone please help me troubleshoot an issue with my chat app? Every time I try to send a message, the textarea adds a line break instead of just focusing on the textarea so I can send a new message smoothly. I have recorded a video demonstrating the ...

Dynamic image swapping with Jquery: How to change image links on the fly

Hi there! I'm currently working on a code where I can change images dynamically and it's going well. However, I am facing a challenge with changing the links that correspond to each image dynamically as well. Does anyone have any suggestions on h ...

Styling CSS Based on Input from Child Siblings

Is it possible to customize an adjacent element based on a valid input from a child element? Let's say we have the following HTML structure: <div id="source"> <input type="text"> </div> <div id="target"> </div> Below ...

Limiting the scope of the jQuery scrollToFixed functionality within various nested DIV elements

I have been grappling with this issue for the past two days without success. I am utilizing the ScrollToFixed plugin from https://github.com/bigspotteddog/ScrollToFixed and my goal is to restrict the fixed positioning within a parent DIV. Despite scouring ...

Tips on eliminating the top margin on my webpage

I am in need of assistance with removing the margin at the top of my page. Take a look at the screenshot for reference: As shown in the image, there is a red arrow pointing to the problematic margin. Can someone guide me on how to eliminate this margin? B ...

Are you interested in designing a bootstrap album for your homepage?

I'm currently working on designing an album-style layout similar to the examples provided below: if you look at the recent works section where you have an image on one side and text on the other, occupying the entire width of the page: or the example ...

Expanding Iframes in Joomla K2

Sorry if this question has been asked before, but I'm really struggling here... Here is the URL where the issue is happening: I am trying to embed an iframe from one of my client's websites onto my own personal website. Currently, I have the i ...

Guide to using jQuery to load an image

I am using this code to load an image and display it within a dialog box. <div id="image_preview" title="Client Photo Preview"> <p><img src="" alt="client image" id="client_image_preview" /></p> </div> $("#client_image_p ...

Challenge encountered in handling AJAX response data for presentation

Currently, I am immersed in a project and decided to implement AJAX for smoother form submissions. My initial attempt was trying to display text from a .txt file below the "submit" button, but unfortunately, that approach didn't yield the desired resu ...