1

Context:

I'm relatively new to HTML/CSS and have been tasked with creating a search form for my company's website. I have all the actual code working beautifully, but the thing thats stumping me is a simple style issue. In the search form, the text input field and the button input field do not align vertically very nicely, and I cannot get them to cooperate via CSS. I'd like them both to be the same height and level with each other. Any advice? Thank you!

Search Form

Code:

#srchContainer {
  width: 70%;
  height: 100%;
  border: 0px;
  margin: 0 auto;
  padding: 0;
}
#searchForm {
  text-align: center;
  margin: 20px auto;
  padding: 0;
  width: 100%;
  vertical-align: top;
}
#searchInputBox {
  width: 60%;
  height: 31px;
  border: 1px solid #717171;
  font-size: 1.5em;
  margin: 0;
  padding: 0 0 0 5px;
  display: inline;
}
#srchBtn {
  height: 32px;
  margin-left: 2px;
  margin-top: 0;
  margin-bottom: 0;
  padding-left: 6px;
  padding-right: 6px;
  padding-bottom: 0px;
  padding-top: 1px;
  display: inline;
}
.btn {
  color: #717171;
  border-radius: 0px;
  padding-left: 6px;
  padding-right: 6px;
  padding-bottom: 1px;
  padding-top: 1px;
  border: 1px solid #717171;
  margin-left: 2px;
  margin-right: 2px;
  margin-top: 0px;
  margin-bottom: 2px;
  height: 20px;
}
.btn:hover,
.btn2:hover {
  background-color: #717171;
  color: white;
}
<html>

<body>
  <div id="searchContainer">
    <form id="searchForm">
      <input type="text" id="searchInputBox" />
      <input type="button" id="srchBtn" class="btn" value="Search" />
    </form>
  </div>
</body>

</html>

1
  • It's worth noting that the root cause of your problem is the font-size set on the text input. Commented Nov 11, 2015 at 16:32

2 Answers 2

1

Apply vertical-align: middle; to both of the input elements.

Sign up to request clarification or add additional context in comments.

1 Comment

Amazing how easy it is to overlook something so simple. I had attemped using this on the parent elements, but not on the inputs themselves. Thank you very much!
0

You can easily work in the alignment using the CSS flexbox.

See the following link to check the browser support.

Here´s a quick example:

.navbar {
  display: flex;
}
.navbar input {
  flex: 1;
}
.navbar button {
  border: 1px solid #aaa;
  margin-left: 3px;
}
<div class="navbar">

  <input type="text">

  <button type="button">search</button>

</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.