How to create: Button group
- Previous Page Breadcrumbs Navigation
- Next Page Vertical Button Group
Learn how to create a 'button group' using CSS.
Horizontal button group
In the button group, align a series of buttons in a row:
How to create a button group
Step 1 - Add HTML:
<div class="btn-group"> <button>Apple</button> <button>Samsung</button> <button>Sony</button> </div>
Step 2 - Add CSS:
.btn-group button { background-color: #04AA6D; /* Green background */ border: 1px solid green; /* Green border */ color: white; /* White text */ padding: 10px 24px; /* Some padding */ cursor: pointer; /* Pointer/hand icon */ float: left; /* Float buttons side by side */ } .btn-group button:not(:last-child) { border-right: none; /* Prevent double border */ } /* Clear float (clearfix hack) */ .btn-group:after { content: ""; clear: both; display: table; } /* Add background color when mouse hovers */ .btn-group button:hover { background-color: #3e8e41; }
Align buttons at both ends/Full-width button group:
<!-- 三个按钮为一组 --> <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> <!-- 四个按钮为一组 --> <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>
Related Pages
Tutorial:CSS Button
- Previous Page Breadcrumbs Navigation
- Next Page Vertical Button Group