bootstrap中怎么样使按钮居中

xiaoxiao2021-02-28  137

总结一下以下几种方法: 在bs中表现按钮的方法有两种: 1.关于 <a> 元素  只须将一系列 .btn 元素包裹到 .btn-group.btn-group-justified 中即可。   <div class="btn-group btn-group-justified" role="group" aria-label="...">    ...  </div> 复制代码 2.关于 <button> 元素  为了将 <button> 元素用于两端对齐的按钮组中,必须将每个按钮包裹进一个按钮组中you must wrap each button in a button group。大部分的浏览器不能将我们的 CSS 应用到对齐的 <button> 元素上,但是,由于我们支持按钮式下拉菜单,我们可以解决这个问题。 <div class="btn-group btn-group-justified" role="group" aria-label="...">   <div class="btn-group" role="group">     <button type="button" class="btn btn-default">Left</button>   </div>   <div class="btn-group" role="group">     <button type="button" class="btn btn-default">Middle</button>   </div>   <div class="btn-group" role="group">     <button type="button" class="btn btn-default">Right</button>   </div> </div> 复制代码 在做项目的过程中遇到要将万恶的按钮居中,顿时脑袋空白了,margin又不能用,还要遵循框架,哎呀,问了下度娘,果然找到几种不错的方法,当然缘由还不是很明白,希望遇到哪个大神给详细讲下理论,好了,看下面的方法吧: 1.block 没设定宽度是不能 margin auto 来居中的,一个简单的办法是 display: table; display: table width: auto margin-left: auto margin-right: auto 复制代码 运行代码 复制代码 保存代码 提示:您可以先修改部分代码再运行! power by W3Cfuns.com 2.很直接,用<center></center> <center><button type="button" class="btn btn-primary" >Primary</button></center> 复制代码 自己试验了一下不好用,文章不好找,先备份一下。
转载请注明原文地址: https://www.6miu.com/read-37658.html

最新回复(0)