最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论