【问题标题】:bootstrap btn-group buttons not joined引导 btn 组按钮未加入
【发布时间】:2017-04-22 20:58:12
【问题描述】:

我正在使用引导程序版本 3.3.7,并且我从 W3Schools 网站获得了此代码(引导程序网站目前在我的国家不可用):

    <div class="btn-group btn-group-lg">
        <button type="button" class="btn btn-primary">Apple</button>
        <button type="button" class="btn btn-primary">Samsung</button>
        <button type="button" class="btn btn-primary">Sony</button>
    </div>

按钮没有连接在一起:

我尝试在表单和容器内以及页面上裸露的情况下添加role="group",无论有无btn-group-lg。在 chrome 开发者工具中,我可以看到 btn-group 被应用并且没有被覆盖(我希望边界半径会被覆盖)并且我已经重新下载了 boostrap CSS 文件,以防我不小心损坏了它们:

我还可以查看哪些内容来了解​​他们未加入的原因?

我在输入组上有类似的东西,但目前找不到示例。

编辑

根据其中一个答案,我删除了所有应用程序样式并链接到引导 CDN,但它仍然不起作用,我看到小提琴和 sn-ps 确实有效,但我仍然在不知道为什么它在这里不起作用。基于相同的答案,我将其添加到我的应用程序 CSS 中:

.btn-group button.btn {
    border-radius:0px;
}
.btn-group button.btn:first-child {
    border-radius:6px 0 0 6px;
}

.btn-group button.btn:last-child {
    border-radius:0 6px 6px 0;
}

它们现在按预期显示,但如果可能的话,我仍然想了解到底发生了什么:(

【问题讨论】:

    标签: css twitter-bootstrap buttongroup


    【解决方案1】:

    尝试将此添加到您的样式中,这将检查 btn 组中的 btn 是否不是第一个或最后一个孩子,将边框半径设置为 0:

    .btn-group>.btn:not(:first-child):not(:last-child):not(.dropdown-toggle) {
        border-radius: 0 !important;
    }
    

    对我有用吗?你有任何使用 !important 的 CSS 可以覆盖引导程序样式吗?

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    
    
    
    <div class="btn-group">
      <button type="button" class="btn btn-primary">Apple</button>
      <button type="button" class="btn btn-primary">Samsung</button>
      <button type="button" class="btn btn-primary">Sony</button>
    </div>

    您可以创建自己的 btn 的另一个选项,请检查以下内容:

    最重要的是

    .btngrp li:first-child {
      border-radius: 6px 6px 0 0;
      border-top-width: 2px;
    }
    .btngrp li:last-child {
      border-radius: 0 0 6px 6px;
    }
    

    这将通过强制first btn 在组中创建btn 组效果,使border-radius 在左侧,last btn 在组中,使border-radius 在右侧,中间的任何btn 都不会有任何@987654328 @attr.

    *, *:before, *:after {
      box-sizing: border-box;
    }
    
    body {
      text-align: center;
      padding: 2em;
      font-family: raleway, sans-serif;
    }
    
    .btngrp {
      list-style-type: none;
      margin: 2em auto;
      padding: 0;
      font-size: .85em;
      display: table;
      letterspacing: .2em;
    }
    @media (min-width: 768px) {
      .btngrp {
        font-size: 1em;
      }
    }
    .btngrp li {
      vertical-align: middle;
      background: #337ab7;
      padding: .75em 1.5em;
      line-height: 0.5;
      border: 2px solid #2e6da4;
      border-top-width: 0;
      -webkit-transition: 200ms;
      transition: 200ms;
    }
    .btngrp li:first-child {
      border-radius: 6px 6px 0 0;
      border-top-width: 2px;
    }
    .btngrp li:last-child {
      border-radius: 0 0 6px 6px;
    }
    @media (min-width: 480px) {
      .btngrp li {
        display: table-cell;
        border-top-width: 2px;
        border-left-width: 0;
      }
      .btngrp li:first-child {
        border-radius: 6px 0 0 6px;
        border-left-width: 2px;
      }
      .btngrp li:last-child {
        border-radius: 0 6px 6px 0;
      }
    }
    .btngrp li:hover {
      background: #286090;
     border: 2px solid ##204d74;
    }
    .btngrp a {
      display: block;
      text-align: center;
      padding: 0 .5em;
      text-decoration: none;
    }
    @media (min-width: 768px) {
      .btngrp a {
        padding: .5em .5em;
      }
    }
    .btngrp a:link, .btngrp a:visited {
      color: white;
    }
    <ul class="btngrp">
      <li><a href="#">Apple</a></li>
      <li><a href="#">Samsung</a></li>
      <li><a href="#">Sony</a></li>
    </ul>

    【讨论】:

    • 谢谢丹尼尔,我不想创造一堆新东西并颠覆自然机制,另外你不能为 LI 中的锚定样式。不过基于此,我确实想出了一个修复方法,但我不确定这是不是答案?
    • @NigelJohnson 可能是您的引导样式未应用于您的应用程序?或者您可以尝试在您的页眉中使用 CDN 链接吗?就像我第一个解决方案中的这 3 个链接一样。
    • 我做到了。我取消了所有样式,只是将引导程序样式从 CDN 中移除。正如我所期望的那样,我对某些元素进行了一些样式设置。在上面的开发者控制台截图中,你可以看到样式被应用到 bootstrap.css 中的按钮
    • @NigelJohnson 如果你能提供你页面的链接,100% 我可以修复它,没有它很难
    • @NigelJohnson 好的,请查看我更新的帖子,第一部分,尝试这种风格,如果它不起作用,请检查中间的孩子,看看是什么覆盖了它?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-30
    • 2018-01-07
    • 2018-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    相关资源
    最近更新 更多