0

I have this HTML:

<div class="title_right mid_center top_menu">
  <a class="btn btn-app" href="/Home/ComoFunciona">
  <a class="btn btn-app" href="/Home/Tarifas">
  <a class="btn btn-app" href="/Home/Contacto">
  <a class="btn btn-app" href="/Security/Account">
</div>

The CSS is:

.page-title .title_right {
  width: 55%;
  float: left;
  display: block;
}

.mid_center {
    width: 370px;
    margin: 0 auto;
    text-align: center;
    padding: 10px 20px;
}

div.top_menu {
    height: 167px;
    vertical-align: middle;
}

How can I center those buttons vertically? I don't want to patch it using padding.

P.S.
  • 15,970
  • 14
  • 62
  • 86
jstuardo
  • 3,901
  • 14
  • 61
  • 136
  • Add the style property `vertical-align: middle` to each `.btn`. `vertical-align` specifies the alignment for the elements you've applied the property to as opposed to the children of that element. – Thomas Maddocks Aug 05 '17 at 01:09

2 Answers2

0

It's pretty easy with Flexbox. I have changed only div.top_menu styles:

.page-title .title_right {
    width: 55%;
    float: left;
    display: block;
}

.mid_center {
    width: 370px;
    margin: 0 auto;
    text-align: center;
    padding: 10px 20px;
    background-color: violet;
}

div.top_menu {
    height: 167px;
    vertical-align: middle;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;

    -ms-flex-align: center;
    -webkit-align-items: center;
    -webkit-box-align: center;
    align-items: center;

    -webkit-justify-content: center;
    justify-content: center;
}
<div class="title_right mid_center top_menu">
  <a class="btn btn-app" href="/Home/ComoFunciona">1</a>
  <a class="btn btn-app" href="/Home/Tarifas">2</a>
  <a class="btn btn-app" href="/Home/Contacto">3</a>
  <a class="btn btn-app" href="/Security/Account">4</a>
</div>

Need to say, that it's a crossbrowser solution, but some old browser doesn't support flexbox.

P.S.
  • 15,970
  • 14
  • 62
  • 86
0

Using display: table-cell with your vertical-align: middle should do it.

.page-title .title_right {
  width: 55%;
}

.mid_center {
    width: 370px;
    margin: 0 auto;
    text-align: center;
    padding: 10px 20px;
}

div.top_menu {
    height: 167px;
    vertical-align: middle;
    background-color: lightgray;
    display: table-cell;
}
<div class="title_right mid_center top_menu">
  <a class="btn btn-app" href="/Home/ComoFunciona">1</a>
  <a class="btn btn-app" href="/Home/Tarifas">2</a>
  <a class="btn btn-app" href="/Home/Contacto">3</a>
  <a class="btn btn-app" href="/Security/Account">4</a>
</div>
Ricky Dam
  • 1,833
  • 4
  • 23
  • 42