Fixed width buttons with Bootstrap

后端 未结 12 681
臣服心动
臣服心动 2021-01-29 18:36

Does Bootstrap support fixed width buttons? Currently if I have 2 buttons, \"Save\" and \"Download\", the button size changes based on content.

Also what is the right wa

12条回答
  •  悲哀的现实
    2021-01-29 19:21

    Here I found a solution by comparing buttons in a button-group element. The simple solution is to get the one with the largest width and set the width to the other buttons. So they can have a equal width.

        function EqualizeButtons(parentElementId) {
    
        var longest = 0; 
        var element = $(parentElementId);
    
        element.find(".btn:not(.button-controlled)").each(function () {
            $(this).addClass('button-controlled');
            var width = $(this).width();
            if (longest < width) longest = width;
    
        }).promise().done(function () {
            $('.button-controlled').width(longest);
        });
    }
    

    It worked like a charm.

提交回复
热议问题