Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Bootstrap 按钮组


按钮组

Bootstrap 允许您将一系列按钮分组在一起(在一行上)形成一个按钮组

使用带有类 .btn-group<div> 元素来创建一个按钮组

示例

<div class="btn-group">
  <button type="button" class="btn btn-primary">苹果</button>
  <button type="button" class="btn btn-primary">三星</button>
  <button type="button" class="btn btn-primary">索尼</button>
</div>
亲自尝试 »

提示: 而不是对按钮组中的每个按钮应用按钮尺寸,使用类 .btn-group-lg|sm|xs 来调整按钮组中所有按钮的尺寸

示例

<div class="btn-group btn-group-lg">
  <button type="button" class="btn btn-primary">苹果</button>
  <button type="button" class="btn btn-primary">三星</button>
  <button type="button" class="btn btn-primary">索尼</button>
</div>
亲自尝试 »

垂直按钮组

Bootstrap 也支持垂直按钮组

使用类 .btn-group-vertical 来创建一个垂直按钮组

示例

<div class="btn-group-vertical">
  <button type="button" class="btn btn-primary">苹果</button>
  <button type="button" class="btn btn-primary">三星</button>
  <button type="button" class="btn btn-primary">索尼</button>
</div>
亲自尝试 »


两端对齐按钮组

要跨越整个屏幕宽度,请使用 .btn-group-justified

带有 <a> 元素的示例

示例

<div class="btn-group btn-group-justified">
  <a href="#" class="btn btn-primary">苹果</a>
  <a href="#" class="btn btn-primary">三星</a>
  <a href="#" class="btn btn-primary">索尼</a>
</div>
亲自尝试 »

注意: 对于 <button> 元素,您必须将每个按钮包装在一个 .btn-group 类中

示例

<div class="btn-group btn-group-justified">
  <div class="btn-group">
    <button type="button" class="btn btn-primary">苹果</button>
  </div>
  <div class="btn-group">
    <button type="button" class="btn btn-primary">三星</button>
  </div>
  <div class="btn-group">
    <button type="button" class="btn btn-primary">索尼</button>
  </div>
</div>
亲自尝试 »

嵌套按钮组和下拉菜单

嵌套按钮组以创建下拉菜单

示例

<div class="btn-group">
  <button type="button" class="btn btn-primary">苹果</button>
  <button type="button" class="btn btn-primary">三星</button>
  <div class="btn-group">
    <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
    索尼 <span class="caret"></span></button>
    <ul class="dropdown-menu" role="menu">
      <li><a href="#">平板电脑</a></li>
      <li><a href="#">智能手机</a></li>
    </ul>
  </div>
</div>
亲自尝试 »

分割按钮下拉菜单

示例

<div class="btn-group">
  <button type="button" class="btn btn-primary">索尼</button>
  <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="menu">
    <li><a href="#">平板电脑</a></li>
    <li><a href="#">智能手机</a></li>
  </ul>
</div>
亲自尝试 »

通过练习测试自己

练习

添加一个 Bootstrap 类来将按钮组合在一起。

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

开始练习



×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.