Html 更改引导3中的堆叠顺序

Html 更改引导3中的堆叠顺序,html,css,twitter-bootstrap,Html,Css,Twitter Bootstrap,在xs宽度处,我需要第二列显示在顶部,然后是第一列,然后是第三列。我尝试过使用push和pull来实现这一点,但对我来说没有效果,如果将列从容器外部推到右侧和左侧,会发生什么情况 这是我的密码: <div class="container"> <div class="row"> <div class="col-xs-12 col-sm-4 one"></div> <div class="col-xs-1

在xs宽度处,我需要第二列显示在顶部,然后是第一列,然后是第三列。我尝试过使用push和pull来实现这一点,但对我来说没有效果,如果将列从容器外部推到右侧和左侧,会发生什么情况

这是我的密码:

<div class="container">
    <div class="row">
        <div class="col-xs-12 col-sm-4 one"></div>
        <div class="col-xs-12 col-sm-4 two"></div>
        <div class="col-xs-12 col-sm-4 three"></div>
    </div>
</div>

.one{
    background-color: red;
    height: 50px;
}

.two{
    background-color: green;
    height: 50px;
}

.three{
    background-color: blue;
    height: 50px;
}

.一{
背景色:红色;
高度:50px;
}
.二{
背景颜色:绿色;
高度:50px;
}
.三{
背景颜色:蓝色;
高度:50px;
}

