简体   繁体   English

Bootstrap 3“btn-group”在小屏幕上的无响应行为

[英]Bootstrap 3 "btn-group" non-responsive behavior on small screens

Is there a bootstrap 3 way to handle small screen sizes for "btn-group"?是否有引导程序 3 方法来处理“btn-group”的小屏幕尺寸?

Button group is placed in <td> and wrapped in <div class="btn-group"> :按钮组放置在<td>并包裹在<div class="btn-group">

btn-组

Looks okay, until you re-size it to <768px.看起来不错,直到您将其重新调整为 <768px。 Then you have:那么你有:

在此处输入图片说明

How to make them persistent?如何让它们持久化? I tried to add class btn-group-justified .我试图添加类btn-group-justified But it gives as a result full width buttons and looks even worse on re-size to small screen size.但结果是它提供了全宽按钮,并且在重新调整到小屏幕尺寸时看起来更糟。

PS> I have an idea, how to implement it adding full set of custom classes. PS> 我有一个想法,如何实现它添加全套自定义类。 My question is about bootstrap3 way.我的问题是关于 bootstrap3 的方式。 May be I missed something.可能是我错过了什么。

You can create two button groups with the same buttons and make one of them btn-group-vertical . 您可以使用相同的按钮创建两个按钮组,并使其中一个按钮组为btn-group-vertical Then after applying the hidden-xs and visible-xs to them you can hide and show vertical group on appropriate screen size. 然后在将hidden-xsvisible-xs应用于它们之后,您可以隐藏并在适当的屏幕尺寸上显示垂直组。

<div class="btn-group hidden-xs">
    <button class="btn btn-default">View</button>
    <button class="btn btn-default">Delete</button>
</div>
<div class="btn-group-vertical visible-xs">
    <button class="btn btn-default">View</button>
    <button class="btn btn-default">Delete</button>
</div>

Unfortunately, this requries repeating the markup of the buttons but it should not be an issue if you use any templating tool (define the markup once and include it twice). 不幸的是,这个要求重复了按钮的标记,但是如果你使用任何模板工具(定义标记一次并包含它两次)它就不应该是一个问题。

Wide screen: 宽屏:

宽屏按钮

Narrow screen: 窄屏:

窄屏幕按钮

See the JSFiddle . JSFiddle

I want to offer you a version with icons from FontAwesome . 我想为你提供一个带有FontAwesome图标的版本。 With a minimum screen resolution text hide leaving only icons. 使用最小屏幕分辨率文本隐藏只留下图标。

Sorry for my english. 对不起我的英语不好。

<div class="btn-group">
    <button class="btn btn-default" title="View"><i class="fa fa-eye"></i><span class="hidden-xs"> View</span></button>
    <button class="btn btn-default" title="Delete"><i class="fa fa-times"></i><span class="hidden-xs"> Delete</span></button>
</div>  

UPDATE by Vishal Kumar : add GLYPHICONS preview Vishal Kumar更新:添加GLYPHICONS预览

Check this fiddle: http://jsfiddle.net/Jeen/w33GD/4/ 检查这个小提琴: http//jsfiddle.net/Jeen/w33GD/4/

Here's an alternative to @fracz's answer you can try that won't duplicate HTML content. 这里有一个替代@fracz的答案你可以尝试不会复制HTML内容。 Just copied the css from btn-vertical-group and btn-group and used a media query. 刚刚从btn-vertical-group和btn-group复制了css并使用了媒体查询。

All you have to do is add btn-toolbar-responsive to the toolbar div's classes. 您所要做的就是为工具栏div的类添加btn-toolbar-responsive。

It's in scss for simplicity although you can convert it online easily. 虽然您可以轻松地在线转换它,但它简单易用。 Here is the JS Bin: demo 这是JS Bin: demo

SCSS: SCSS:

.btn-toolbar.btn-toolbar-responsive{
  text-align: center;
  margin: 0;
  .btn-group{
    float: none;
  }

  @media (max-width: 767px){
    .btn + .btn,
    .btn + .btn-group,
    .btn-group + .btn,
    .btn-group + .btn-group {
      margin-top: -1px;
      margin-left: 0;
    }


    .btn-group{
      position: relative;
      display: block;
      vertical-align: middle;
      margin: 0;
      .btn {
        display: block;
        float: none;
        max-width: 100%;

      }
      .btn:not(:first-child):not(:last-child) {
        border-radius: 0;
      }
      .btn:first-child:not(:last-child) {
        border-top-right-radius: 4px;
        border-top-left-radius: 4px;
        border-bottom-right-radius: 0;
        border-bottom-left-radius: 0;
      }
      .btn:last-child:not(:first-child) {
        border-top-right-radius: 0;
        border-top-left-radius: 0;
        border-bottom-right-radius: 4px;
        border-bottom-left-radius: 4px;
      }

    }
    .btn-group:not(:first-child):not(:last-child) {
      .btn {
        border-radius: 0;
      }
    }

    .btn-group:first-child:not(:last-child) {
      .btn:last-child, .dropdown-toggle {
        border-bottom-right-radius: 0;
        border-bottom-left-radius: 0;
      }
    }

    .btn-group:last-child:not(:first-child) {
      .btn:first-child {
        border-top-right-radius: 0;
        border-top-left-radius: 0;
      }
    }
  }

}

