When you design your website, you may want something other than the plain textbox appearance that comes with the default:
In this short tutorial, I’ll show you how to make a textbox appear however you want using an image background and some easy CSS adjustments.
Create a background image
First, you will need to create a background image to fill the textbox. This background image is just a rectangle of whatever size and appearance you want. For instance, I wanted a large textbox to use as a central, main search box on my website’s home page. Here is the image I created:
As you can see, it’s just a simple rectangle with a bit of inner shadow and whatnot.
Write the form
Anyone experienced in web development has done this a million and a half times, so use whatever form code you want incorporating the text box. As an example, here is a very simple search form:
<form method="get" action="" class="search">
My Search Form
<input class="msb" maxlength="2048" name="q" size="25" title="Search" value="" lang="en" />
<input value="Search" type="submit" />
Write the CSS
Now we will use a little CSS to adjust the textbox to accept its new appearance. Note that the class attribute of the “q” input entity is set to “msb” (msb stands for mysearchbox).
First, set the background-image property to the location and filename of your textbox background image that you created in step 1:
Then, set the size of the textbox by adding the height and width properties:
Note that these are just the actual dimensions of the background image.
Finally, use the padding property to vertically align your text within the box. Whatever padding you add to adjust the placement of text inside the textbox, you must subtract from the height and width values. I used FireBug to play around with the padding and font size until I got something that looked right. I found that this combo of CSS properties worked well for me:
padding:10px 0px 0px 10px;
That’s it! As you can see, it really couldn’t be easier to customize the appearance of an HTML textbox to give your website a unique design and feel.