2

I need two "flat" buttons, without space between them. It should look like this: enter image description here

Page itself is in AngularJS. So far I've created this (just snippet):

HTML:

  <body ng-app="">
    <section layout="row" layout-align="center center">
      <button id="legal" ng-click="businessType=true" ng-model="businessType" ng-init="businessType = true">Legal Person</button>
      <button id="individual" ng-click="businessType=false">Individual</button>
    </section>

    <p>Area 1 - common data</p>
    <hr>

    <div ng-if="businessType == true">
      <p>Area 2 - legal person data</p>
    </div>

    <div ng-if="businessType == false">
      <p>Area 2 - individual data</p>
    </div>

    <hr>
    <p>Area 3 - common data</p>
    <hr>
  </body>

</html>

CSS:

button#legal:focus {
  background: blue;
  color: white;
}

button#individual:focus {
  background: blue;
  color: white;
}

JSFiddle

which looks (initially and when option selected) like:

enter image description hereenter image description here

I've tried several options, with AngularJS Material button etc., but none produced desired effect, i.e. buttons which looks like example on mockup ('flat' like, no space).

Any help with this, please?

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Nenad Bulatović
  • 7,238
  • 14
  • 83
  • 113

3 Answers3

3

You can try these styles (as you have to override some default styles) and don't forget to remove whitespace between buttons (here I simply made them close to each other). You can also consider the autofocus attribute to have the focus at the start.

button {
  border: none;
  outline: none;
  padding: 10px 20px;
}

button#legal:focus,
button#individual:focus {
  background: blue;
  color: white;
}
<section>
  <button id="legal" autofocus >Legal Person</button><button id="individual">Individual</button>
</section>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
2

It's 2018! Wrap them inside an element with display: inline-flex or display: flex.

.button-container {
  display: inline-flex;
}
<div class="button-container">
  <button type="button">Button1</button>
  <button type="button">Button2</button>
  <button type="button">Button3</button>
</div>
kalicki2k
  • 540
  • 4
  • 9
1

Because buttons are by default inline elements which take space to align itself.

So use flex to the button row which will make the button flex item. Also remove the outline of the button

Stack Snippet

button#legal:focus {
  background: blue;
  color: white;
}

button#individual:focus {
  background: blue;
  color: white;
}

section[layout="row"] {
  display: flex;
}

button {
  outline: none;
}
<body ng-app="">
  <section layout="row" layout-align="center center">
    <button id="legal" ng-click="businessType=true" ng-model="businessType" ng-init="businessType = true">Legal Person</button>
    <button id="individual" ng-click="businessType=false">Individual</button>
  </section>

  <p>Area 1 - common data</p>
  <hr>

  <div ng-if="businessType == true">
    <p>Area 2 - legal person data</p>
  </div>

  <div ng-if="businessType == false">
    <p>Area 2 - individual data</p>
  </div>

  <hr>
  <p>Area 3 - common data</p>
  <hr>
</body>
Bhuwan
  • 16,525
  • 5
  • 34
  • 57