I'm trying to vertically align text (pulled left) and a button (pulled right) inside a Bootstrap 3 alert
. Somehow like this:
+------------------------------------------------+
| Some text [A button] |
+------------------------------------------------+
What I have so far is the following (Bootply):
<div class="alert alert-info" style="overflow:hidden">
<p class="pull-left">Some text</p>
<button class="btn btn-sm btn-default pull-right">A button</button>
</div>
The button is perfectly aligned (this was actually my first problem, solved here), but now the text is out of center.
I appreciate your help!
row is now display:flex you can simply use align-self-center on any column to vertically center it... or, use align-items-center on the entire .
Change the alignment of elements with the vertical-alignment utilities. Please note that vertical-align only affects inline, inline-block, inline-table, and table cell elements. Choose from .align-baseline , .align-top , .align-middle , .align-bottom , .align-text-bottom , and .align-text-top as needed.
Bootstrap 4 use flexbox, so d-flex assign the property display: flex than align-items-center aligns it vertically and justify-content-center aligns it horizontally. Whilst code only answers may solve the problem, some explanation of your answer would help others understand what you have done and why you have done it.
Center the text vertically between the top and bottom margins. Select the text that you want to center. in the Page Setup group, and then click the Layout tab. In the Vertical alignment box, click Center.
Assuming you don't want to use line-height, you can also try:
div.alert-info {
position: relative;
}
div.alert-info p.pull-left {
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-o-transform: translateY(-50%);
transform: translateY(-50%);
position: absolute;
top: 50%;
}
http://www.bootply.com/117260
use display:table; width:100%;
for the alert div, and for the p
tag remove the float and use display:table-cell; vertical-align:middle
.
You can use the same rules for the button.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With