1

As you can see in the demo, once I add the <em> the <button> is displaced.

I would like the button to be vertically center in the footer.

Demo: http://jsfiddle.net/chovy/5h5hc/1/

HTML

<footer>
    <button class="btn-primary">Reply</button>
</footer>

<footer>
    <em></em>
    <button class="btn-primary">Reply</button>
</footer>

CSS

footer {
    display: block;
    height: 50px;
    line-height: 50px;
    border: 1px solid red;
    padding: 0 20px;
    text-align: right;
    margin-top: 20px;
}

em {
    display: inline-block;
    height: 50px;
    width: 50px;
    border: 1px solid blue;
    box-sizing: border-box;
}
Falguni Panchal
  • 8,873
  • 3
  • 27
  • 33
chovy
  • 72,281
  • 52
  • 227
  • 295

4 Answers4

1

Make a small change to your HTML.

<footer>
    <button class="btn-primary">Reply</button>
</footer>

<footer>
    <em>&nbsp;</em>
    <button class="btn-primary">Reply</button>
</footer>

Add some text to your <em> it works as expected. (If you don't want any text in there, just put &nbsp; for a space.)

Fiddle here.

Sunny R Gupta
  • 5,026
  • 1
  • 31
  • 40
0

LIke this please add float:left; in em selector

DEMO

CSS

em {
    display: inline-block;
    height: 50px;
    width: 50px;
    border: 1px solid blue;
    box-sizing: border-box;
    float:left;
}
Falguni Panchal
  • 8,873
  • 3
  • 27
  • 33
0

You could tell them to behave like tables: http://jsfiddle.net/5h5hc/12/. Then your footer can be as flexible as you like and the content will always be horizontally centered.

<footer>
    <div><em>an em</em><button class="btn-primary">Reply</button></div>
</footer>

css:

footer {
    display:table;
    height:50px;
    border:1px solid #990000;
    width:100%;
}
footer div {
    display:table-cell;
    vertical-align:middle;
    text-align:right;
}
Moob
  • 14,420
  • 1
  • 34
  • 47
0

You simply add vertical-align: top to the <em> to negate the default behaviour of the display: inline-block declaration. fiddle

cjross
  • 636
  • 1
  • 5
  • 10