html - 使用按钮居中内容 block

标签 html css twitter-bootstrap twitter-bootstrap-3

The center-block class of Bootstrap在图像、调整大小的 block 元素(如 div)和显然在按钮中有效。

按钮类应用于链接(成为伪按钮)时,它不会水平居中

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<button type="button" class="btn btn-default center-block">Pure button</button>
<a href="#" class="btn btn-default center-block">Link button</a>

appearance具有 button 值的 CSS 属性不起作用。并且设置固定尺寸(widthmax-widthmin-width)并不是一个好的解决方案。

This trouble was ignored in GitHub .

最佳答案

Display: block 以其他方式作用于 buttons 和其他元素(例如 a)。您需要添加 display: table 链接而不是 display: block;

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<style>
a.btn-default {display: table}
</style>

<button type="button" class="btn btn-default center-block">Pure button</button>
<a href="#" class="btn btn-default center-block">Link button</a>

关于html - 使用按钮居中内容 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47938099/

相关文章:

html - 使用 css 类有条件地更改 anchor 标记自定义链接按钮背景颜色

html - 电子邮件图表 - 条形图、面积图和饼图

twitter-bootstrap - Kendo UI Grid 过滤器没有

javascript - 在 Bootstrap 模式中显示 sumoselect

javascript - 在 Highcharts 中动态更改条形图背景颜色

CSS:水平菜单,每个入口侧有两个图像和翻转

html - Safari 中的 CSS 过渡转换 z-index 冲突(适用于 Chrome/FF)

javascript - 有没有办法列出网页的所有可用 css 类?

javascript - 打字机追加淡入

javascript - 尝试在 Bootstrap 中将两个表单并排放置。任何想法如何?