Bootstrap 4 - center text with button label

2020-05-01 06:04发布

I want to achieve a very simple goal: I have a line - text aligned to left and a button to right. And I want the text to be vertically aligned to button's label. I tried to play with padding, margins,... but nothing worked. I believe there is a simple and smart solution I am missing.

Plunker demo:

https://plnkr.co/edit/KwRF2uOmKc3aPFQW9DXn?p=preview

<div>
    <span>
        This text should match the "Submit" text
    </span>
    <button type="button" class="btn btn-secondary float-right">Submit</button>
</div>

Thank for your answers.

1条回答
做自己的国王
2楼-- · 2020-05-01 06:43

Bootstrap 4 is based on flexbox, so already has classes for applying those alignment utilities. d-flex makes the container a flex container, and align-items-center does the vertical alignment. Try something like:

<div class="d-flex align-items-center">
    <span>
        This text should match the "Submit" text
    </span>
    <button type="button" class="btn btn-secondary ml-auto">Submit</button>
</div>
查看更多
登录 后发表回答