简体   繁体   English

Bootstrap 中卡片页脚中心的按钮

[英]Button in the center of a card footer in Bootstraps

I have this .card-footer :我有这个.card-footer

<div class="card-footer">
    <button class="btn btn-theme pull-left" type="button" id="toleft"><</button>
    <button class="btn btn-theme" type="button" id="more">+</button>
    <button class="btn btn-theme pull-right" type="button" id="toright">></button>
</div>

The buttons .toleft and .toright are in the correct position, however the button #more should be exactly on the center of the footer, but it is still on the left.按钮.toleft.toright在正确的位置,但是按钮#more应该正好在页脚的中心,但它仍然在左边。

Any ideas?有什么想法吗?

Bootstrap 3引导程序 3

You can use the following solution adding .text-center to the .card-footer container:您可以使用以下解决方案将.text-center添加到.card-footer容器:

 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="card-footer text-center"> <button class="btn btn-theme pull-left" type="button" id="toleft">&lt;</button> <button class="btn btn-theme" type="button" id="more">+</button> <button class="btn btn-theme pull-right" type="button" id="toright">&gt;</button> </div>


Bootstrap 4.0+引导程序 4.0+

On Bootstrap 4.0+ there is no class .pull-left or .pull-right anymore .在 Bootstrap 4.0+ 上,不再.pull-left.pull-right You have to use .float-left and .float-right instead.您必须改用.float-left.float-right You can also use .text-center to center the second button.您还可以使用.text-center center 将第二个按钮居中。

 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> <div class="card-footer text-center"> <button class="btn btn-dark float-left" type="button" id="toleft">&lt;</button> <button class="btn btn-dark" type="button" id="more">+</button> <button class="btn btn-dark float-right" type="button" id="toright">&gt;</button> </div>


Note: I don't recommend to use custom CSS rules.注意:我不建议使用自定义 CSS 规则。 Bootstrap is a CSS Framework to provide solutions for many design problems. Bootstrap 是一个 CSS 框架,为许多设计问题提供解决方案。 Overwriting CSS properties on components can cause problems.覆盖组件上的 CSS 属性可能会导致问题。

If you're seeing this in 2018 or beyond, please note that some of these old answers will not work with Bootstrap 4 ...如果您在 2018 年或以后看到这种情况,请注意,其中一些旧答案不适用于 Bootstrap 4 ...

However, there is no need to include additional CSS as a couple of the previous answers suggest.但是,不需要像前面的几个答案所建议的那样包含额外的 CSS。

The pull-left and pull-right classes no longer work in Bootstrap 4. pull-leftpull-right类在 Bootstrap 4 中不再有效。

Instead, we now use float-left and float-right to float our left and right buttons.相反,我们现在使用float-leftfloat-right来浮动左右按钮。

The easiest way to achieve the desired effect would be to start by centering the footer contents by adding the text-center class to the footer.实现所需效果的最简单方法是通过将text-center类添加到页脚来使页脚内容居中。

Next, we can float the left button with the float-left class and float the right button with the float-right class.接下来,我们可以使用float-left类浮动左按钮,使用float-right类浮动右按钮。

Here's the final HTML:这是最终的 HTML:

<div class="card-footer text-center">
<button class="btn btn-theme float-left" type="button" id="toleft">left</button>
<button class="btn btn-theme" type="button" id="more">center</button>
<button class="btn btn-theme float-right" type="button" id="toright">right</button>
</div>

Which gives us the following result:这给了我们以下结果:

Just tried this with the latest alpha6 build of Bootstrap 4 (I'm assuming you're using BS4 as you mentioned the card component), and it looks as though the default behaviour is to align buttons in card footers to the middle anyway.刚刚使用 Bootstrap 4 的最新 alpha6 版本尝试了这个(我假设您在使用 BS4 时提到了卡片组件),看起来默认行为是将卡片页脚中的按钮对齐到中间。

Note that I also had to introduce the .pull-left / .pull-right utility classes, as these no longer appear to be defined in the Bootstrap CSS.请注意,我还必须引入.pull-left / .pull-right实用程序类,因为它们似乎不再在 Bootstrap CSS 中定义。

See demo below:请参阅下面的演示:

 .pull-left { float: left; } .pull-right { float: right; }
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous"> <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script> <div class="card text-center"> <div class="card-header"> Featured </div> <div class="card-block"> <h4 class="card-title">Special title treatment</h4> <p class="card-text">With supporting text below as a natural lead-in to additional content.</p> <a href="#" class="btn btn-primary">Go somewhere</a> </div> <div class="card-footer text-muted"> <button class="btn btn-theme pull-left" type="button" id="toleft">&lt;</button> <button class="btn btn-theme" type="button" id="more">+</button> <button class="btn btn-theme pull-right" type="button" id="toright">&gt;</button> </div> </div>

Try This :试试这个:

 .card-footer{ text-align: center; }
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <div class="card-footer"> <button class="btn btn-theme pull-left" type="button" id="toleft"><</button> <button class="btn btn-theme" type="button" id="more">+</button> <button class="btn btn-theme pull-right" type="button" id="toright">></button> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM