Bootstrap 4 提供了不同样式的按钮:
<button type="button" class="btn">Basic</button>
<button type="button" class="btn btn-primary">Primary</button>
<button type="button" class="btn btn-secondary">Secondary</button>
<button type="button" class="btn btn-success">Success</button>
<button type="button" class="btn btn-info">Info</button>
<button type="button" class="btn btn-warning">Warning</button>
<button type="button" class="btn btn-danger">Danger</button>
<button type="button" class="btn btn-dark">Dark</button>
<button type="button" class="btn btn-light">Light</button>
<button type="button" class="btn btn-link">Link</button>
亲自试一试 »
按钮类可用于<a>
,<button>
, 或者<input>
要素:
<a href="#" class="btn btn-info" role="button">Link Button</a>
<button type="button" class="btn btn-info">Button</button>
<input type="button" class="btn btn-info" value="Input Button">
<input type="submit" class="btn btn-info" value="Submit Button">
亲自试一试 »
为什么我们在链接的 href 属性中放置#?
由于我们没有任何页面可以将其链接到,并且我们不想收到 "404" 消息,因此我们将 # 作为链接。在现实生活中,它当然应该是 "Search" 页面的真实 URL。
Bootstrap 4 提供了八个轮廓/边框按钮:
<button type="button" class="btn btn-outline-primary">Primary</button>
<button type="button" class="btn btn-outline-secondary">Secondary</button>
<button type="button" class="btn btn-outline-success">Success</button>
<button type="button" class="btn btn-outline-info">Info</button>
<button type="button" class="btn btn-outline-warning">Warning</button>
<button type="button" class="btn btn-outline-danger">Danger</button>
<button type="button" class="btn btn-outline-dark">Dark</button>
<button type="button" class="btn btn-outline-light text-dark">Light</button>
亲自试一试 »
使用.btn-lg
大按钮类或.btn-sm
小按钮的类:
<button type="button" class="btn btn-primary btn-lg">Large</button>
<button type="button" class="btn btn-primary">Default</button>
<button type="button" class="btn btn-primary btn-sm">Small</button>
亲自试一试 »
添加类.btn-block
创建一个跨越父元素整个宽度的块级按钮。
按钮可以设置为活动(显示为按下)或禁用(不可单击)状态:
班上.active
使按钮看起来被按下,并且disabled
属性使按钮不可点击。请注意,<a>元素不支持disabled属性,因此必须使用.disabled
类以使其在视觉上显示为禁用。
<button type="button" class="btn btn-primary active">Active Primary</button>
<button type="button" class="btn btn-primary" disabled>Disabled Primary</button>
<a href="#" class="btn btn-primary disabled">Disabled Link</a>
亲自试一试 »
您还可以将 "spinners" 添加到按钮,您将在我们的BS4 加载器教程:
<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>
亲自试一试 »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!