推拉类不用于订购。 您可以通过多种方式实现所需的结果:

  • Javascript/jQuery。检查insertBefore和insertAfter方法
  • 使用flexbox。使用flexbox可以访问属性“order”
  • 我会选择Flexbox。 有关此支票的详细信息

    我为您创建了以下元素交换函数,如果您不想使用flexbox,它应该用作jQuery函数

    (function ($) {
    $.fn.swapElements = function (opties) {
        //Variables
        var settings = $.extend({
            targetResolution: 768, //Trigger swapping of elements on this resolution
            changeWith: '', //Which element should be swapped $('#object2')
            changeSpeed: 30,
            resize: true //Check for resize event
        }, opties);
    
        var a = this;
        var b = settings.changeWith;
        var tmp = $('<span>').hide();
    
        var doSwap = function () {
            var windowWidth = $(window).width();
            var firstElement = $('#' + a.attr('id') + ', #' + settings.changeWith.attr('id')).first().eq(0).attr('id');
            if (windowWidth <= settings.targetResolution && firstElement === a.attr('id')) {
                a.before(tmp);
                b.before(a);
                tmp.replaceWith(b);
            } else if (windowWidth > settings.targetResolution && firstElement === b.attr('id')) {
                b.before(tmp);
                a.before(b);
                tmp.replaceWith(a);
            }
        }
    
        $(document).ready(function () {
            doSwap();
        });
    
        if (settings.resize) {
            //Check on resize
            $(window).resize(function () {
                clearTimeout($.data(this, 'resizeTimer'));
                $.data(this, 'resizeTimer', setTimeout(function () {  
                    doSwap();
                }, settings.changeSpeed));
    
            });
        }
        return this;
    };
    }(jQuery));
    

    推拉类不用于订购。 您可以通过多种方式实现所需的结果:

  • Javascript/jQuery。检查insertBefore和insertAfter方法
  • 使用flexbox。使用flexbox可以访问属性“order”
  • 我会选择Flexbox。 有关此支票的详细信息

    我为您创建了以下元素交换函数,如果您不想使用flexbox,它应该用作jQuery函数

    (function ($) {
    $.fn.swapElements = function (opties) {
        //Variables
        var settings = $.extend({
            targetResolution: 768, //Trigger swapping of elements on this resolution
            changeWith: '', //Which element should be swapped $('#object2')
            changeSpeed: 30,
            resize: true //Check for resize event
        }, opties);
    
        var a = this;
        var b = settings.changeWith;
        var tmp = $('<span>').hide();
    
        var doSwap = function () {
            var windowWidth = $(window).width();
            var firstElement = $('#' + a.attr('id') + ', #' + settings.changeWith.attr('id')).first().eq(0).attr('id');
            if (windowWidth <= settings.targetResolution && firstElement === a.attr('id')) {
                a.before(tmp);
                b.before(a);
                tmp.replaceWith(b);
            } else if (windowWidth > settings.targetResolution && firstElement === b.attr('id')) {
                b.before(tmp);
                a.before(b);
                tmp.replaceWith(a);
            }
        }
    
        $(document).ready(function () {
            doSwap();
        });
    
        if (settings.resize) {
            //Check on resize
            $(window).resize(function () {
                clearTimeout($.data(this, 'resizeTimer'));
                $.data(this, 'resizeTimer', setTimeout(function () {  
                    doSwap();
                }, settings.changeSpeed));
    
            });
        }
        return this;
    };
    }(jQuery));
    
    使用flexbox

    (function ($) {
    $.fn.swapElements = function (opties) {
        //Variables
        var settings = $.extend({
            targetResolution: 768, //Trigger swapping of elements on this resolution
            changeWith: '', //Which element should be swapped $('#object2')
            changeSpeed: 30,
            resize: true //Check for resize event
        }, opties);
    
        var a = this;
        var b = settings.changeWith;
        var tmp = $('<span>').hide();
    
        var doSwap = function () {
            var windowWidth = $(window).width();
            var firstElement = $('#' + a.attr('id') + ', #' + settings.changeWith.attr('id')).first().eq(0).attr('id');
            if (windowWidth <= settings.targetResolution && firstElement === a.attr('id')) {
                a.before(tmp);
                b.before(a);
                tmp.replaceWith(b);
            } else if (windowWidth > settings.targetResolution && firstElement === b.attr('id')) {
                b.before(tmp);
                a.before(b);
                tmp.replaceWith(a);
            }
        }
    
        $(document).ready(function () {
            doSwap();
        });
    
        if (settings.resize) {
            //Check on resize
            $(window).resize(function () {
                clearTimeout($.data(this, 'resizeTimer'));
                $.data(this, 'resizeTimer', setTimeout(function () {  
                    doSwap();
                }, settings.changeSpeed));
    
            });
        }
        return this;
    };
    }(jQuery));
    
    .row{
    显示器:flex;
    弯曲方向:立柱;
    }
    .一{
    背景色:红色;
    高度:50px;
    顺序:2;
    }
    .二{
    背景颜色:绿色;
    高度:50px;
    顺序:1;
    }
    .三{
    背景颜色:蓝色;
    高度:50px;
    顺序:3;
    }
    
    
    使用flexbox

    (function ($) {
    $.fn.swapElements = function (opties) {
        //Variables
        var settings = $.extend({
            targetResolution: 768, //Trigger swapping of elements on this resolution
            changeWith: '', //Which element should be swapped $('#object2')
            changeSpeed: 30,
            resize: true //Check for resize event
        }, opties);
    
        var a = this;
        var b = settings.changeWith;
        var tmp = $('<span>').hide();
    
        var doSwap = function () {
            var windowWidth = $(window).width();
            var firstElement = $('#' + a.attr('id') + ', #' + settings.changeWith.attr('id')).first().eq(0).attr('id');
            if (windowWidth <= settings.targetResolution && firstElement === a.attr('id')) {
                a.before(tmp);
                b.before(a);
                tmp.replaceWith(b);
            } else if (windowWidth > settings.targetResolution && firstElement === b.attr('id')) {
                b.before(tmp);
                a.before(b);
                tmp.replaceWith(a);
            }
        }
    
        $(document).ready(function () {
            doSwap();
        });
    
        if (settings.resize) {
            //Check on resize
            $(window).resize(function () {
                clearTimeout($.data(this, 'resizeTimer'));
                $.data(this, 'resizeTimer', setTimeout(function () {  
                    doSwap();
                }, settings.changeSpeed));
    
            });
        }
        return this;
    };
    }(jQuery));
    
    .row{
    显示器:flex;
    弯曲方向:立柱;
    }
    .一{
    背景色:红色;
    高度:50px;
    顺序:2;
    }
    .二{
    背景颜色:绿色;
    高度:50px;
    顺序:1;
    }
    .三{
    背景颜色:蓝色;
    高度:50px;
    顺序:3;
    }

    您可以通过
    .col xx pull-
    .col xx push-
    内置网格类来实现这一点。首先考虑移动,在html中首先放置“2”列,然后使用pull-push:

    <div class="container">
        <div class="row">
            <div class="col-xs-12 col-sm-4 col-sm-push-4 two">2</div>
            <div class="col-xs-12 col-sm-4 col-sm-pull-4 one">1</div>        
            <div class="col-xs-12 col-sm-4 three">3</div>
        </div>
    </div>
    
    .one {
        background-color: red;
        height: 50px;
    }
    
    .two {
        background-color: green;
        height: 50px;
    }
    
    .three {
        background-color: blue;
        height: 50px;
    }
    
    
    2.
    1.
    3.
    .一{
    背景色:红色;
    高度:50px;
    }
    .二{
    背景颜色:绿色;
    高度:50px;
    }
    .三{
    背景颜色:蓝色;
    高度:50px;
    }
    

    您可以通过
    .col xx pull-
    .col xx push-
    内置网格类来实现这一点。首先考虑移动,在html中首先放置“2”列,然后使用pull-push:

    <div class="container">
        <div class="row">
            <div class="col-xs-12 col-sm-4 col-sm-push-4 two">2</div>
            <div class="col-xs-12 col-sm-4 col-sm-pull-4 one">1</div>        
            <div class="col-xs-12 col-sm-4 three">3</div>
        </div>
    </div>
    
    .one {
        background-color: red;
        height: 50px;
    }
    
    .two {
        background-color: green;
        height: 50px;
    }
    
    .three {
        background-color: blue;
        height: 50px;
    }
    
    
    2.
    1.
    3.
    .一{
    背景色:红色;
    高度:50px;
    }
    .二{
    背景颜色:绿色;
    高度:50px;
    }
    .三{
    背景颜色:蓝色;
    高度:50px;
    }
    

    您可以使用flexbox更改订单。我发现这个SO问题可能对您有帮助(包括示例+专业和专业):您可以使用flexbox更改订单。我发现这个SO问题可能对您有帮助(包括示例+专业和专业):