14

I need to get a button inside a form-actions vertically:

This is how is displayed:

enter image description here

So that green button is being displayed down to its div (the blue area). How can I get to center it. I use a style.css file where I've styled some other divs.

Jack Bonneman
  • 1,821
  • 18
  • 24
diegoaguilar
  • 8,179
  • 14
  • 80
  • 129

3 Answers3

12

Is this what you need! Here is a demo, please check and let me know if you need anything else.

http://jsfiddle.net/fkQBf/

<div style="height: 200px; border: solid 2px green; text-align:center;line-height:200px;">
    <input type="submit" Value="Ok" style="vertical-align: middle"></input>
</div>

Updated code and fiddle:

We should not use inline styles, so below is the updated fiddle with separate style

http://jsfiddle.net/fkQBf/1/

<div id="container">
    <input id="verticalButton" type="submit" Value="Ok"></input>
</div>

div#container
{
    height: 200px; 
    border: solid 2px green; text-align:center;
    line-height:200px;
}

input#verticalButton
{
     vertical-align: middle
}

Hope this helps!

Narendra
  • 3,069
  • 7
  • 30
  • 51
6

Since I didn't want to set an absolute height, I used flex boxes.

/* Latest compiled and minified CSS included as External Resource*/

/* Optional theme */
@import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');

body {
    margin: 10px;
}

.container {
  height:50%;
  border: 1px solid black;
  display:flex;
  align-items:center; /* vertically aligned! */
  justify-content: center;
}

.other {
  height:320px;
  border: 1px solid red;
}
<div class="other"><!-- Other content -->
Welcome to my great site!
  <div class="container"> <!-- the container you want that button -->
      <button class="btn btn-danger btn-lg">
      Hello World
      </button>
  </div>
</div>
Standard
  • 1,450
  • 17
  • 35
1

use some style like

display:table-cell; //main div

vertical-align:center; // to button

If this will not worked than try

height:100%; // to button
vertical-align:center; // to button
line-height : 100%;  // to button
JayDeep Nimavat
  • 476
  • 6
  • 22