, 或 元素上:
<template>
<div class="container mt-3">
<h2>按钮元素</h2>
<a href="#" class="btn btn-info m-3" role="button">链接按钮</a>
<button type="button" class="btn btn-info m-3">按钮</button>
<input type="button" class="btn btn-info m-3" value="输入框按钮">
<input type="submit" class="btn btn-info m-3" value="提交按钮">
</div>
</template>
按钮设置边框
Bootstrap 5 也可以设置按钮多边框,鼠标移动到按钮上添加突出到效果:
<template>
<div class="container mt-3">
<h2>按钮设置边框</h2>
<button type="button" class="btn m-1 btn-outline-secondary">次要按钮</button>
<button type="button" class="btn m-1 btn-outline-success">成功</button>
<button type="button" class="btn m-1 btn-outline-primary">主要按钮</button>
<button type="button" class="btn m-1 btn-outline-info">信息</button>
<button type="button" class="btn m-1 btn-outline-warning">警告</button>
<button type="button" class="btn m-1 btn-outline-danger">危险</button>
<button type="button" class="btn m-1 btn-outline-dark">黑色</button>
<button type="button" class="btn m-1 btn-outline-light text-dark">浅色</button>
</div>
</template>
不同大小的按钮
Bootstrap 5 可以设置按钮的大小,使用 .btn-lg 类设置大按钮,使用 .btn-sm 类设置小按钮:
<template>
<div class="container mt-3">
<h2>按钮设置边框</h2>
<button type="button" class="btn m-1 btn-outline-secondary btn-lg">大按钮</button>
<button type="button" class="btn m-1 btn-outline-success">普通按钮</button>
<button type="button" class="btn m-1 btn-outline-primary btn-sm">小按钮</button>
</div>
</template>
块级按钮
通过添加 .btn-block 类可以设置块级按钮,.d-grid 类设置在父级元素中:
如果有多个块级按钮,你可以使用用 .gap-* 类来设置:
<template>
<div class="container mt-3">
<p>通过添加 .btn-block 类可以设置块级按钮,.d-grid 类设置在父级元素中:</p>
<div class="d-grid gap-3">
<button type="button" class="btn btn-primary btn-block">100% 宽度的按钮</button>
<button type="button" class="btn btn-primary btn-block">100% 宽度的按钮</button>
<button type="button" class="btn btn-primary btn-block">100% 宽度的按钮</button>
</div>
</div>
</template>
激活和禁用的按钮
<template>
<div class="container mt-3">
<h2>按钮状态</h2>
<button type="button" class="btn btn-primary">主要按钮</button>
<button type="button" class="btn btn-primary active">点击后的按钮</button>
<button type="button" class="btn btn-primary" disabled>禁止点击的按钮</button>
<a href="#" class="btn btn-primary disabled">禁止点击的链接</a>
</div>
</template>
加载按钮
我们也可以设置一个正在加载的按钮。
<template>
<div class="container mt-3">
<h2>加载按钮</h2>
<p>按钮添加正在加载按钮:</p>
<button class="btn btn-primary">
<span class="spinner-border spinner-border-sm"></span>
</button>
<button class="btn btn-primary">
<span class="spinner-border spinner-border-sm"></span>
Loading..
</button>
<button class="btn btn-primary" disabled>
<span class="spinner-border spinner-border-sm"></span>
Loading..
</button>
<button class="btn btn-primary" disabled>
<span class="spinner-grow spinner-grow-sm"></span>
Loading..
</button>
</div>
</template>