Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you horizontal align submit button?

Tags:

html

css

How do you make this search button to center align horizontally?

This is how it looks like

input.search {
    width: 7em; height: 3em;
    float: right;
    padding-right: 10px;
    background-color: #777777;
}
like image 317
TriggeredNope Avatar asked May 17 '26 13:05

TriggeredNope


1 Answers

Inputs by default use the display:inline; style, which means that the parent element would need to have text-align:center; like this:

.parent {
  background-color: #404040;
  text-align: center;
  padding: 5px;
}
<div class="parent">
  <input type="submit" class="submit" value="Submit">
</div>

Or alternatively, you can change the display type of the button/input to display:block; and use auto margins like this:

.parent {
  background-color: #404040;
  padding: 5px;
}
.submit {
  display:block;
  width: 100px; /* note that display block will go full width unless you specify otherwise */
  text-align:center;
  margin: auto;
}
<div class="parent">
  <input type="submit" class="submit" value="Submit">
</div>
like image 106
Frits Avatar answered May 19 '26 03:05

Frits



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!