css - 具有相同高度的 Bootstrap btn-group

标签 css twitter-bootstrap

我正在使用 Bootstrap3,并且我在 中有一些按钮。为了根据屏幕尺寸具有相同的宽度,我使用 btn-group-justified 并且效果很好。但是我的按钮标签有一些文字和字形,我通过 white-space:normal 设置了换行的可能性。 但在这种情况下,按钮有时会出现错误的高度。如何强制所有按钮具有相同的高度

<div class="btn-group-justified">
    <div class="btn-group">
        <button type="button" class="btn btn-primary">Button one</button>
    </div>
    <div class="btn-group">
        <button type="button" class="btn btn-primary">Button Two</button>
    </div>
    <div class="btn-group">
        <button type="button" class="btn btn-primary">Button Three and Breaky</button>
    </div>
    <div class="btn-group">
        <button type="button" class="btn btn-primary">Button Four</button>
    </div>
    <div class="btn-group">
        <button type="button" class="btn btn-primary">Button Five</button>
    </div>
</div>

还有我的风格:

button {
    white-space: normal !important;
}

Here is a jsfiddle-Link to show the challenge.

编辑:添加了响应式设计的证据。

最佳答案

请试试这个,希望它能奏效。这将在任何屏幕尺寸下保持按钮高度的一致性

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<script>
    $(document).ready(function(){

    var highestBox = 0;
        $('.btn-group-justified .btn').each(function(){  
                if($(this).height() > highestBox){  
                highestBox = $(this).height();  
        }
    });    
    $('.btn-group-justified .btn').height(highestBox);

});
</script>

关于css - 具有相同高度的 Bootstrap btn-group,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33039376/

相关文章:

html - 如何设置CSS网格列的最大宽度

javascript - 如何使用 jQuery 和 CSS 在底层以精确位置获取 DIV 的背景

jquery - 自定义带箭头滚动条,仅当文字高于<div/>高度时

javascript - 在 Jasny Bootstrap 中使用 fileinput.js 时,选择文件后自动提交表单

html - 输入字段宽无法正常工作

css - 无法在我的 wamp 本地主机中加载 @font_face?

css - 如何使用自定义 css 文件覆盖 react-bootstrap

jquery - Bootstrap 菜单 - 两个相互切换的折叠按钮?意思是,一次只能打开 1 个

javascript - bootstrap3-datetimepicker-rails 显示问题

jquery - 禁用 Twitter Bootstrap 按钮组