Bootstrap - Grupisana dugmadi (Button Groups)


Kreiranje grupa dugmadi pomoću Bootstrap-a

U prethodnoj lekciji naučili ste kako kreirati različite tipove pojedinačnih dugmadi i mijenjati ih unaprijed definisanim klasama. Međutim, Bootstrap vam takođe omogućava grupisanje niza dugmadi u jedan red kroz komponentu grupe dugmadi. Da biste kreirali grupe dugmadi, samo omotajte niz dugmadi sa .btn klasom u element <div> i na nju primijenite klasu .btn-group, kao što je prikazano u sljedećem primjeru:

<div class="btn-group">
    <button type="button" class="btn btn-primary">Početna</button>
    <button type="button" class="btn btn-primary">O nama</button>
    <button type="button" class="btn btn-primary">Kursevi</button>
</div>
Pogledajmo kako koristiti primjer u praksi:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bootstrap 4 Grupisana dugmad</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<style>
    .bs-example{
        margin: 20px;        
    }
</style>
</head>
<body>
<div class="bs-example">
    <div class="btn-group">
        <button type="button" class="btn btn-primary">Početna</button>
        <button type="button" class="btn btn-primary">O nama</button>
        <button type="button" class="btn btn-primary">Kursevi</button>
    </div>
</div>
</body>
</html>

Prikaz koda iz gornjeg primjera izgledaće odprilike ovako:



Kreiranje alatne trake pomoću dugmadi

Takođe možete kombinovati skupove grupa dugmadi kako biste stvorili složenije komponente poput alatne trake. Da biste kreirali alatnu traku dugmadi, samo omotajte skupove grupa dugmadi u element <div> i na nju primijenite klasu .btn-toolbar, kao što je prikazano u sljedećem primjeru:

<div class="btn-group mr-2">
    <button type="button" class="btn btn-primary">
        <i class="fa fa-font"></i>
    </button>
    <button type="button" class="btn btn-primary">
        <i class="fa fa-bold"></i>
    </button>
    <button type="button" class="btn btn-primary">
        <i class="fa fa-italic"></i>
    </button>
</div>
<div class="btn-group mr-2">
    <button type="button" class="btn btn-primary">
        <i class="fa fa-align-left"></i>
    </button>
    <button type="button" class="btn btn-primary">
        <i class="fa fa-align-center"></i>
    </button>
    <button type="button" class="btn btn-primary">
        <i class="fa fa-align-right"></i>
    </button>
    <button type="button" class="btn btn-primary">
        <i class="fa fa-align-justify"></i>
    </button>
</div>
<div class="btn-group">
    <button type="button" class="btn btn-primary">
        <i class="fa fa-undo"></i>
    </button>
</div>
Pogledajmo kako koristiti primjer u praksi:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bootstrap 4 Alatna traka kreirana uz pomoć dugmadi</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<style>
    .bs-example{
        margin: 20px;        
    }
</style>
</head>
<body>
<div class="bs-example">
    <div class="btn-group mr-2">
        <button type="button" class="btn btn-primary">
            <i class="fa fa-font"></i>
        </button>
        <button type="button" class="btn btn-primary">
            <i class="fa fa-bold"></i>
        </button>
        <button type="button" class="btn btn-primary">
            <i class="fa fa-italic"></i>
        </button>
    </div>
    <div class="btn-group mr-2">
        <button type="button" class="btn btn-primary">
            <i class="fa fa-align-left"></i>
        </button>
        <button type="button" class="btn btn-primary">
            <i class="fa fa-align-center"></i>
        </button>
        <button type="button" class="btn btn-primary">
            <i class="fa fa-align-right"></i>
        </button>
        <button type="button" class="btn btn-primary">
            <i class="fa fa-align-justify"></i>
        </button>
    </div>
    <div class="btn-group">
        <button type="button" class="btn btn-primary">
            <i class="fa fa-undo"></i>
        </button>
    </div>
</div>
</body>
</html>

Prikaz koda iz gornjeg primjera izgledaće odprilike ovako:



Veličina dimenzija grupa dugmadi

Umjesto da na svako dugme u grupi primijenite klase za dimenzioniranje dugmeta, možete jednostavno primijeniti klase za dimenzioniranje grupa dugmadi poput .btn-group-lg ili .btn-group-sm direktno na svaki element .btn-group da biste stvorili veće ili manje grupe dugmadi, kao što je prikazano u sljedećem primjeru:

<div class="btn-group mb-2 btn-group-lg">
    <button type="button" class="btn btn-primary">Početna</button>
    <button type="button" class="btn btn-primary">O nama</button>
    <button type="button" class="btn btn-primary">kursevi</button>
</div>
<br>
<div class="btn-group mb-2">
    <button type="button" class="btn btn-primary">Početna</button>
    <button type="button" class="btn btn-primary">O nama</button>
    <button type="button" class="btn btn-primary">Kursevi</button>
</div>
<br>
<div class="btn-group btn-group-sm">
    <button type="button" class="btn btn-primary">Početna</button>
    <button type="button" class="btn btn-primary">O nama</button>
    <button type="button" class="btn btn-primary">Kursevi</button>
