Nigel Johnson
Nigel Johnson

Reputation: 522

bootstrap btn-group buttons not joined

I'm using bootstrap version 3.3.7 and I have this code from the W3Schools website (bootstrap website not currently available in my country):

    <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>

The buttons are not joined together:

buttons not joined

I have tried adding role="group", with and without the btn-group-lg, inside a form and inside containers as well as bare on the page. In chrome developer tools I can see the btn-group being applied and nothing being overridden (I would expect border-radius to be) And I have redownloaded the boostrap CSS files in case I accidentally corrupted them:

Chrome developer tools

What else can I look at to see why they are not joined?

I have something similar on input groups but cant find an example at this point.

EDIT

Based on one of the answers, I removed all of the application styling and linked to the bootstrap CDN, but it still didn't work, I seen the fiddles and the snippets do work, but I'm still at a loss as to why it doesn't work here. Based on the same answer, I added this into my application 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;
}

And they now appear as expected, but I'd still like to get ot the bottom of what's going on if possible :(

Upvotes: 0

Views: 2464

Answers (1)

Dalin Huang
Dalin Huang

Reputation: 11342

Try add this to your style, this will check if btn in btn group is not first or last child, turn border-radius to 0:

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

works fine for me? do you have any css using !important that could overwrite bootstrap style?

<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>

Another option you can create your own btn, check the following:

the most important part is

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

this will create the btn group effect by force first btn in group to have border-radius at left side and last btn in group to have border-radius at right side, any btn in between will not have any border-radius 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>

Upvotes: 1

Related Questions