方法-ボタングループ
CSSで「ボタングループ」を作成する方法を学びます。
水平ボタングループ
ボタングループの1行に一連のボタンをグループ化します。
ボタングループを作成する方法
ステップ1)HTMLを追加します。
例
<div class="btn-group">
<button>Apple</button>
<button>Samsung</button>
<button>Sony</button>
</div>
ステップ2)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 the
buttons side by side */
}
.btn-group button:not(:last-child) {
border-right: none; /* Prevent double borders */
}
/* Clear floats (clearfix hack) */
.btn-group:after {
content: "";
clear: both;
display:
table;
}
/* Add a background color on hover */
.btn-group button:hover {
background-color: #3e8e41;
}
両端揃え/全幅ボタングループ:
例
<!-- Three buttons in a 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>
<!--
Four buttons in a group -->
<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>
ヒント:ボタンのスタイルを設定する方法の詳細については、 CSSボタンのチュートリアルにアクセスしてください。