Okay, so this worked in a test page I made: 好的,所以这在我做的测试页面中有效:

<div class='btn-group'>
    <button class='btn btn-default col-xs-6'>View</button>
    <button class='btn btn-default col-xs-6'>Delete</button>
</div>

Forcing each button to be 50% using col-xs-6 kept it from wrapping in my own test page modeled after your example. 使用col-xs-6强制每个按钮为50%,这使得它不会包裹在我的自己的测试页面中,模仿您的示例。 However, if you have a wider table than the example and you squish down to 320px, the text will overflow the buttons and it looks even worse than your bad example. 但是,如果你有一个比示例更宽的表,并且你压缩到320px,文本将溢出按钮,它看起来比你的坏例子更糟糕。

You may already know this and it may not be practical for your situation, so I apologize if I'm just presenting unhelpful examples. 您可能已经知道这一点,但对您的情况可能不太实际,所以如果我只是提出无用的例子,我会道歉。 However, if your table is much wider than what you posted as an example, I would suggest making your rows using the BS grid instead of a table. 但是,如果您的表格比您发布的示例宽得多,我建议您使用BS网格而不是表格来创建行。 What this allows you to do is make a single row become two rows when the page shrinks, eg 这允许您做的是在页面缩小时使单行变为两行,例如

<div class='row'>
    <div class='col-xs-12 col-sm-6'>Some additional details</div>
    <div class='col-xs-6 col-sm-3'>Date</div>
    <div class='col-xs-6 col-sm-3'>
        <div class='btn-group'>
            <button class='btn btn-default col-xs-6'>View</button>
            <button class='btn btn-default col-xs-6'>Delete</button>
        </div>
    </div>
</div>

then, just find a way to alternate colors, add borders, or whatever you need to show the separation between the multiple row rows. 然后,找到一种方法来交替颜色,添加边框,或任何你需要显示多行行之间的分隔。

In the BootPly that I just made, as I said, the buttons start to overlap at very small sizes, but they don't wrap when inside a <td> in my browser tests: 在我刚刚制作的BootPly中,正如我所说,按钮开始以非常小的尺寸重叠,但是当我在浏览器测试中的<td>内时它们不会换行:

http://www.bootply.com/117330 http://www.bootply.com/117330

try to set min-width on <td> 尝试在<td>上设置min-width

<td style="min-width: 90px">
    <div class="btn-group">
        <button class=" btn btn-default btn-circle" type="button">
            <i class="fa fa-check"></i>
        </button>
        <button class=" btn btn-default btn-circle" type="button">
            <i class="fa fa-question"></i>
        </button>
        <button class=" btn btn-default btn-circle" type="button">
            <i class="fa fa-times"></i>
        </button>
    </div>
</td>
<div id="secondNav" class="btn-group" role="group">
    <button class='btn btn-default'>View</button>
    <button class='btn btn-default'>Delete</button>
</div>

You can accomplish this with some simple jQuery 您可以使用一些简单的jQuery来完成此任务

<script>
$(window).resize(function() {
    justifyBtnGroup('secondNav');
});

function justifyBtnGroup(id) {
    var btnGroup = $('#' + id);
    if($(window).width() > 768) {
        btnGroup.addClass('btn-group').removeClass('btn-group-vertical');
    } else {
        btnGroup.removeClass('btn-group').addClass('btn-group-vertical');
    }
}
justifyBtnGroup('secondNav'); // will run when page loads
</script>

This help for me.这对我有帮助。 It doesn't make the buttons vertical, but it doesn't compress them either它不会使按钮垂直,但也不会压缩它们

<div class="btn-group flex-wrap" data-toggle="buttons">

不,如果您在小屏幕中打开页面,引导程序会包裹您的按钮。

<div class="btn-group btn-group-lg">...</div>
<div class="btn-group">...</div>
<div class="btn-group btn-group-sm">...</div>
<div class="btn-group btn-group-xs">...</div>

you can add the class (btn-group-xs,btn-group-sm) in the media < 720px 你可以在媒体中添加类(btn-group-xs,btn-group-sm)<720px

hope it will help you ;) 希望它会帮助你;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM