Bootstrap 3: pull-right for col-lg only

前端 未结 13 2141
醉酒成梦
醉酒成梦 2020-11-29 20:00

New to bootstrap 3.... In my layout I have:

elements 1
相关标签:
13条回答
  • 2020-11-29 20:39

    It is very simple using Sass, just use @extend:

    .pull-right-xs { 
        @extend .pull-right;
     }
    
    0 讨论(0)
  • 2020-11-29 20:41

    Just use bootstrap's responsive utility classes!

    The best solution for that task is to use the following code:

    <div class="row">
        <div class="col-lg-6 col-md-6">elements 1</div>
        <div class="col-lg-6 col-md-6 text-right">
            <div class="visible-lg-inline-block visible-md-block visible-sm-block visible-xs-block">
                elements 2
            </div>
        </div>
    </div>
    

    Element will be aligned to the right only on lg screens - on the rest the display attribute will be set to block as it is by default for div element. This approach is using text-right class on the parent element instead of pull-right.

    Alternative solution:

    The biggest disadvantage is that the html code inside needs to be repeated twice.

    <div class="row">
        <div class="col-lg-6 col-md-6">elements 1</div>
        <div class="col-lg-6 col-md-6">
             <div class="pull-right visible-lg">
                elements 2
             </div>
             <div class="hidden-lg">
                elements 2
             </div>
        </div>
    </div>
    
    0 讨论(0)
  • 2020-11-29 20:44

    For those interested in text alignment, a simple solution is to create a new class:

    .text-right-large {
        text-align: right;
    }
    @media (max-width: 991px) {
        .text-right-large {
            text-align: left;
        }
    }
    

    Then add that class:

    <div class="row">
        <div class="col-lg-6 col-md-6">elements 1</div>
        <div class="col-lg-6 col-md-6 text-right-large">
            elements 2
        </div>
    </div>
    
    0 讨论(0)
  • 2020-11-29 20:45
    .pull-right-not-xs, .pull-right-not-sm, .pull-right-not-md, .pull-right-not-lg{
        float: right;
    }
    
    .pull-left-not-xs, .pull-left-not-sm, .pull-left-not-md, .pull-left-not-lg{
        float: left;
    }
    @media (max-width: 767px) {    
        .pull-right-not-xs, .pull-left-not-xs{
            float: none;
        }
        .pull-right-xs {
            float: right;
        }
        .pull-left-xs {
            float: left;
        }
    }
    @media (min-width: 768px) and (max-width: 991px) {
        .pull-right-not-sm, .pull-left-not-sm{
            float: none;
        }
        .pull-right-sm {
            float: right;
        }
        .pull-left-sm {
            float: left;
        }
    }
    @media (min-width: 992px) and (max-width: 1199px) {
        .pull-right-not-md, .pull-left-not-md{
            float: none;
        }
        .pull-right-md {
            float: right;
        }
        .pull-left-md {
            float: left;
        }
    }
    @media (min-width: 1200px) {
        .pull-right-not-lg, .pull-left-not-lg{
            float: none;
        }
        .pull-right-lg {
            float: right;
        }
        .pull-left-lg {
            float: left;
        }
    }
    
    0 讨论(0)
  • 2020-11-29 20:46

    This problem is solved in bootstrap-4-alpha-2.

    Here is the link: http://blog.getbootstrap.com/2015/12/08/bootstrap-4-alpha-2/

    Clone it on github: https://github.com/twbs/bootstrap/tree/v4.0.0-alpha.2

    0 讨论(0)
  • 2020-11-29 20:47

    now include bootstrap 4:

    @import url('https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.3/css/bootstrap.min.css');
    

    and code should be like this:

    <div class="row">
        <div class="col-lg-6 col-md-6" style="border:solid 1px red">elements 1</div>
        <div class="col-lg-6 col-md-6" style="border:solid 1px red">
             <div class="pull-lg-right pull-xl-right">
                elements 2
             </div>
        </div>
    </div>
    
    0 讨论(0)
提交回复
热议问题