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

Generate new variables based on the data received from an ajax call

Suppose there is a .txt file containing some integers separated by spaces, like '22 1 3 49'. I would like to use Ajax to read the file as an array or list, and then save each integer as a JavaScript variable. Currently, this code reads all cont ...

Is it possible to transfer the style object from PaperProps to makeStyles in Material UI?

I am working with a Material UI Menu component and attempting to customize its border. Currently, I am only able to achieve this customization by using PaperProps inline on the Menu element. However, I already have a makeStyles object defined. Is there a ...

Using PHP GET Variable in an HTML Form

I am attempting to populate my form values using variables passed through the URL. Despite trying various solutions, I sometimes encounter an issue where the variable does not display. Any assistance on this matter would be greatly appreciated! Thank you! ...

Problem with Flexbox Wrapping on iPhone 6

I love the flexibility that flexbox provides, but I've been facing an issue specifically with wrapping on iOS devices. Is there a simple fallback option for handling wrapping? Here's a problem scenario where items refuse to wrap: ( JSFiddle Fans ...

Fetching row data from Datatables, followed by executing fn.dataTable.ext.search.push

My alert function is operational, however I am having difficulty utilizing the rowData to filter my other instances of datatables. Here's the link to my codepen: http://codepen.io/smuglovsky/pen/YpNjXm?editors=1010 I picked up the technique of "click ...

Why is my HTML image stored in the database not showing up in TCPDF?

Currently, my situation involves using TCPDF to retrieve content from a MySQL table row that contains HTML code like this: <p><a href="x.html"><img src="http://1/2/3/x.jpg" width="x" height="x"></a></p> The problem arises wh ...

What is the best way to prevent the span text from wrapping to the next line depending on the content of the previous span element using CSS?

i want to ensure the span elements text remains fixed to two lines within a flexbox. What is my goal? https://i.stack.imgur.com/k0GhL.png I am aiming to achieve something similar to the image above. The issue arises when the value in '/400' be ...

Krajee Bootstrap File Input: Easily upload files along with your form

I am facing an issue where I am unable to submit the form along with the selected files. I have tried both methods mentioned in the documentation. My requirement is to send everything together by clicking the submit button on the form. Here is the HTML co ...

Screen readers are unable to "read" text that is identified through aria-describedby

When enhancing my web application for accessibility, I encountered a challenge. I have implemented two required fields in a form that should display separate error messages as spans. To accomplish this, I am utilizing aria-invalid to signal when the fields ...

Bars of varying heights (Google Chart)

I have incorporated a Google chart within a mat-grid-tile. In this setup, one column displays a value of 50, while the other showcases a value of 30. These particular values are sourced from myService and are accurate. Although when I hover over the bars i ...

Pair of columns create bootstrap 4 layout

I'm having trouble with implementing bootstrap, can someone help me out? I want to create a page layout using bootstrap that is divided into two columns. The first column, with a size of 'col-md-4', should display text information while the ...

Form Field Highlighting

I am currently attempting to eliminate the blue "halo" outline that appears on form elements in Firefox on OS X. I have successfully removed the halo in Safari on OS X using CSS with the following code: input { outline: none; } However, this method doe ...

Enhance the performance of Jquery using loops

Here is the code snippet I am working with: $('.counter_d').mouseover(function() { $('#description').html('Counter'); }); $('.selector_d').mouseover(function() ...

How to resolve: Preventing Ajax - Post request from executing repetitively

I am facing an issue with a table that is formatted using the Datatables script. There is a column in the table which contains icons for actions. When a user clicks on an icon, a modal is loaded and its content is fetched using the POST method. The modal ...

Integrate CSS and JavaScript files into Node Express

I am facing an issue including my CSS file and JavaScript file in a node-express application, as I keep getting a 404 not found error. Here is the code snippet that I am using: 1. In server.js var http = require('http'); var app = require(' ...

Is there a method in AngularJS to automatically set app.comment to null if the point is not equal to 1 using front end logic?

Can we verify on the front end in AngularJS if app.point !=1 and app.comment==null? <td> <input type="number" max="5" min="1" ng-init="app.point=5" data-ng-model="app.point"> </td> < ...

How can I prevent an image from moving in relation to other objects on a webpage using HTML?

I'm currently working on my HTML website and facing a layout issue. I have an image in the center of the screen, but I want to add text beside it on the right side. Every time I try to do this, the image moves down, which is frustrating. I'm not ...

Menu options moved to the right of the screen

I am encountering a small issue with my dropdown menu that I can't seem to solve. The first item in the dropdown menu appears correctly, but the second item is slightly shifted to the right. It seems like the margin-right applied to the link may be c ...

Using JSON within HTML: A guide to sanitizing stringified objects

Is there a way to improve the readability of a string that looks like an object but is actually just a string? It currently does not look very nice and easy to read. Using JSON.parse doesn't work because not every element in the string meets the requi ...

Ways to Customize the Text Color in the Navigation Bar

Is there a way to change the color of text in my navigation bar to #b3b3b3? It seems like I am limited to the colors provided by bootstrap. How can I work around this limitation? <nav class="navbar" style="color: #b3b3b3; background-col ...