Julia
Julia

Reputation: 11

Center 3 buttons in a column

I want to make three square buttons that are centered in the middle of my website. Its in a split so then when the screen in small, the buttons are in rows and when the screen in big, the buttons are in columns.

  .split {
  display: flex;
  flex-direction: column;
  column-gap: 50px;
}

@media (min-width: 40em) {
  .split {
    flex-direction: row;
  }
  .text-center {
    text-align: center;
  }
  button {
    display: flex;
    justify-content: space-evenly;
    background: #ADCEAC;
    width: 80%;
    line-height: 250px;
    font-family: "Tenor Sans", sans-serif;
    border: none;
    border-radius: 15px;
  }
<div class="text-center">
  <div class="split">
    <div>
      <button onclick="window.location.href = 'FirstPage.html';">HOME</button>
    </div>
    <div>
      <button onclick="window.location.href = 'FirstPage.html';">HOME</button>
    </div>
    <div>
      <button onclick="window.location.href = 'FirstPage.html';">HOME</button>
    </div>
  </div>
</div>

When it is in rows, it is fine. However when it is columns, the buttons are 3 long lines at the very left end.

Upvotes: 0

Views: 311

Answers (2)

Andrii Stropalov
Andrii Stropalov

Reputation: 725

You just need to define the button’s width property:

.split {
  display: flex;
  flex-direction: column;
  column-gap: 50px;
}

@media (min-width: 40em) {
  .split {
    flex-direction: row;
  }
  button {
    margin-bottom: 0;
  }
  .text-center {
    text-align: center;
  }
}

button {
  display: flex;
  justify-content: space-evenly;
  background: #ADCEAC;
  width: 70px;
  font-family: "Tenor Sans", sans-serif;
  border: none;
  border-radius: 15px;
  margin-bottom: 10px;
}
<div class="text-center">
  <div class="split">
    <div>
      <button onclick="window.location.href = 'FirstPage.html';">HOME</button>
    </div>
    <div>
      <button onclick="window.location.href = 'FirstPage.html';">HOME</button>
    </div>
    <div>
      <button onclick="window.location.href = 'FirstPage.html';">HOME</button>
    </div>
  </div>
</div>

Upvotes: 3

.split { display: flex flex-direction: column column-gap: 50px justify-content: center

Upvotes: -2

Related Questions