简体   繁体   English

为什么 bootstrap float-right class 对我的按钮不起作用?

[英]Why bootstrap float-right class not working for my button?

The bootstrap float-right class did not work with my buttons. bootstrap float-right class 不适用于我的按钮。

This is my html code snippet:这是我的 html 代码片段:

 <link href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" rel="stylesheet"/> <div class="container-fluid"> <button type="button" id="reset_button" class="btn btn-outline-secondary btn-lg float-right" disabled="disabled">Reset</button> <button type="button" id="convert_button" class="btn btn-primary btn-lg float-right" disabled="disabled">Submit</button> </div>

I want to make buttons align right but when I add the float-right class in both the buttons it doesn't work.我想让按钮右对齐但是当我在两个按钮中添加float-right class 时它不起作用。

Can anyone please tell me what's wrong with my code and how can I fix this...任何人都可以告诉我我的代码有什么问题以及我该如何解决这个问题......

Instead of float there are probably better Bootstrap options.除了浮动,可能还有更好的 Bootstrap 选项。

Try removing the float-right and instead use d-flex with justify-content-end on the top line of your code like this....尝试删除float-right ,而是在代码的第一行使用d-flexjustify-content-end ,就像这样......

<div class="container-fluid d-flex justify-content-end">
      <button type="button" id="reset_button" class="btn btn-outline-secondary btn-lg" disabled="disabled">Reset</button>
      <button type="button" id="convert_button" class="btn btn-primary btn-lg" 
       disabled="disabled">Submit</button>
</div>

The code is working for me.该代码对我有用。 I just copied your snippet and buttons are on the right side.我刚刚复制了您的代码段,按钮在右侧。

Problem is meaby in parent DIRs with different CSS or something else is rewriting your style.问题出在具有不同 CSS 的父目录中,或者其他东西正在重写您的样式。

You can also see this, when you run your snippet here.当您在此处运行您的代码片段时,您也可以看到这一点。

Like previous answers has stated, maybe there are some other styles in a parent div or element that aren't compatible with the float classes.正如之前的回答所述,父 div 或元素中可能还有其他一些 styles 与float类不兼容。

Try adding in a parent div the clearfix Bootstrap class, that should solve the issue in your code.尝试在父 div 中添加clearfix Bootstrap class,这应该可以解决您的代码中的问题。

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

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