user6124024
user6124024

Reputation:

Make smaller button in bootstrap

I use bootstrap 3 buttons and I want to modify the size to smaller, I've tried with the following which doesn't work

.btn-sml {
    padding: 10px 10px;
    font-size: 22px;
    border-radius: 8px;
}

There is a better way to achieve this ?

Upvotes: 43

Views: 117605

Answers (4)

methos
methos

Reputation: 111

You can use badge style links, they look and behave like buttons:

.badge-sm {
    min-width: 1.8em;
    padding: .25em !important;
    margin-left: .1em;
    margin-right: .1em;
    color: white !important;
    cursor: pointer;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<label class="mx-1 text-dark">Buttons:</label>
<a href="#" class="badge badge-primary badge-sm" data-scale="hour" data-value="1">1</a>
<a href="#" class="badge badge-danger badge-sm" data-scale="hour" data-value="2">2</a>

Upvotes: 8

r4k3sh
r4k3sh

Reputation: 131

You can easily make your buttons smaller using the height property in Bootstrap 4.

For example:

.btn-sml { height: 4vh; } /* change the value according to your need. */

Upvotes: 4

Dsenese1
Dsenese1

Reputation: 1156

Bootstrap provides four button sizes:

The classes that define the different sizes are:

.btn-lg
.btn-md
.btn-sm
.btn-xs // Removed in Bootstrap 4+

The following example shows the code for different button sizes:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
</head>
<body>

<div class="container">
  <h2>Button Sizes</h2>
  <button type="button" class="btn btn-primary btn-lg">Large</button>
  <button type="button" class="btn btn-primary btn-md">Medium</button>    
  <button type="button" class="btn btn-primary btn-sm">Small</button>
</div>

Upvotes: 66

Nils L.
Nils L.

Reputation: 776

Manually setting the padding in y-direction to 0 and adding an inline-style to reduce the font size gave me an xs-Button in Bootstrap 4:

<input type="submit" value="Submit" class="btn btn-sm btn-outline-primary py-0" style="font-size: 0.8em;">

Upvotes: 60

Related Questions