How do I bottom-align grid elements in bootstrap fluid layout

前端 未结 10 1714
你的背包
你的背包 2020-12-04 10:21

I have a fluid layout using Twitter\'s bootstrap, wherein I have a row with two columns. The first column has a lot of content, which I want to fill the span normally. The

10条回答
  •  广开言路
    2020-12-04 10:47

    Based on the other answers here is an even more responsive version. I made changes from Ivan's version to support viewports <768px wide and to better support slow window resizes.

    !function ($) { //ensure $ always references jQuery
        $(function () { //when dom has finished loading
            //make top text appear aligned to bottom: http://stackoverflow.com/questions/13841387/how-do-i-bottom-align-grid-elements-in-bootstrap-fluid-layout
            function fixHeader() {
                //for each element that is classed as 'pull-down'
                //reset margin-top for all pull down items
                $('.pull-down').each(function () {
                    $(this).css('margin-top', 0);
                });
    
                //set its margin-top to the difference between its own height and the height of its parent
                $('.pull-down').each(function () {
                    if ($(window).innerWidth() >= 768) {
                        $(this).css('margin-top', $(this).parent().height() - $(this).height());
                    }
                });
            }
    
            $(window).resize(function () {
                fixHeader();
            });
    
            fixHeader();
        });
    }(window.jQuery);
    

提交回复
热议问题