2

Is there a way how to center white text in controls vertical and horizontal to put text on both in the middle of orange canvas? Center

Demo:

.ButtonOrange {
    width: 161px;
    height: 160px;
    float: left;
    display: inline-block;
    border-style: hidden;
    border-width: 0px;
    border-color: inherit;
    padding: 12px;
    margin: 5px;
    background-color: #F66907;
    color: #FFF;
    border-radius: 6px;
    text-align: center;
    font-weight: bold;
    font-size: 12px;
    font-family: Arial, Helvetica, sans-serif;
    font-style: normal;
    text-decoration: none;
    position: relative;
}
<p>
    <input value="Login" class="ButtonOrange" type="submit">
<a class="ButtonOrange" href="#">Register</a>

</p>
Nasenbaer
  • 4,810
  • 11
  • 53
  • 86
  • Using `float` and `display:inline-block` at the same time is not logical...they are mutually exclusive. – Paulie_D Nov 05 '15 at 17:04

2 Answers2

2

You can use line-height:160px;(160px = The height of element) and remove padding,

.ButtonOrange {
    line-height:160px;             
    width: 161px;
    height: 160px;
    float: left;
    border-style: hidden;
    border-width: 0px;
    border-color: inherit;
    margin: 5px;
    background-color: #F66907;
    color: #FFF;
    border-radius: 6px;
    text-align: center;
    font-weight: bold;
    font-size: 12px;
    font-family: Arial, Helvetica, sans-serif;
    font-style: normal;
    text-decoration: none;
    position: relative;
}
<p>
    <input value="Login" class="ButtonOrange" type="submit">
<a class="ButtonOrange" href="#">Register</a>

</p>
Alex
  • 8,461
  • 6
  • 37
  • 49
2

I create a class(.centerVerticalHorizontal) which you can add it in your elements you wish to center both horizontal and vertical using flex

.ButtonOrange {
  width: 161px;
  height: 160px;
  float: left;
  display: inline-block;
  border-style: hidden;
  border-width: 0px;
  border-color: inherit;
  padding: 12px;
  margin: 5px;
  background-color: #F66907;
  color: #FFF;
  border-radius: 6px;
  text-align: center;
  font-weight: bold;
  font-size: 12px;
  font-family: Arial, Helvetica, sans-serif;
  font-style: normal;
  text-decoration: none;
  position: relative;
}
.centerVerticalHorizontal {
  display: flex;
  justify-content: center;
  align-items: center;
}
<p>
  <input value="Login" class="ButtonOrange centerVerticalHorizontal" type="submit">
  <a class="ButtonOrange centerVerticalHorizontal" href="#">Register</a>
  <div class="ButtonOrange centerVerticalHorizontal">Test div text</div>
</p>
Alex Char
  • 32,879
  • 9
  • 49
  • 70