Hoe te maken: knopgroep

Leer hoe je een 'knopgroep' maakt met CSS.

Horizontale knopgroep

In de knopgroep, plaats een reeks knoppen in een rij:

Try it yourself

Hoe knopgroepen te maken

Eerste stap - Voeg HTML toe:

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

Tweede stap - Voeg CSS toe:

.btn-group button {
  background-color: #04AA6D; /* Groene achtergrond */
  border: 1px solid green; /* Groene rand */
  color: white; /* Witte tekst */
  padding: 10px 24px; /* Enkele binnenafstand */
  cursor: pointer; /* Muispuntter/handtekeningsicoon */
  float: left; /* Knoppen naast elkaar floaten */
}
.btn-group button:not(:last-child) {
  border-right: none; /* Dubbele rand voorkomen */
}
/* Floats oplossen (clearfix hack) */
.btn-group:after {
  content: "";
  clear: both;
  display: table;
}
/* Achtergrondkleur toevoegen bij muisovergang */
.btn-group button:hover {
  background-color: #3e8e41;
}

Try it yourself

Horizontaal uitgelijnde/kleine breedte knopgroep:

<!-- Drie knoppen in een groep -->
<div class="btn-group" style="width:100%">
  <button style="width:33.3%">Apple</button>
  <button style="width:33.3%">Samsung</button>
  <button style="width:33.3%">Sony</button>
</div>
<!-- Vier knoppen in een groep -->
<div class="btn-group" style="width:100%">
  <button style="width:25%">Apple</button>
  <button style="width:25%">Samsung</button>
  <button style="width:25%">Sony</button>
  <button style="width:25%">HTC</button>
</div>

Try it yourself

Related pages

Tutorial:CSS button