Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap, pull-left for small devices

I'm building a site in Bootstrap 3. Is there anyway to make a element use the class pull-left on smaller devices and use pull-right on larger ones?

Something like: pull-left-sm pull-right-lg.

I've managed to do it with jquery, catching the resize of the window. Is there any other way? Pref without duplicating the code in a hidden-x pull-left. Or is it considered more ok to duplicate code/content now when going responsive?

like image 800
Christoffer Eklund Avatar asked Aug 20 '13 07:08

Christoffer Eklund


People also ask

How we define grid for small devices in Bootstrap?

Bootstrap Grid - Small Devices Tip: Small devices are defined as having a screen width from 768 pixels to 991 pixels. For small devices we will use the . col-sm-* classes. Now Bootstrap is going to say "at the small size, look for classes with -sm- in them and use those".

What is pull left in Bootstrap?

pull-left class is used to float the element to the left. The . pull-right class is used to float the element to the right.

How do I move a element to the left in Bootstrap?

Answer: Use the justify-content-between Classd-flex to left align and right align text content within a <div> container in Bootstrap 4.

What is Col MD 6 in Bootstrap?

col-sm- (small devices - screen width equal to or greater than 576px) . col-md- (medium devices - screen width equal to or greater than 768px) . col-lg- (large devices - screen width equal to or greater than 992px)


2 Answers

Just add this to your SASS file:

@media (max-width: $screen-xs-max) {
    .pull-xs-left {
        float: left;
    }
    .pull-xs-right {
        float: right;
    }
}

@media (min-width: $screen-sm-min) and (max-width: $screen-sm-max) {
    .pull-sm-left {
        float: left;
    }
    .pull-sm-right {
        float: right;
    }
}

@media (min-width: $screen-md-min) and (max-width: $screen-md-max) {
    .pull-md-left {
        float: left;
    }
    .pull-md-right {
        float: right;
    }
}

@media (min-width: $screen-lg-min) {
    .pull-lg-left {
        float: left;
    }
    .pull-lg-right {
        float: right;
    }
}

Insert actual px values for $screen-* if you use plain CSS of course.

HTML:

<div class="pull-md-left pull-lg-left">
    this div is only floated on screen-md and screen-lg
</div>
like image 156
Alex Avatar answered Oct 25 '22 10:10

Alex


You can use CSS Media Queries

basic usage will be like this; if you want to float left below devices of width 500px, then

@media (max-width: 500px) {
 .your_class {
    float: left;
  }
}

 @media (min-width: 501px) {
 .your_class {
    float: right;
  }
}
like image 30
palerdot Avatar answered Oct 25 '22 12:10

palerdot