最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Increasing the size of a input field in HTMLCSSJS - Stack Overflow

matteradmin8PV0评论

I am trying to increase the size of an input field on a webpage. My width is fine, but my height is what I am trying to figure out.

#searchBox {
  color: white;
  float: right;
  margin-right: 10px;
  padding: 20px;
}
<div id="searchBox">
  <form action="search" id="searchBar">
    <input type="text" name="search">
  </form>
</div>
<!-- searchBox -->

I am trying to increase the size of an input field on a webpage. My width is fine, but my height is what I am trying to figure out.

#searchBox {
  color: white;
  float: right;
  margin-right: 10px;
  padding: 20px;
}
<div id="searchBox">
  <form action="search" id="searchBar">
    <input type="text" name="search">
  </form>
</div>
<!-- searchBox -->

Share Improve this question edited Oct 20, 2015 at 13:48 j08691 208k32 gold badges269 silver badges280 bronze badges asked Oct 20, 2015 at 13:47 TheDetailerTheDetailer 2996 silver badges16 bronze badges 4
  • 1 Have you tried setting a height on the input? – j08691 Commented Oct 20, 2015 at 13:49
  • Yes, I have tried adding css code to every tag/element for that block of code, along with trying to manually add the css through the html tags. – TheDetailer Commented Oct 20, 2015 at 13:50
  • padding: 40px 20px this modifies height and width seperatly – NooBskie Commented Oct 20, 2015 at 13:52
  • 1 Really? Because setting the height seems to work jsfiddle/j08691/9g6tpbox – j08691 Commented Oct 20, 2015 at 13:53
Add a ment  | 

2 Answers 2

Reset to default 3

You can simply increase the font size; the input will scale along with it.

#searchBox {
  color: white;
  float: right;
  margin-right: 10px;
  padding: 20px;
}

#searchBox input {
  font-size: 200%;
  width: 100px;
}
<div id="searchBox">
  <form action="search" id="searchBar">
    <input type="text" name="search">
  </form>
</div>

There are 2 ways to do this. You may set the height with the attribute height inside the input, or change the height via css.

First Method:

<input type="text" name="search" height="200" />

Second Method:

input[name="search"] {
    height: 200px;
}

I prefer using the first one. Since it better expands to the text inside of it. But for using it multiple times, css is the way to go.

Also note that the first method might not work if you arent using any reset css or modernizer since browsers tend to overwrite/ignore the height attribute inside elements like inputs.

Post a comment

comment list (0)

  1. No comments so far