Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a slider with columns using Bootstrap

I have a site with 4 columns. I would like to make it responsive but instead of displaying the columns at the bottom like Bootstrap's default method, I would like columns to be full width of the device and slide between them.

Here is a schema:

schema

And what I did so far:

jsfiddle

@media (max-width: 979px) {
.container {
    max-width: none !important;
}
.column1 {
    width: 100%;
}

}

Is it possible to make a column full width using device width and not container width? Do I have to use javascript?

like image 508
Vilarix Avatar asked Sep 11 '13 23:09

Vilarix


People also ask

How do I make 4 columns in Bootstrap?

First example: create a row ( <div class="row"> ). Then, add the desired number of columns (tags with appropriate . col-*-* classes). The first star (*) represents the responsiveness: sm, md, lg or xl, while the second star represents a number, which should always add up to 12 for each row.

Can you put rows in columns Bootstrap?

You can easily nest grids using bootstrap by adding additional rows. Here is a step-by-step guide for this process. Within the desired column, create another element with class row . This second row element will contain your nested grid.

How do I make 5 columns in Bootstrap 4?

Populate the 'row' div with 5 divs with class 'col'. Because Bootstrap 4.0+ grid system has now shifted to Flexbox, the columns will arrange by themselves into five equally sized DOM elements.


1 Answers

If you don't mind using javascript, you can use Swipe.js

The html structure goes like so:

<div id='slider' class='swipe'>
  <div class='swipe-wrap'>
    <div></div>
    <div></div>
    <div></div>
  </div>
</div>

The CSS looks like this:

.swipe {
  overflow: hidden;
  visibility: hidden;
  position: relative;
}
.swipe-wrap {
  overflow: hidden;
  position: relative;
}
.swipe-wrap > div {
  float:left;
  width:100%;
  position: relative;
}

And the Javascript looks like this:

window.onload = function() {
  window.mySwipe = Swipe(document.getElementById('slider'));
}

Don't forget to include the javascript file: https://github.com/bradbirdsall/Swipe/blob/master/swipe.js

Here's a demo

Edit Providing you only want this to apply to mobile devices, here's the mobile specific code:

The HTML would change to this:

<div id='slider'>
  <div>
    <div></div>
    <div></div>
    <div></div>
  </div>
</div>

And the JavaScript would change to this:

window.onload = function() {
  if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
    var slider = document.getElementById('slider');
    if (slider.classList) {
      slider.classList.add('swipe');
      slider.getElementsByTagName('div')[0].classList.add('swipe-wrap');
    } else {
      slider.className += 'swipe';
      slider.getElementsByTagName('div')[0].className += 'swipe-wrap';
    }
    window.mySwipe = Swipe(document.getElementById('slider'));
  }
}

Here's another demo

like image 153
Graham Walters Avatar answered Oct 21 '22 17:10

Graham Walters