Guide to making a vertical clickable separator/line using bootstrap

Seeking advice on creating a layout where the left side consists of a sidebar menu occupying 24% and the right side contains main content taking up 75%, with a clickable vertical divider at 1% between them. When this line is clicked, the left part will hide, the line will shift to the left edge of the screen, and the right part will expand to 99%. Subsequent clicks on the line will revert the layout back to 24% on the left and 75% on the right.

How can I implement this interactive vertical divider?

I only require details on creating the clickable line itself; I am confident in my abilities to handle the functionality when it comes to resizing the left/right sections.

What method should be used to generate this line within an HTML structure? Would it involve using a div element, utilizing a vertical line image, or something else entirely?

Appreciate any insights provided, seems like it's all achievable through CSS magic :)

Answer №1

Check out this awesome solution using Flexbox and Jquery

$('.clickable span').on('click', function() {
  $('.left-side').toggleClass('hidden');
  $(this).toggleClass('highlighted');
});
body, html {
  margin: 0;
  padding: 0;
}

.container {
  display: flex;
  min-height: 100vh;
}

.left-side {
  flex: 0 0 25%;
  transition: all 0.3s ease-in;
}

.right-side {
  flex: 75%;
  position: relative;
  transition: all 0.3s ease-in;
}

span {
  position: absolute;
  height: 100vh;
  top: 0;
  left: 0;
  width: 3px;
  background: black;
}

.hidden {
  flex: 0 0 0;
  overflow: hidden;
}

.highlighted {
  width: 6px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="content">
  <div class="left-side">Left Side</div>
  <div class="right-side"><span tabindex="0"></span>Right Side</div>
</div>

Answer №2

Here is an example I created:

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="left">
left lorem ipsum dolor sit amet
</div>
<div id="divider">

</div>
<div id="right">
right content lorem ipsum dolor sit amet
</div>

CSS

div {
  height:300px;
}
#left{
  width: 23%;
  float:left;
  transition:all .4s ease-in-out;
  -webkit-transition:all .4s ease-in-out;
  -moz-transition:all .4s ease-in-out;
}
.toggle-left {
  width:0% !important;
  overflow:hidden;
}

#divider {
  width:2%;
  float:left;
  background:#000;
  cursor:pointer;
}
#right {
  width:75%;
  float:left;
  transition:all .4s ease-in-out;
  -webkit-transition:all .4s ease-in-out;
  -moz-transition:all .4s ease-in-out;
}
.toggle-right {
  width: 98% !important;
}

JS

$(document).ready(function(){
    $(document).on('click','#divider',function(){
    $("#left").toggleClass('toggle-left');   
    $("#right").toggleClass('toggle-right');
  });
});

https://jsfiddle.net/4b1p8nse/1/

Answer №3

Even though there are already solutions provided, I wanted to share a unique approach using bootstrap. The main content div has a left border which acts as a vertical trigger line. By overlaying it with another div, we can provide a pointer (hand) cursor for better user experience.

