I have a link that I want to center vertically in the .well
class from the bootstrap framework and am using the class btn btn-danger
on the anchor tag. Here's the pic below. I tried to use vertical-align:middle;
but that doesn't seem to work. You can see that the space on the well isn't even on the top and the bottom.
Here is the HTML:
<div class="well">
<%= link_to "Remove", thing, method: :delete, style: "font-size: 11px; float:right; ", :class => 'btn btn-danger'%>
</div>
One way to vertically center is to use my-auto . This will center the element within it's flexbox container (The Bootstrap 4 . row is display:flex ). For example, h-100 makes the row full height, and my-auto will vertically center the col-sm-12 column.
Align / Center content Vertically Aligning content to the center of the DIV is very simple in Bootstrap 5, You just have to convert the div into a flex box using d-flex class property and then use the property align-items-center to vertically align the content in the middle of the div.
To center a div vertically on a page, you can use the CSS position property, top property, and transform property. Start by setting the position of the div to absolute so that it's taken out of the normal document flow. Then set the top property to 50%.
Give the div that's inside the container: align-content: center; All the content inside this div will show up in the middle of the page.
It appears you shouldn't (or simply can't) vertically align a floating element.
Here is what i suggest :
<div class="well mywell">
<div class="pull-right myfloater">
<button class="btn btn-danger vcenter">Remove</button>
</div>
<p><!-- things --></p>
</div>
.mywell{
height: 150px;
}
.myfloater {
line-height: 150px;
}
.vcenter{
vertical-align: middle;
}
The live example : http://jsfiddle.net/Sherbrow/wxM5Z/2/
Edit
Better with line-height
applied to the floating element.
Maybe this is what you need: jsfiddle .
I've added new classes, so as not to overwrite the default bootstrap.
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