1

I am trying to align text horizontally and vertically inside buttons. I checked tons of solutions, no joy. This is what I have right now:

<div class="buttonx">

                <a href="texttext.html">Text</a>

                <a href="texttext.html">text text<br>text</a>

                <a href="texttext.html">text</a>

                <a href="texttext.html">text</a>

                <a href="texttext.html">text</a>

            </div>
<style>
.buttonx {
    display: flex;
    flex-wrap: wrap;
}

.buttonx a {
    display: table;
    background-color: #a00c1a;
    width: 120px;
    line-height: 20px;
    margin: 10px;
    text-decoration: none;
    color: rgb(0, 0, 0);
    text-align: center;
    align-items: center;
    color: white;
}
</style>

The text comes out as aligned horizontally, but not vertically. Please help.

Lukas
  • 21
  • 3

2 Answers2

1

Change only your buttonx class like that:

.buttonx {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.buttonx {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.buttonx a {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #a00c1a;
  width: 120px;
  line-height: 20px;
  margin: 10px;
  text-decoration: none;
  color: rgb(0, 0, 0);
  text-align: center;
  color: white;
  height:40px;
}
<div class="buttonx">

  <a href="texttext.html">Text</a>

  <a href="texttext.html">text text<br>text</a>

  <a href="texttext.html">text</a>

  <a href="texttext.html">text</a>

  <a href="texttext.html">text</a>

</div>

Note I also remove from your buttonx a class some css properties.

Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
0

.buttonx {
  display: flex;
  flex-wrap: wrap;
}

.buttonx a {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #a00c1a;
  width: 120px;
  line-height: 20px;
  margin: 10px;
  text-decoration: none;
  color: rgb(0, 0, 0);
  text-align: center;
  color: white;
}
<div class="buttonx">

  <a href="texttext.html">Text</a>

  <a href="texttext.html">text text<br>text</a>

  <a href="texttext.html">text</a>

  <a href="texttext.html">text</a>

  <a href="texttext.html">text</a>

</div>
Nitheesh
  • 19,238
  • 3
  • 22
  • 49