$(".nav-switch").on("click", function() {
  var $t = $(this),
    v = !!$t.data("visible");
  $t.data("visible", !v);
  $("div.nav-col").toggleClass("hidden");
  if (v) {
    /*currently showing nav*/
    $("div.main-col").removeClass("col-xs-9").addClass("col-xs-12");
  } else {
    $("div.main-col").removeClass("col-xs-12").addClass("col-xs-9");
  }
});
.main-col {
  background-color: #d39;
}
.nav-switch {
  border-left: 10px blue solid;
}
.nav-switch-pointer {
  border: 0px dotted yellow;
  width: 10px!important;
  cursor: pointer;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  float: left;
  clear: none;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>


<div class="container-fluid">
  <div class="row">
    <div class="col-xs-3 nav-col">
      this is navigation column
    </div>
    <div class="col-xs-9 main-col">
      <div class="row fl-rt nav-switch" data-visible="1">
        <div class="nav-switch-pointer">
          &nbsp;
        </div>
        <div class="col-xs-12">
          this is right column.
          <br/>click on blue line to hide/show nav
          <br/>this div will adjust its width accordingly
          <br/>
          <br/>
          <br/>
          <br/>
          <br/>wow!
        </div>
      </div>
    </div>
  </div>
</div>

Answer №4

I came up with a simple solution that should work for you.

$('.vd').on('click', function(){
  
  $('.left').toggleClass('not-visible');
  $('.right').toggleClass('all-visible');
  
});
html,body{
  height: 100%;  
}

.left, .vd, .right{
  display: block;
  float: left;
  height: 100%;
}

.left{
  width: 24%;  
  background: #f00;
}
.vd{
  width: 1%;  
  background: #000;
  cursor: pointer;
}
.right{
  width: 75%;  
  background: #f0f;
}
.animated{
  -webkit-transition: all 500ms cubic-bezier(0.190, 1.000, 0.220, 1.000); 
   -moz-transition: all 500ms cubic-bezier(0.190, 1.000, 0.220, 1.000); 
     -o-transition: all 500ms cubic-bezier(0.190, 1.000, 0.220, 1.000); 
        transition: all 500ms cubic-bezier(0.190, 1.000, 0.220, 1.000);  
}
.not-visible{
  width: 0%;  
}
.all-visible{
  width: 99%;  
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<div class="left animated">Left content</div>
<div class="vd"></div>
<div class="right animated">
  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</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

How to handle multiple file uploads and save information in dual tables using Laravel

Currently, I am dealing with a <form> that allows users to upload multiple files. However, my requirement is to store these uploaded files in a separate table within the database. Unfortunately, the files are not being saved into the database for som ...

Learn the steps to successfully select a drop-down option by clicking on a button

Below is the HTML code for my select options: <select id="font"> <option value="School">School</option> <option value="'Ubuntu Mono'">SansitaOne</option> <option value="Tangerine">Tange ...

Utilizing JQuery to Send Checkbox Selections to PHP

I have created a user login form with a "Keep Me Logged In" checkbox and I am attempting to send the value via JQuery to a PHP file for processing, but I am unsure about the correct code to use. Here is my current progress: var username=$("#username").val ...

What do you do when you need to hide a table column that has a colspan

I have been searching for a solution to my unique table structure, but I haven't found any that match my situation. When attempting to hide column A or B, the following code works perfectly: $('table td:nth-child(1),table th:nth-child(1)') ...

Using the class method to handle jQuery events alters the context

Is it possible to access the class context from within a method being used as a jQuery event handler? The example below illustrates the scenario: class EventHandler { constructor() { this.msg = 'I am the event handler'; } ...

What is the method to switch between radio buttons on a webpage?

Here is an example of HTML code: <input type="radio" name="rad" id="Radio0" checked="checked" /> <input type="radio" name="rad" id="Radio1" /> <input type="radio" name="rad" id="Radio2" /> <input type="radio" name="rad" id="Radio4" /& ...

What is the process behind managing today's Google image of the day?

After coming across the javascript picture control on the Google search page, I became interested in replicating it myself. The feature zooms in on a picture when hovering over it, but I couldn't locate the HTML code they were using for it. Is there ...

You can interact with our dropdown menu using the tab key, even when it is

We are looking to make our dropdown tabbable when expanded and non-tabbable when collapsed. We attempted using tabindex="-1" on the content inside the expandable div, but this resulted in it being non-tabbable even when expanded. Any suggestions on how t ...

Verify whether a div element is styled in a specific manner

Upon initial load of my website, if the page is maximized or in fullscreen mode, the comBrand div will have specific CSS properties applied. However, during a resize event, I use the .css() function to adjust the properties of this element so it doesn&apos ...

Convert the 'value' attribute in HTML into a clickable link

Is there a way to make the output value of an HTML input field into a clickable link? Right now, it appears as follows: <input type="email" class="form-control" name="contactEmail" value="<?php echo $row_rsContactD ...

Tips for establishing a universal onkeydown listener for all frames within a webpage?

Working with a complex legacy multi-frame webpage that needs to be compatible with IE-11 and responsive to hotkey events has brought up some challenges. It appears I can't simply declare a JavaScript method in the parent page. Rather, it seems that e ...

Exploring the handling of the nth element within a jQuery each loop

In the process of looping through elements using an each loop, function test(){ $('#first li').each(function(n){$(this).//jQuery effects for nth li of first \\ need to process nth li of id="second" simultaneously }); Is there a wa ...

When a block is clicked, jQuery will reveal that block while hiding the others sequentially, starting with the second block, then the third, and finally the fourth

Creating a navigation menu with 4 blocks can be a bit tricky, especially when trying to show one block at a time upon click. Here is my code attempt, but unfortunately it's not working as expected. I would greatly appreciate any help or suggestions on ...

Is it possible for me to include an ::after pseudo-element within a label that contains an input field?

I'm trying to create a clickable effect using CSS only with labels and inputs. However, I am struggling to replicate the same effect on my ::after pseudo-element without moving the input outside of the label. I attempted using flexbox order property b ...

Utilizing data attributes in E2E testing for optimal results

We have decided to transition from using tag and classname selectors to data attributes in Cypress for our E2E testing. This change is intended to make the selectors more robust and less prone to breaking. Specifically, Cypress recommends using data-cy, d ...

Is there a way to include all images from a local/server directory into an array and then utilize that array variable in a different file?

I'm currently using Netbeans version 8.0.1 with PHP version 5.3 Here is a PHP file example: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/199 ...

Issue with CSS on various mobile devices

Using this CSS to display a fixed part at the bottom of the mobile screen, I noticed that it works well on the Samsung Grand Prime but appears narrower on the Samsung J7 Max. Here is the code snippet and images for reference: .footer { position: fixed ...

Remove the blue outline in Fancybox when clicked

Does anyone know how to remove the default blue outline that appears after opening and closing an image or video in Fancybox 3? It disappears when clicked next to, but I would like to get rid of it completely. Any help is appreciated. https://i.stack.imgu ...

Responsive design challenge

I'm currently working on a WordPress theme with a fixed header and footer on the homepage, and a vertical slider in between that includes content and images. I've made the website responsive, but I'm facing an issue where the content in the ...

What is the best way to restrict the selection of specific days of the week on an HTML form date input using a combination of JavaScript, React, and HTML?

I need help customizing my Forms Date Input to only allow selection of Thursdays, Fridays, and Saturdays. I've searched for a solution but haven't been successful so far. Is there any JavaScript or HTML code that can help me achieve this? Below ...