如何創建:垂直按鈕組

學習如何使用 CSS 創建垂直“按鈕組”。

垂直按鈕組

將一系列按鈕分組到垂直按鈕組中:

親自試一試

如何創建垂直按鈕組

第一步 - 添加 HTML:

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

第二步 - 添加 CSS:

.btn-group button {
  background-color: #04AA6D; /* 綠色背景 */
  border: 1px solid green; /* 綠色邊框 */
  color: white; /* 白色文本 */
  padding: 10px 24px; /* 一些內邊距 */
  cursor: pointer; /* 鼠標指針/手形圖標 */
  width: 50%; /* 如果需要,設置寬度 */
  display: block; /* 使按鈕堆疊 */
}
.btn-group button:not(:last-child) {
  border-bottom: none; /* 防止雙邊框 */
}
/* 鼠標懸停時添加背景顏色 */
.btn-group button:hover {
  background-color: #3e8e41;
}

親自試一試

相關頁面

教程:CSS 按鈕