-1

I have a button that i make. but what i want is that to make the button center alligin. i use alignment center. but it is not working. what i have to do is that to make the button allignement in center in whole page.

.button {
  text-decoration:none;
  text-align:center;
  display: flex;
  background: #333333;
  color: white;
  justify-content: space-between;
  align-items: center;
  pointer-events:none;
  max-width:660px;
  border-bottom:solid gray 1px
    font-family: DIN pro;
    font-weight: bold;
}
.button .fa {
  padding:1em;
  pointer-events:auto;
  width:1.5em;
}
.button::before {
  content: '';
  padding: 1em
}
<a href="#" class="button"> CONTACT <i class="fa fa-arrow-right border-left "></i></a>
Danish Riaz
  • 61
  • 1
  • 2
  • 12

3 Answers3

0

Add margin: 0 auto; to your .button class.

.button {
  margin: 0 auto;
  text-decoration:none;
  text-align:center;
  display: flex;
  background: #333333;
  color: white;
  justify-content: space-between;
  align-items: center;
  pointer-events:none;
  max-width:660px;
  border-bottom:solid gray 1px
    font-family: DIN pro;
    font-weight: bold;
}
.button .fa {
  padding:1em;
  pointer-events:auto;
  width:1.5em;
}
.button::before {
  content: '';
  padding: 1em
}
<a href="#" class="button"> CONTACT <i class="fa fa-arrow-right border-left "></i></a>
DaftPlug
  • 60
  • 1
  • 10
0

Set display: flex; justify-content: center; for the parent of that button. Here the parent is body

body {
  display: flex;
  justify-content: center;
}

body {
  display: flex;
  justify-content: center;
}
.button {
  text-decoration: none;
  text-align: center;
  display: flex;
  background: #333333;
  color: white;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  max-width: 660px;
  border-bottom: solid gray 1px;
  font-family: DIN pro;
  font-weight: bold;
}
.button .fa {
  padding: 1em;
  pointer-events: auto;
  width: 1.5em;
}
.button::before {
  content: "";
  padding: 1em;
}
<a href="#" class="button">
      CONTACT <i class="fa fa-arrow-right border-left "></i
    ></a>
Nitheesh
  • 19,238
  • 3
  • 22
  • 49
0

First of all, you need to remove the display: flex property in your button, so then you will can center it by a parent element.

You are setting text-align: center in the button, but what you need to do is to set this property in a parent element of the button.

EXAMPLE

<div style="text-align: center;">
    <button>I'm in the center!</button>
</div>