</div>
Pogledajmo kako koristiti primjer u praksi:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bootstrap 4 Dimenzije grupa dugmadi</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<style>
    .bs-example{
        margin: 20px;        
    }
</style>
</head>
<body>
<div class="bs-example">
    <div class="btn-group mb-2 btn-group-lg">
        <button type="button" class="btn btn-primary">Početna</button>
        <button type="button" class="btn btn-primary">O nama</button>
        <button type="button" class="btn btn-primary">Kursevi</button>
    </div>
    <br>
    <div class="btn-group mb-2">
        <button type="button" class="btn btn-primary">Početna</button>
        <button type="button" class="btn btn-primary">O nama</button>
        <button type="button" class="btn btn-primary">Kursevi</button>
    </div>
    <br>
    <div class="btn-group btn-group-sm">
        <button type="button" class="btn btn-primary">Početna</button>
        <button type="button" class="btn btn-primary">Kursevi</button>
        <button type="button" class="btn btn-primary">O nama</button>
    </div>
</div>
</body>
</html>

Prikaz koda iz gornjeg primjera izgledaće odprilike ovako:





Ugnježdene grupe dugmadi (Nesting Button Groups)

Grupe dugmadi takođe se mogu ugnjezditi. Sljedeći primjer pokazuje kako .btn-grupu smjestiti u drugu .btn-grupu kako bi se stvorio padajući menu unutar grupe dugmadi.

<div class="btn-group">
    <a href="#" class="btn btn-primary">Početna</a>
    <a href="#" class="btn btn-primary">O nama</a>
    <div class="btn-group">
        <a href="#" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">Kursevi</a>
        <div class="dropdown-menu">
            <a class="dropdown-item" href="#">Bootstrap 4</a>
            <a class="dropdown-item" href="#">HTML5 - CSS3</a>
        </div>
    </div>
</div>
Pogledajmo kako koristiti primjer u praksi:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bootstrap 4 Ugnježdena grupa dugmadi</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<style>
    .bs-example{
        margin: 20px;        
    }
</style>
</head>
<body>
<div class="bs-example">
    <div class="btn-group">
        <a href="#" class="btn btn-primary">Početna</a>
        <a href="#" class="btn btn-primary">O nama</a>
        <div class="btn-group">
            <a href="#" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">Kursevi</a>
            <div class="dropdown-menu">
                <a class="dropdown-item" href="#">Bootstrap 4</a>
                <a class="dropdown-item" href="#">HTML5-CSS3</a>
            </div>
        </div>
    </div>
</div>
</body>
</html>

Prikaz koda iz gornjeg primjera izgledaće odprilike ovako:



Vertikalno naslagana grupa dugmadi

Možete i učiniti da se grupe dugmadi prikazuju vertikalno naslagani, a ne vodoravno. Da biste to učinili, samo zamijenite klasu .btn-group s klasom .btn-group-vertical, ovako:

<div class="btn-group-vertical">
    <a href="#" class="btn btn-primary">Početna</a>
    <a href="#" class="btn btn-primary">O nama</a>
    <div class="btn-group">
        <a href="#" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">Kursevi</a>
        <div class="dropdown-menu">
            <a class="dropdown-item" href="#">Bootstrap 4</a>
            <a class="dropdown-item" href="#">HTML5 - CSS3</a>
        </div>
    </div>
</div>
Pogledajmo kako koristiti primjer u praksi:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bootstrap 4 Vertikalna grupa dugmadi</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<style>
    .bs-example{
        margin: 20px;        
    }
</style>
</head>
<body>
<div class="bs-example">
    <div class="btn-group-vertical">
        <a href="#" class="btn btn-primary">Početna</a>
        <a href="#" class="btn btn-primary">O nama</a>
        <div class="btn-group">
            <a href="#" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">Kursevi</a>
            <div class="dropdown-menu">
                <a class="dropdown-item" href="#">Bootstrap 4</a>
                <a class="dropdown-item" href="#">HTML5 - CSS3</a>
            </div>
        </div>
    </div>
</div>
</body>
</html>

Prikaz koda iz gornjeg primjera izgledaće odprilike ovako:



Kreiranje Justified grupa dugmadi

Grupe gumba takođe možete razvući kako biste popunili svu dostupnu širinu primjenom klase .d-flex na element .btn-group. U ovom slučaju svako dugme ima jednaku širinu.

<div class="btn-group d-flex">
    <button type="button" class="btn btn-primary">Početna</button>
    <button type="button" class="btn btn-primary">O nama</button>
    <button type="button" class="btn btn-primary">Kursevi</button>
</div>
Pogledajmo kako koristiti primjer u praksi:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bootstrap 4 Justified grupa dugmadi</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<style>
    .bs-example{
        margin: 20px;        
    }
</style>
</head>
<body>
<div class="bs-example">
    <div class="btn-group d-flex">
        <button type="button" class="btn btn-primary">Početna</button>
        <button type="button" class="btn btn-primary">O nama</button>
        <button type="button" class="btn btn-primary">Kursevi</button>
    </div>
</div>
</body>
</html>

Prikaz koda iz gornjeg primjera izgledaće odprilike ovako: