Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically center bootstrap btn in .well class

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.

enter image description here

Here is the HTML:

<div class="well">
   <%= link_to "Remove", thing, method: :delete, style: "font-size: 11px; float:right; ", :class => 'btn btn-danger'%>

</div>
like image 366
locoboy Avatar asked Jun 25 '12 07:06

locoboy


People also ask

How do I center something vertically in bootstrap?

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.

How do I center my bootstrap 5 vertically?

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.

How do I center something vertically in a 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%.

How do I center a container in the middle of a bootstrap page?

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.


2 Answers

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-heightapplied to the floating element.

like image 63
Sherbrow Avatar answered Oct 15 '22 19:10

Sherbrow


Maybe this is what you need: jsfiddle .

I've added new classes, so as not to overwrite the default bootstrap.

like image 28
Xella Avatar answered Oct 15 '22 18:10

Xella